Skip to main content
When user context is enabled, the package automatically adds the authenticated user’s ID as a user.id attribute on all traces and logs. This makes it easy to correlate telemetry data back to the user who triggered it. User context is enabled by default.

How it appears in traces

When a user is authenticated, the user.id attribute is set on the root span of each trace. Any observability backend that supports OpenTelemetry attributes — such as Jaeger, Grafana Tempo, or Honeycomb — will display this attribute alongside the span.
Root span attributes:
  http.method: GET
  http.route: /dashboard
  user.id: 42

Disabling user context

If your application has privacy requirements that prevent you from recording user identifiers in telemetry data, disable user context with:
OTEL_USER_CONTEXT=false
Or set it in config/opentelemetry.php:
'user_context' => env('OTEL_USER_CONTEXT', true),
Disable user context when handling sensitive personal data, when running in regions with strict privacy regulations, or when your users have not consented to this type of tracking.

Custom resolver

By default, only user.id is recorded. You can customize which attributes are collected by registering a resolver in your service provider’s boot method:
use Keepsuit\LaravelOpenTelemetry\Facades\OpenTelemetry;
use Illuminate\Contracts\Auth\Authenticatable;

public function boot(): void
{
    OpenTelemetry::user(function (Authenticatable $user) {
        return [
            'user.id' => $user->getAuthIdentifier(),
            'user.email' => $user->email,
        ];
    });
}
The resolver receives the authenticated Authenticatable instance and must return an associative array of attribute key-value pairs. All returned attributes are added to every root span and log record while that user is authenticated.
Be mindful of which attributes you include. Attributes like user.email can be useful for debugging, but consider your privacy policy and data retention rules before adding personally identifiable information to traces.

Build docs developers (and LLMs) love