From HTTP request to worker: tracing one application operation
Intent, delivery, attempt and effect in MySQL 8.4/InnoDB: SDK parent graphs, receipt loss and a new trace without a second local effect.
A client sends a request, the server accepts work, and the background handler's receipt never arrives. The repeated request has another request ID, the message gets another attempt, and the logs contain several similar entries. Are these independent actions or repeated attempts at one action? Even a complete trace cannot answer without a business identity and a record of the result.
Consider an executed synthetic path: acceptance → persisted intent → serialized message → worker attempt → local effect. One Symfony Demo checks persisted state in MySQL 8.4/InnoDB through native PDO and actual SDK parent contexts. Targeted checks cover redelivery, a new trace for the same intent, and local deduplication. This is a local single-caller fixture without a real broker, exporter, collector or external provider.
Which identity are we looking for?
| Identity | What it identifies | When it changes |
|---|---|---|
| Request | One HTTP reception | With each new request |
| Trace | Diagnostic context for related spans | With a new trace root |
| Span | One portion of work in a trace | For each distinct portion or attempt |
| Operation / intent | The business intention to perform work | For a different business operation |
| Delivery / attempt | A delivery and a particular processing attempt | On redelivery and a new attempt |
| Effect | A business result applied once under the contract | For another permitted effect |
These values can be joined in structured logs, but are not interchangeable. A new trace does not automatically create a new intent. One intent can survive redelivery; one delivery can finish without a receipt. A record that a handler started work alone says nothing about whether the effect committed.
Using a trace ID as the deduplication key is especially dangerous. A client can repeat the same action in a new trace. If uniqueness is based on trace ID, the database sees a new key and permits another effect. A stable operation key belongs to the business contract, and the content must be checked for immutability alongside it. Reusing the key with a different payload is a conflict, not permission to silently replace the work.
The graph crosses a process boundary
W3C Trace Context defines traceparent with version, trace ID, parent ID, and flags. For version 00, the trace ID is 16 bytes and the parent ID is 8; all-zero values are invalid. Avoid a homegrown simplified parser: the standard also defines how to handle malformed and future formats. An untrusted header does not establish identity, authorization, or ownership of an operation.
In the executed model, valid inbound context parents the HTTP span. It contains a producer span whose allowed carrier is serialized. The worker invocation reads persisted bytes, extracts context and creates a distinct attempt span. A process variable does not cross a queue: the carrier needs explicit transfer. This checks encoding and restoration, rather than real interprocess transport.
OpenTelemetry for PHP demonstrates TraceContextPropagator for injection and extraction. Messaging does not reduce to one universal tree: OpenTelemetry conventions permit the creation context as parent for processing a single message. Batches or an existing ambient span may call for links. Messaging conventions are in development, so document and revisit the choice when upgrading.
This model processes one message at a time, with no other active parent. Both redelivery attempts are therefore distinct child spans of one producer. This is the example's chosen rule, not a requirement for every queue. The relationship comes from context, not an assumption that a later clock timestamp must have been caused by an earlier one.
Intent, message, and local effect
Let op-A be one synthetic intent and effect-A its local effect. The receiver persists the operation key and a hash of precisely defined payload bytes. The payload itself does not enter telemetry. A real request's hashing format and canonicalization require a separate agreement; a hash of a low-entropy secret can also reveal information and is not automatically safe to log.
The local ledger has separate intent, delivery, attempt, and effect records in InnoDB tables. For tests, the shared guarded App\Infrastructure\MysqlLab fixture provides a disposable MySQL schema and separate migrator and runtime connections. Explicitly initialize the schema through the migrator before business transactions; runtime performs DML only, without CREATE, ALTER or DROP. MySQL DDL can cause implicit commits, so this is neither an atomic schema upgrade nor an automatic data migration from the old SQLite store. Delivery and attempt IDs differ. Message context is versioned, and its serialized bytes are restored before worker invocation. The fixture is not a real broker: it checks only the declared encoding and decoding boundary. A real transport needs separate tests of its serializer, redeliveries, failures, and header-size limits.
The effect key has a uniqueness constraint in MySQL. Checking and recording the effect share one InnoDB transaction; the verified invariant of this single-caller fixture is one local effect after repeated attempts at the same work. This does not establish behavior under arbitrary concurrency. The transaction does not cover an external API. Its result after a timeout may remain unknown and needs a separate idempotency and reconciliation contract.
Lost receipt and a new request
The first attempt committed the local effect, while a test-only flag modeled receipt loss. It recorded receipt_unknown, rather than “the effect did not happen.” Redelivery retained exact carrier bytes; a new attempt found the effect key and became deduplicated. A separate native PDO connection to the same MySQL schema independently read the committed state through SQL: one intent, two deliveries, two attempts and one effect. This is a controlled lost-receipt seam, not a real crash or lost network acknowledgement.
A second acceptance without an inbound parent created a new root trace for the same op-A and payload. The third attempt had its own producer parent but the same effect-A: a separate native PDO connection to the same MySQL schema found one intent, three deliveries, three attempts and one effect. Locate all traces through business correlation rather than trace-ID equality. Separate checks reject changed payload or effect IDs under the same business identity.
Missing or invalid context must not supply an arbitrary parent. The lab's policy is a new root trace while preserving business identity. W3C describes discarding invalid context and creating a new one; tracestate without a corresponding traceparent should not be accepted. Sampling is not a business rule either: a span may not be recorded, while commit and deduplication must work the same way. The sampled flag alone does not guarantee a trace will be stored.
Allow fields instead of cleaning everything afterward
Start with an empty set of fields. The synthetic lab allows event name, artificial request/operation/delivery/attempt/effect IDs, trace/span IDs, state, and a reason from a bounded list. No arbitrary request object, exception message, authorization header, query string, email address, or payload is copied to a log. Even allowed identifiers can be personal data elsewhere: assess their generation, access, and retention separately.
The checks cover canary strings in payload, authorization, query and exception text, plus whether structured-event and carrier keys match their allowlists. This is a finite check of specific sentinel inputs, rather than a guarantee against every leak or proof of third-party logger/tracer safety.
What was established
An SDK onStart probe recorded seven span contexts and their actual parents: inbound → HTTP1 → producer1; producer1 → attempt1 and attempt2; separate HTTP2 → producer2 → attempt3. This checks parent context rather than merely equal trace IDs. Two new kernel checks obtained 202 from the test-only POST route and 404 in dev, where the route is absent. This does not establish public authentication or production tracing.
The example uses OpenTelemetry API 1.11.0, SDK 1.16.1 and nyholm/psr7 1.8.2. Adding tracing introduced thirteen dev/transitive packages; all 105 previous package records remained unchanged. Moving storage to MySQL did not change package versions. The SDK is created locally without an exporter, collector or global SDK registration, and there are no external service calls. Native PDO does connect to MySQL over the network; that is distinct from an HTTP call to an external provider. This article's observation and targeted tests do not replace a full regression gate.
When investigating an incident, start with the work identifier available to an authorized operator and find related request and attempt records. Inspect each trace's causal edges and the effect ledger in its source of truth. If a span is missing, record the gap: sampling, a lost carrier, or missing instrumentation are possible causes. None alone establishes whether the effect occurred. Likewise, a successful HTTP span may only mean that the intent was accepted, not that background work finished. A status must name the boundary it actually describes.
A trace helps locate a particular execution path; a stable business key finds the same work across several paths. The durable effect record answers a different question: what was committed. Keeping these answers distinct makes a retry easier to understand even when telemetry is incomplete.
The shared MySQL fixture and its files are introduced in the transaction chapter. Run commands from the single article_demo root; do not create a separate Symfony application for each article.
Check the current example against an owned disposable MySQL schema:
bash fixtures/mysql_labs/run.sh php vendor/bin/phpunit tests/TraceLab