Skip to main content
The AppSignal for PHP package provides out-of-the-box instrumentations for your PHP application. However, sometimes you need fine-grained observability, which requires manual instrumentation. For these cases, use the Appsignal::instrument method and customize the data sent to AppSignal using the helper methods.
Data sent to AppSignal must not contain any personal data, such as names or email addresses. Sanitize your application’s data before sending it to AppSignal. If you need to identify a person, use alternatives like a user ID, hash, or pseudonym.

Creating spans

The Appsignal 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, the instrument 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 base Appsignal 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
See the tagging guide for more information on how tags work in AppSignal.

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