TracekitTracekit

Laravel OpenTelemetry Queue Tracing: Verify Context

Test Laravel OpenTelemetry queue tracing across dispatch, workers, and retries. Learn when job spans share a request trace and when they do not.

Terry Osayawe4 min read
Laravel OpenTelemetry Queue Tracing: Verify Context

Laravel OpenTelemetry queue tracing has two separate jobs: record what a worker does, and carry the dispatching request's trace context into that worker. A worker span can exist even when the trace link is missing. This guide gives you a small test that distinguishes those outcomes before you trust a production trace.

If you still need the PHP extension, SDK, and exporter, start with the Laravel OpenTelemetry setup guide. This guide starts after request spans already reach your trace backend.

What must cross the queue

A normal HTTP request runs in one PHP process. A queued job can run later in another process or host. The active span in the request process does not move with the job by itself. Instrumentation must inject trace context into a safe job carrier at dispatch. The worker must extract that context before it starts the job span. The OpenTelemetry PHP propagation guide explains this process boundary.

Result in your trace viewWhat you can conclude
Request span and job span share a trace IDContext reached the worker. Check the parent or link relationship next.
Job span exists with another trace IDJob tracing works, but request-to-job propagation is not proven.
No job span appearsCheck worker instrumentation, exporter settings, sampling, and job execution.
Two job spans appear for one attemptCheck duplicate instrumentation and how each package records lifecycle events.

Do not infer a shared trace from close timestamps, matching job names, or a job ID. Compare actual trace IDs and span relationships.

Choose one instrumentation path

The OpenTelemetry PHP Laravel auto-instrumentation path creates request spans. Queue propagation depends on the queue instrumentation you install and enable. Check that your chosen package documents both injection at dispatch and extraction in the worker. The Laravel queue documentation explains job middleware, workers, retries, and failure behavior. It does not promise trace propagation.

The Tracekit Laravel package records queue job activity through Laravel's job events. Its current job listener starts a new trace when a job begins. It records completion or failure and then flushes the trace. That listener does not carry the request trace ID into the job. Use its job trace to inspect worker execution, but do not describe it as an automatic child of the dispatching request.

Avoid enabling two queue tracing packages for the same job without checking for duplicate spans. If your goal is one request-to-worker trace, select instrumentation that explicitly propagates context, or add a tested propagation step at the queue boundary.

Run a three-part test

Use a staging environment and a job that does one harmless, identifiable task. Record a test marker that contains no credentials or personal data. Keep the queue driver and worker configuration the same as production.

  1. Send one HTTP request that dispatches one job. Find the request span and write down its trace ID.
  2. Wait for a real asynchronous worker to process the job. Find the job span. Compare its trace ID with the request's trace ID, then inspect its parent or link.
  3. Trigger one controlled retry or failure. Confirm that each attempt has a clear status. Check whether context remains correct and whether the next job inherits any stale context.

This last check matters for long-running workers. A worker handles many jobs in one process. Instrumentation must detach or reset job context after each attempt. Otherwise, a later job can appear under an unrelated trace. The OpenTelemetry PHP context guide explains context storage and scope.

Test sync separately if your application uses it. A synchronous job runs inside the request process, so its trace shape cannot prove that propagation works across an asynchronous queue. Also test the actual worker runtime: PHP CLI can have different extensions and environment variables from PHP-FPM. Restart workers after instrumentation changes.

SymptomFirst checkNext action
Request trace ends at dispatchIs context injected into the job carrier?Check the queue instrumentation's dispatch hook.
Worker span starts another traceDoes the worker extract and activate context?Check worker setup and carrier support for your queue driver.
Worker span is absentDid the job run? Is the worker exporter configured?Check the queue worker, sampling, and exporter errors.
Retry uses the wrong parentDoes each attempt reset its scope?Test two jobs in sequence on one worker.
One attempt creates duplicate spansAre two packages tracing the same job?Disable one path and repeat the test.

When the trace link is absent, keep the job trace as useful evidence. It can still show duration, status, and instrumented work inside the worker. Do not change production code solely to make a diagram look continuous. First confirm what your queue package supports.

What to check in Tracekit

Use the trace view to compare request and job trace IDs. The Laravel package guide covers the Tracekit-specific installation path. The distributed tracing feature page explains how to follow instrumented work across services.

If you need request-to-job continuity, verify a compatible propagation implementation in your application. Then repeat the asynchronous worker test. Tracekit can display the resulting OTLP spans, but a trace viewer cannot repair context that the producer or worker did not carry.

Share this post

Related Posts