Go error tracking installation
Contents
- 1
Install the Go SDK
RequiredInstall the PostHog Go SDK:
TerminalSource context not yet supportedThe Go SDK captures stack traces with file names, line numbers, and function names, but does not yet support source context (displaying the surrounding lines of code in the error tracking UI).
- 2
Initialize the client
RequiredGo - 3
Capture exceptions
RequiredThere are two ways to capture exceptions with the Go SDK:
Option A: Direct capture
Use
NewDefaultExceptionto capture errors directly. This automatically generates a UUID and stack trace for you.GoFor more control, build the
Exceptionstruct manually:GoTo see how
net/httpservices can automatically associate backend exceptions with frontend users, view the Go request context documentation.Option B: Automatic capture with slog
The SDK provides a
SlogCaptureHandlerthat wraps Go's standardlog/sloglogger and automatically captures log records as exceptions.By default, it captures logs at
Warninglevel and above.GoThe handler supports several configuration options:
Option Description Default WithMinCaptureLevel(level)Minimum log level to capture slog.LevelWarnWithDistinctIDFn(fn)Function to extract distinct ID from context/record Returns ""(skips capture)WithFingerprintFn(fn)Custom fingerprint for error grouping nil(PostHog assigns)WithSkip(n)Stack frames to skip 5WithStackTraceExtractor(e)Custom stack trace extractor DefaultStackTraceExtractorWithDescriptionExtractor(e)Custom description extractor ErrorExtractorError extractionThe slog handler automatically extracts error descriptions from log attributes with keys
errorerror(case-insensitive). It also supports wrapped errors via theUnwrap()interface. - 4
Verify error tracking
RecommendedTrigger a test exception to confirm events are being sent to PostHog. You should see them appear in the activity feed.
Go - 5
Upload debug symbols (macOS)
OptionalFor production Go binaries on macOS, uploading debug symbols enables server-side symbolication with full stack traces including inlined frames.
Build with uncompressed DWARF
Go compresses its embedded DWARF by default, which the symbolication server cannot read. Disable compression when building:
TerminalUpload the binary
After building, upload the binary with the PostHog CLI:
TerminalThe CLI finds the Go executable, extracts its
LC_UUID, and uploads the debug symbols. Run this as part of the same pipeline that produces your production binary — each build has its own UUID, so symbols must be re-uploaded for every build you deploy.Version requirementsMach-O executable uploads require CLI 0.8.2 or later.