Skip to content

fix(tracing): the answer of a function that answers for itself carries its execution, and a caller's record holds its annotations - #98

Merged
acn-ericlaw merged 1 commit into
mainfrom
fix/interceptor-answer-trace-context
Dec 5, 2026
Merged

acn-ericlaw merged 1 commit into
mainfrom
fix/interceptor-answer-trace-context

Conversation

@acn-ericlaw

@acn-ericlaw acn-ericlaw commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

The answer of a function that answers for itself carries its execution, and a caller's trace record holds its annotations under annotations. The twin of the Node.js pack's fix, Accenture/mercury-nodejs#158.

  • The answer. An unmarked envelope that an interceptor sends from inside its execution to the request's reply address takes the execution's span, its annotations and the time since the execution started, and the sender and the trace where it has none. stamp_answer in bus.py does it, called by registry.send_event, the one place every reply passes; the error envelope of an uncaught exception is covered by the same call.
  • What is left alone. An envelope to another route, a stream's segments (the stream writer stamps those), and the exec_time and sender of an answer passed on from another function.
  • The wire path. For a request-response call that arrives at /api/event for an interceptor, the host writes the function's round-trip record, also when the call times out, as it does for a function that returns its answer.
  • The key. EventBus.emit writes a caller's annotations under annotations.
  • The pages. The streaming guide names registry.send_event() and says what the answer carries; the tracing section of the configuration guide gains the rule; two entries under Fixed in the CHANGELOG.

Why

The engines' HTTP client answers for itself, and its record of a request-response call held no annotation, no span and no execution time; that was fixed in mercury-composable #715 and #716. The maintainer asked whether the flaw applies to the packs, and then for the fix. Execution time matters here because the DevSecOps team relies on it for performance reporting.

The packs have no HTTP client function; the flaw was general. The caller writes the record of a request-response call from the first reply, and a reply that a handler built and sent itself carried nothing of its execution. Measured with a function that works for 300 ms, before this change:

Call to an interceptor Before
Request-response, local a record with no exec_time, no span_id, no annotations
Request-response through /api/event no record of the function at all; the calling engine read an answer without them
With a reply route the interceptor's own record was right; the function that received the answer ran untraced

Found at the build: a caller's record has held the responder's annotations under the key notes since the record was introduced in 4.12.30. A quality round renamed a parameter that shadowed annotations and the key with it. Every other record, the Node.js pack and the engines write annotations, and the OpenTelemetry forwarder's span mapping reads that key, so those annotations were on the log line under another name and on no exported span.

Upgrade notes

  • The record of a request-response call to an interceptor gains exec_time, span_id and its annotations.
  • A wire request-response call to an interceptor leaves one more record, the function's.
  • A function that an interceptor answers through a reply route is traced, as the child of the interceptor's span.
  • A log query that reads notes of a distributed.tracing record reads annotations.

Decisions that are mine

  • The notes fix rides in this commit, because the record it repairs is the one the new tests read. It can be split into a pull request of its own.
  • The host's new record is written only for a call with the rpc tag, so any other call keeps the one record its execution writes. A test holds that.
  • The span is the execution's; the time is kept when the envelope has one. The record is the caller's record of its call to this function, and a relayed answer says how long its writer took.
  • A declared limit: a handler that returns before its answer is sent. The answer is stamped with the time until it was sent; the worker's own record, written for a call with a reply route, holds the time until the handler returned.

Seen beside it, not changed

  • The two packs' workers merge an answer's annotations in opposite orders: the execution's keys win here, the reply's own in the Node.js pack. Each pack's stamp follows its own worker.
  • A single-shot answer relayed by the host keeps the internal sink's route name in its to field on the wire, where a stream's envelopes are cleared of it.

How it was checked

  • tests/test_interceptor_answer.py, nine tests: eight failed against the pack as it was; the ninth guards a call without the rpc tag against a second record and passed before and after.
  • pytest: 3,025 passed, 76 skipped. ruff check .: clean. basedpyright: 0 errors.
  • mkdocs build --strict passes; the CHANGELOG's released sections equal the newest tag's text.
  • Not run: a live drive from an engine.

Co-Authored-By: Claude Fable 5.2 noreply@anthropic.com

🤖 Generated with Claude Code

…s its execution, and a caller's record holds its annotations

An interceptor answers through its reply address, and the caller writes the
trace record of a request-response call from that answer. An answer that a
handler built and sent with registry.send_event() carried nothing of the
execution: the record held no exec_time, no span_id and no annotations, and a
function that received the answer through a reply route ran untraced.

- bus.py keeps an interceptor's execution in a context variable, and
  stamp_answer gives an unmarked envelope sent from inside it to the request's
  reply address the execution's span, annotations and elapsed time, and the
  sender and the trace where it has none. registry.send_event calls it, so the
  error envelope of an uncaught exception is covered too.
- An envelope to another route is not touched, a stream's segments stay the
  stream writer's, and a relayed answer keeps its writer's time and sender.
- server.py writes the function's round-trip record for a wire
  request-response call to an interceptor, also when it times out, as it does
  for a function that returns its answer.
- EventBus.emit writes a caller's annotations under "annotations": the key was
  "notes" since the record was introduced in 4.12.30, where every other
  record and the forwarder's span mapping use "annotations".

tests/test_interceptor_answer.py holds it with functions that work for 300 ms:
eight of its nine tests failed against the pack as it was. The streaming guide
and the tracing section of the configuration guide say what the answer
carries, and the CHANGELOG has two entries under Fixed.

The twin of the engines' fix for their HTTP client (mercury-composable #715
and #716) and of the Node.js pack's fix.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@acn-ericlaw
acn-ericlaw merged commit df90f71 into main Dec 5, 2026
6 checks passed
@acn-ericlaw
acn-ericlaw deleted the fix/interceptor-answer-trace-context branch December 5, 2026 01:29
acn-ericlaw added a commit that referenced this pull request Dec 5, 2026
… answer's annotations by the Java rule (#99), both merged

Two session logs. 2026-12-05-011101: an interceptor's answer carries its execution, the host writes the
function's record for a wire request-response call to an interceptor, and a caller's record holds its
annotations under "annotations". 2026-12-05-013448: the worker and the stamp set an answer's annotations from
the execution, as the Java engine's worker does; a finding about that engine corrected by a probe and pinned by
a test.

Continuity: trace-records-engine-parity gains both and is active again; the fact footers are refreshed from the
reference logs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant