: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(cymbal): support go binaries in native symbolication (#63348)
Catalin Irimiec334e9f9c3c5
diff --git a/cli/.sampo/changesets/go-build-id-guidance.md b/cli/.sampo/changesets/go-build-id-guidance.mdnew file mode 100644index 000000000000..b4a53fc57f34--- /dev/null+++ b/cli/.sampo/changesets/go-build-id-guidance.md@@ -0,0 +1,5 @@+---+cargo/posthog-cli: patch+---++Mention Go's `-ldflags=-B=gobuildid` when `symbol-sets upload` finds ELF files without a GNU build id, since Go binaries don't emit one by default.diff --git a/cli/src/debug_symbols/mod.rs b/cli/src/debug_symbols/mod.rsindex 2b006927da5c..446161798d93 100644--- a/cli/src/debug_symbols/mod.rs+++ b/cli/src/debug_symbols/mod.rs@@ -314,7 +314,8 @@ pub fn report_problems(report: &DiscoveryReport, directory: &Path) -> Result<()>"The following files have debug info but no GNU build id, so they cannot be \matched to crash events:\n{listing}\n\Link with `-Wl,--build-id=sha1` (in Rust: `-C link-arg=-Wl,--build-id=sha1` \- via RUSTFLAGS); most toolchains add this by default."+ via RUSTFLAGS; in Go: `-ldflags=-B=gobuildid`); most C/C++/Rust \+ toolchains add this by default, Go does not.");// Only fail the run when there's nothing valid to upload; otherwise a// stray build-id-less helper binary would block every valid symbol.diff --git a/rust/cymbal/src/core/types/langs/native.rs b/rust/cymbal/src/core/types/langs/native.rsindex 3bfd5076b4c9..6c03a9540cfb 100644--- a/rust/cymbal/src/core/types/langs/native.rs+++ b/rust/cymbal/src/core/types/langs/native.rs@@ -320,6 +320,7 @@ impl RawNativeFrame {fn lang_for(&self, filename: Option<&str>) -> String {match filename.and_then(|f| f.rsplit('.').next()) {Some("rs") => "rust".to_string(),+ Some("go") => "go".to_string(),Some("c") => "c".to_string(),Some("cpp" | "cc" | "cxx" | "hpp" | "hh" | "hxx") => "cpp".to_string(),// `.h` is ambiguous across C/C++/Objective-C, so default to C.@@ -927,6 +928,44 @@ mod test {assert_eq!(resolved.resolved_name.as_deref(), Some("inner_function"));}+ /// A Go-built binary: Go function naming, non-PIE link base, and+ /// mid-stack inline expansion (transform inlined into process).+ #[sqlx::test(migrations = "./tests/test_migrations")]+ async fn test_native_go_symbolication_with_inline(db: sqlx::PgPool) {+ use crate::frames::RawFrame;++ const ELF_ZST: &[u8] = include_bytes!("../../../../tests/static/native/test_go_binary.zst");+ let elf = zstd::decode_all(ELF_ZST).unwrap();+ let chunk_id = "ebfd4909-422d-83e9-9d6b-eb2083ab3189";+ let catalog = catalog_for_chunk(&db, chunk_id, zip_fixture(&elf, None)).await;++ // Go links non-PIE at 0x400000 on linux/amd64 by default, so the+ // runtime image base equals the link-time base. 0x7e7a2 is inside+ // main.transform as inlined into main.process; the -1 adjustment+ // lands the lookup on 0x7e7a1.+ let image_base = 0x400000u64;+ let mut raw = native_frame_at(image_base + 0x7e7a2, image_base);+ raw.lang = Some("go".to_string());+ let frame = RawFrame::Native(raw);+ let debug_images = vec![debug_image_at(chunk_id, image_base)];++ let frames = frame.resolve(1, &catalog, &debug_images, 15).await.unwrap();++ assert_eq!(frames.len(), 2, "expected 2 frames, got: {frames:#?}");+ assert!(frames.iter().all(|f| f.resolved));++ // Outermost first: the physical function, then the inlined callee+ assert_eq!(frames[0].resolved_name.as_deref(), Some("main.process"));+ assert_eq!(frames[0].source.as_deref(), Some("test_go.go"));+ assert_eq!(frames[0].line, Some(10));+ assert_eq!(frames[0].lang, "go");++ assert_eq!(frames[1].resolved_name.as_deref(), Some("main.transform"));+ assert_eq!(frames[1].source.as_deref(), Some("test_go.go"));+ assert_eq!(frames[1].line, Some(16));+ assert_eq!(frames[1].lang, "go");+ }+/// Missing symbol set: the frame falls back to client-side enrichment and/// records the failure reason instead of erroring the event.#[sqlx::test(migrations = "./tests/test_migrations")]diff --git a/rust/cymbal/tests/static/native/build.sh b/rust/cymbal/tests/static/native/build.shindex 51caa0e433b9..44d5b012f197 100755--- a/rust/cymbal/tests/static/native/build.sh+++ b/rust/cymbal/tests/static/native/build.sh@@ -5,6 +5,7 @@# - zig (any recent version; used as a hermetic x86_64-linux cross C compiler/linker)# - llvm-objcopy (e.g. from an llvm toolchain)# - rustup with the x86_64-unknown-linux-gnu target installed+# - a Go toolchain (for the Go fixture)# (rustup target add x86_64-unknown-linux-gnu)## DWARF source paths are remapped to the stable prefix /cymbal_tests/native so@@ -61,6 +62,12 @@ rm .zigcc-x86_64-linuxzstd -19 -f -q test_rust_binaryrm test_rust_binary+# Go fixture: real Go function naming and mid-stack inlining. -B gobuildid+# derives the GNU build id from the Go build ID; committed zstd-compressed.+GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-B gobuildid" -o test_go_binary test_go.go+zstd -19 -f -q test_go_binary+rm test_go_binary+echo "Built fixtures:"file test_binary_nopie test_binary_pie test_binary_inline test_binary_nodebug test_binary_nobuildid-ls -la test_rust_binary.zst+ls -la test_rust_binary.zst test_go_binary.zstdiff --git a/rust/cymbal/tests/static/native/test_go.go b/rust/cymbal/tests/static/native/test_go.gonew file mode 100644index 000000000000..357017594adb--- /dev/null+++ b/rust/cymbal/tests/static/native/test_go.go@@ -0,0 +1,24 @@+// Minimal Go test binary for ELF/DWARF symbolication testing, exercising Go+// function naming and mid-stack inlining. See build.sh.+package main++import "os"++//go:noinline+func process(value int) int {+ // Line 10 - this should be symbolicated+ return transform(value) + 1+}++// transform is small enough for the compiler to inline into process.+func transform(value int) int {+ doubled := value * 2+ doubled += value / 3+ // Line 16 - this should appear as an inlined frame+ return doubled + 5+}++func main() {+ // Line 22+ os.Exit(process(len(os.Args)) & 1)+}diff --git a/rust/cymbal/tests/static/native/test_go_binary.zst b/rust/cymbal/tests/static/native/test_go_binary.zstnew file mode 100755index 000000000000..6a887f1ed89dBinary files /dev/null and b/rust/cymbal/tests/static/native/test_go_binary.zst differ