Browser
Server
Native OpenTelemetry
Fullstack Frameworks
Overview
Self Host & Local Dev
Menu
GORM Tracing Quick Start
Learn how to set up auto-instrumented tracing for your database calls using the GORM library.
1
Configure client-side Highlight. (optional)
If you're using Highlight on the frontend for your application, make sure you've initialized it correctly and followed the fullstack mapping guide.
2
Install the Highlight Go SDK.
Install the highlight-go package with go get.
go get -u github.com/highlight/highlight/sdk/highlight-go3
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() // ... }4
Initialize the GORM library with the Highlight hooks
Import the Highlight GORM library and call the SetupGORMOTel hook with any attributes wanted for context.
import ( "github.com/highlight/highlight/sdk/highlight-go" htrace "github.com/highlight/highlight/sdk/highlight-go/trace" "go.opentelemetry.io/otel/attribute" ) DB, err = gorm.Open(<DB_SETTINGS>) if err := htrace.SetupGORMOTel(DB, highlight.GetProjectID()); err != nil { highlight.RecordError(ctx, err) }5
Call GORM with the trace context
When making any database calls with GORM, attach a WithContext hook to provide more data about the trace.
DB.WithContext(ctx).Find(&user) 6
Verify your backend traces are being recorded.
Visit the highlight traces portal and check that backend traces are coming in.