Container Environments

How to use the Sentry Native SDK in container environments.

The Sentry Native SDK uses a database path to store events and crash reports. When you are using a containerized environment, you may want to mount a volume to persist the database across container restarts to avoid losing this data.

Starting with SDK version 0.8.3 for Linux and 0.8.6 for Windows, the option crashpad_wait_for_upload allows the application to wait for the crashpad_handler to finish before a shutdown-after-crash.

In SDK versions older than 0.8.3/0.8.6, you could use a script similar to the example below to tie container shutdown to the crashpad_handler process:

Copied
#!/bin/bash

# ./execute-main-app

crashpad_timeout_s=10
crashpad_process_name=crashpad_handler
crashpad_pid=$(pgrep -n -f $crashpad_process_name)
if [ -n "$crashpad_pid" ]; then
    echo "Waiting for crashpad to finish..."
    timeout $crashpad_timeout_s tail --pid=$crashpad_pid -f /dev/null
    if [ $? -eq 124 ]; then
        echo "The crashpad process did not finish within $crashpad_timeout_s seconds"
    else
        echo "The crashpad process finished successfully"
    fi
fi

on Linux, or for Windows PowerShell

Copied
# Start-Process -FilePath ".\main-app.exe" -Wait

$crashpadTimeoutSec = 10
$crashpadProcessName = "crashpad_handler"
$crashpadProcess = Get-Process -Name $crashpadProcessName -ErrorAction SilentlyContinue | Sort-Object StartTime -Descending | Select-Object -First 1
if ($null -ne $crashpadProcess) {
    Write-Output "Waiting for crashpad to finish..."
    $finished = $crashpadProcess.WaitForExit($crashpadTimeoutSec * 1000)
    if (-not $finished) {
        Write-Output "The crashpad process did not finish within $crashpadTimeoutSec seconds"
    } else {
        Write-Output "The crashpad process finished successfully"
    }
}
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").