Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

ci(rust): upload native debug symbols during production image builds (#69117)

Catalin Irimiea5e1d0f58698
diff --git a/.github/workflows/_rust-build-images.yml b/.github/workflows/_rust-build-images.yml
index de848b15296a..11dece8b8f93 100644
--- a/.github/workflows/_rust-build-images.yml
+++ b/.github/workflows/_rust-build-images.yml
@@ -41,6 +41,8 @@ on:
required: false
POSTHOG_DEVEX_PROJECT_API_TOKEN:
required: false
+ POSTHOG_UPLOAD_SYMBOLS_CLI_API_KEY:
+ required: false
outputs:
digests:
description: 'JSON object mapping image name to digest'
@@ -154,6 +156,27 @@ jobs:
echo "::add-mask::$SCCACHE_WEBDAV_TOKEN"
echo "token=$SCCACHE_WEBDAV_TOKEN" >> "$GITHUB_OUTPUT"
+ # Native debug symbols upload to PostHog error tracking from inside the
+ # image build (see rust/Dockerfile). Only master builds on the canonical
+ # deploy repo get the token; everywhere else the Dockerfile skips the
+ # upload, so unrebased branches and forks are unaffected.
+ - name: Prepare symbol upload token
+ id: symbols
+ env:
+ TOKEN: ${{ secrets.POSTHOG_UPLOAD_SYMBOLS_CLI_API_KEY }}
+ ENABLED: ${{ github.event_name != 'pull_request' && vars.CD_DEPLOY_ENABLED == 'true' }}
+ run: |
+ if [ "$ENABLED" = "true" ] && [ -n "$TOKEN" ]; then
+ echo "::add-mask::$TOKEN"
+ echo "token=$TOKEN" >> "$GITHUB_OUTPUT"
+ # Unique per run: secret mounts don't participate in the layer
+ # cache key, so this busts the cache to guarantee the upload
+ # actually runs on token-bearing builds (see rust/Dockerfile).
+ echo "trigger=${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"
+ else
+ echo "Native symbol upload disabled for this build"
+ fi
+
- name: Build and push image
id: docker_build
uses: depot/build-push-action@5f3b3c2e5a00f0093de47f657aeaefcedff27d18 # v1.17.0
@@ -174,9 +197,11 @@ jobs:
EXTRA_RUSTFLAGS=${{ matrix.extra_rustflags || '' }}
EXTRA_CFLAGS=${{ matrix.extra_cflags || '' }}
SCCACHE_WEBDAV_KEY_PREFIX=${{ steps.sccache.outputs.cache-key-prefix }}
+ SYMBOL_UPLOAD_TRIGGER=${{ steps.symbols.outputs.trigger }}
secrets: |
SCCACHE_WEBDAV_ENDPOINT=${{ steps.sccache.outputs.endpoint }}
SCCACHE_WEBDAV_TOKEN=${{ steps.sccache.outputs.token }}
+ posthog_upload_symbols_cli_api_key=${{ steps.symbols.outputs.token }}
- name: Build failure properties
if: failure()
diff --git a/.github/workflows/rust-docker-build.yml b/.github/workflows/rust-docker-build.yml
index c5fbb2752f62..0a9b3b775560 100644
--- a/.github/workflows/rust-docker-build.yml
+++ b/.github/workflows/rust-docker-build.yml
@@ -99,6 +99,11 @@ jobs:
secrets:
POSTHOG_API_TOKEN: ${{ secrets.POSTHOG_API_TOKEN }}
POSTHOG_DEVEX_PROJECT_API_TOKEN: ${{ secrets.POSTHOG_DEVEX_PROJECT_API_TOKEN }}
+ # Deliberately reuses the frontend sourcemap upload key: sourcemaps and
+ # native symbols go through the same symbol-set upload API on the same
+ # internal project, so there is no separate org secret to create.
+ # Rotating POSTHOG_UPLOAD_SOURCEMAPS_CLI_API_KEY affects both uploads.
+ POSTHOG_UPLOAD_SYMBOLS_CLI_API_KEY: ${{ secrets.POSTHOG_UPLOAD_SOURCEMAPS_CLI_API_KEY }}
permissions:
id-token: write
contents: read
diff --git a/rust/Dockerfile b/rust/Dockerfile
index 2175fd273c82..1fe20dee2f63 100644
--- a/rust/Dockerfile
+++ b/rust/Dockerfile
@@ -60,6 +60,55 @@ RUN --mount=type=secret,id=SCCACHE_WEBDAV_ENDPOINT,required=false \
cargo build --release --bin $BIN ${BUILD_FEATURES:+--features $BUILD_FEATURES} && \
sccache --show-stats
+# Upload native debug symbols (with source context) to PostHog error tracking,
+# so panics and exceptions captured by common-posthog symbolicate server-side.
+# They go to the internal PostHog project (POSTHOG_CLI_ENV_ID=2 on US cloud),
+# the same project the frontend sourcemap upload in the root Dockerfile targets.
+# Runs only when CI mounts the upload token (master builds on the canonical
+# deploy repo — see _rust-build-images.yml); PR and local builds skip it.
+# Upload failures warn instead of failing the build: symbols must never block
+# shipping an image. The cargo registry cache mounts make dependency sources
+# visible to --include-source at the paths DWARF records for them.
+# No release stamping: symbolication resolves by GNU build id alone, and the
+# amd64/arm64 builds run concurrently — the CLI's lookup-then-create release
+# flow would race and drop one platform's upload.
+#
+# SYMBOL_UPLOAD_TRIGGER exists because secret mounts are not part of the layer
+# cache key: without it, a PR build's skipped-upload layer could be reused by a
+# master build and silently skip the upload. CI sets it to the unique run id
+# when the token is provided, so token-bearing builds always re-execute this
+# layer; token-less builds keep a constant empty value and stay cached.
+#
+# The CLI installer is pinned to an immutable release tag and checksum-verified
+# before execution. To upgrade, change POSTHOG_CLI_VERSION and recompute:
+# curl -LsSf "https://github.com/PostHog/posthog/releases/download/posthog-cli%2Fv<X.Y.Z>/posthog-cli-installer.sh" | sha256sum
+ARG POSTHOG_CLI_VERSION=0.8.1
+ARG POSTHOG_CLI_INSTALLER_SHA256=b1f1781a78a37930884db3ad412d9508a9ac015b01339455a7357cd0b23d9c92
+ARG SYMBOL_UPLOAD_TRIGGER=""
+RUN --mount=type=secret,id=posthog_upload_symbols_cli_api_key \
+ --mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
+ --mount=type=cache,target=/usr/local/cargo/git,sharing=locked \
+ if [ -z "$SYMBOL_UPLOAD_TRIGGER" ] || [ ! -s /run/secrets/posthog_upload_symbols_cli_api_key ]; then \
+ echo "No symbol upload trigger/token; skipping native symbol upload"; \
+ elif ( \
+ curl --proto '=https' --tlsv1.2 -LsSf -o /tmp/posthog-cli-installer.sh \
+ "https://github.com/PostHog/posthog/releases/download/posthog-cli%2Fv${POSTHOG_CLI_VERSION}/posthog-cli-installer.sh" && \
+ echo "${POSTHOG_CLI_INSTALLER_SHA256} /tmp/posthog-cli-installer.sh" | sha256sum -c - && \
+ sh /tmp/posthog-cli-installer.sh && \
+ export PATH="/root/.posthog:$PATH" && \
+ export POSTHOG_CLI_TOKEN="$(cat /run/secrets/posthog_upload_symbols_cli_api_key)" && \
+ export POSTHOG_CLI_ENV_ID=2 && \
+ mkdir -p /tmp/posthog-symbols && \
+ cp "target/release/$BIN" /tmp/posthog-symbols/ && \
+ posthog-cli symbol-sets upload \
+ --directory /tmp/posthog-symbols \
+ --include-source \
+ ); then \
+ echo "Native debug symbols uploaded for $BIN"; \
+ else \
+ echo "WARNING: native symbol upload failed for $BIN; panics from this build may not symbolicate" >&2; \
+ fi
+
FROM debian:bookworm-slim AS runtime
RUN apt-get update && \