Star us on GitHub
Star
Menu

Manual Go Tracing

Learn how to set up highlight.io tracing for your Go application.
1
Install the Highlight Go SDK.

Install the highlight-go package with go get.

go get -u github.com/highlight/highlight/sdk/highlight-go
Copy
2
Initialize the Highlight Go SDK.

highlight.Start starts a goroutine for recording and sending backend traces and errors. Setting your project id lets Highlight record errors for background tasks and processes that aren't associated with a frontend session.

import ( "github.com/highlight/highlight/sdk/highlight-go" ) func main() { // ... highlight.SetProjectID("<YOUR_PROJECT_ID>") highlight.Start( highlight.WithServiceName("my-app"), highlight.WithServiceVersion("git-sha"), ) defer highlight.Stop() // ... }
Copy
3
Wrap your code using the Go SDK.

By wrapping your code with StartTrace and EndTrace, the Highlight Go SDK will record a span. You can create more child spans using the child context or add custom attributes to each span.

import ( "github.com/highlight/highlight/sdk/highlight-go" "go.opentelemetry.io/otel/attribute" ) func functionToTrace(ctx context.Context, input int) { s, childContext := highlight.StartTrace(ctx, "functionToTrace", attribute.Int("custom_property", input)) // ... anotherFunction(childContext) // ... highlight.EndTrace(s) } func anotherFunction(ctx context.Context) { s, _ := highlight.StartTrace(ctx, "anotherFunction") // ... highlight.EndTrace(s) }
Copy
4
Verify your backend traces are being recorded.

Visit the highlight traces portal and check that backend traces are coming in.