Go Custom Instrumentation

AppSignal is compatible with OpenTelemetry instrumentation packages. Some of these instrumentation packages may require additional setup.

This does not always include the information you need to debug issues. For more fine-grained reporting, you can add custom instrumentation.

We support OpenTelemetry tracing as laid out in the OpenTelemetry documentation. It's possible to add more data to span using OpenTelemetry span attributes.

There are also AppSignal span attributes that can change how traces are grouped and some attributes that allow for setting sensitive data that is filtered before being sent to our servers.

The AppSignal span attributes are described in more detail in our Go Custom Instrumentation Attributes section.

Setup

When adding custom instrumentation, first import the OpenTelemetry trace package in the file you want to add the instrumentation to.

Go
import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" )

Then, using that trace package, create a new span.

Go
var tracer = otel.Tracer("my-tracer-name") func httpHandler(w http.ResponseWriter, r *http.Request) { ctx, span := tracer.Start(r.Context(), "hello-span") defer span.End() // Set attributes }

Note: In these examples we're relying on the context from the HTTP request, given by r.Context(). Receiving the context may be different in your application.

Or fetch the current active one:

Go
func httpHandler(w http.ResponseWriter, r *http.Request) { ctx := r.Context() span := trace.SpanFromContext(ctx) // Set attributes }

More ways to create and get spans is documented in the OpenTelemetry Go Manual Instrumentation page.

AppSignal attributes

Once you have created, or fetched, a span, you can set certain attributes that are specific to AppSignal to customize how the data arrives in AppSignal. Find the full list of attributes in our attributes section.

Go
span.SetAttributes(attribute.String("attribute name", "attribute value"))