Appsignal::instrument method and customize the data sent to AppSignal using the helper methods.
Creating spans
TheAppsignal class provides a helper for creating spans.
instrument
Creates and activates a new span. Pass a closure to have the span closed automatically, or omit it to manage the span lifecycle manually.
With a closure
If you use a closure, AppSignal closes the active span automatically.PHP
Without a closure
Without a closure, theinstrument method returns an instance of the ActiveSpan class, a thin wrapper around the OpenTelemetry span and its scope. Close this span manually by calling $span->end().
PHP
Helpers
The baseAppsignal class provides helper methods to add custom data to traces or spans. The following sections describe each helper.
The code examples below assume your code is already being instrumented (for
example, inside a Laravel or Symfony route handler). If your code is not
already instrumented, you must create a root span by calling
Appsignal::instrument() and use the helpers inside of it.addAttributes
Add attributes to the current span.
PHP
addHeaders
Adds request headers to the current span. If the header name already exists, the value is overwritten. Request headers are shown for sampled traces in AppSignal. See the Request header customization guide for more information.
PHP
addTags
Add tags to the current span. Tags appear as filterable metadata in AppSignal and are prefixed with appsignal.tag. internally.
PHP
setAction
Sets the action name on the current span. AppSignal displays this as the transaction name and uses it to group samples.
PHP
setNamespace
Sets the namespace of the root span.
PHP
setParams
Set the query parameters of the incoming request. The $params must be a value that can be serialized as JSON.
PHP
setPayload
Set the payload of the incoming request. The $payload must be a value that can be serialized as JSON.
PHP
ActiveSpan
Appsignal::instrument() returns an ActiveSpan instance that proxies all standard OpenTelemetry API SpanInterface methods. If you need low-level control over the span, use these methods to attach data or events to it directly.
PHP