Request context
In Go, spans are linked to the request through the request’scontext.Context. Pass the request context, or a context derived from it, to instrumented libraries and to the SDK’s functions. The request context to pass depends on your framework:
Instrument libraries
Use OpenTelemetry instrumentation libraries to trace supported libraries. For example, to trace database queries made withdatabase/sql, install otelsql:
otelsql.Open instead of sql.Open, and pass the request context to your queries:
Create custom spans
For custom operations that are not covered by library instrumentation, you can create spans using the standard OpenTelemetry API. Start each span with the request context, or a context derived from it, and pass the returned context to nested operations:Capture handled errors
Apitally includes errors in request traces to help you diagnose server errors. Panics are captured automatically, as are errors that are returned to Echo or Fiber, or added to the Gin context withc.Error().
If your application handles an error itself, for example by writing an error response directly, call apitally.CaptureError() with the request context to include it in the current request trace.