OpenTelemetry facade provides a single entry point to all three OTel signals — tracing, metrics, and logging — and exposes the user context resolver configuration. The individual Tracer, Meter, and Logger facades remain fully functional and are the recommended way to access each signal directly; OpenTelemetry is useful when you need to access multiple signals or configure cross-cutting behaviour from a single import.
tracer()
Resolves and returns the Tracer instance from the service container.
The application’s
Tracer instance.meter()
Resolves and returns the Meter instance from the service container.
The application’s
Meter instance.logger()
Resolves and returns the Logger instance from the service container.
The application’s
Logger instance.user()
Registers a resolver closure that is called whenever user context attributes need to be collected for a trace span or log record. The closure receives the currently authenticated Authenticatable instance and must return an associative array of attribute key-value pairs.
A closure with the signature
function (Authenticatable $user): array. The array must use non-empty string keys mapped to scalar or array values.AppServiceProvider (or any service provider’s boot method):
opentelemetry.user_context is true (the default), this resolver is invoked automatically for every trace span and every log record emitted through the Logger facade.
If no custom resolver is registered, the package defaults to including only
user.id using $user->getAuthIdentifier().collectUserContext()
Invokes the registered user context resolver for the given Authenticatable instance and returns the resulting attributes array. This method is called internally by the tracing and logging layers.
The authenticated user to collect context for.
An associative array of
non-empty-string => bool|int|float|string|array|null attribute pairs returned by the registered resolver.flush()
Force-flushes all pending telemetry data across all three signals — traces, metrics, and logs — immediately. Use this in long-running processes (queue workers, Octane) when you need to guarantee that data is exported without waiting for the next batch interval or process shutdown.
In worker mode, the package can be configured to flush automatically after each iteration (HTTP request, queue job) via the
OTEL_WORKER_MODE_FLUSH_AFTER_EACH_ITERATION environment variable. Manual calls to flush() are typically only needed outside of that automatic lifecycle.Relationship to individual facades
TheTracer, Meter, and Logger facades are independent and resolve the same underlying service container bindings as OpenTelemetry::tracer(), OpenTelemetry::meter(), and OpenTelemetry::logger(). You can use them interchangeably:
Tracer, Meter, Logger) for single-signal usage. Use the OpenTelemetry facade when you need cross-signal access or are configuring global behaviour such as the user context resolver.