Setup
When adding custom instrumentation, first import the OpenTelemetry trace package in the file you want to add the instrumentation to.Creating a new span
Using the tracer initialized during the installation, create a new span.r.Context().
Receiving the context may be different in your application.
Get the current span
You can also fetch the current span using the tracer initialized during the installation: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.Report errors
To report an error, record it on a span with the OpenTelemetryRecordError method. Pass trace.WithStackTrace(true) to include the stack trace. You can also set the span’s status to Error with SetStatus.
RecordError adds an exception event to the span with the error’s type and message, plus its stack trace when you pass trace.WithStackTrace(true). AppSignal reports these exception events as errors when they’re recorded on the root span of your service’s part of the trace, such as the span for an incoming HTTP request.
To stop AppSignal from reporting an error, add its type to the ignore_errors list. The type is the Go type of the error, and AppSignal also shows it as the error’s name. For example, every error created with errors.New has the type *errors.errorString, so adding that type ignores all of them.
Report an error from a child span
AppSignal only reports an error recorded on a child span, such as a span you created inside a request, when you add theappsignal.alert_this_error attribute set to true:
Report an error outside a request
For code that doesn’t run inside a request, such as a background job, start a new span fromcontext.Background(). This span is the root span of a new trace, so AppSignal reports errors recorded on it: