Skip to content

fix(tracing): the answer of a function that answers for itself carries its execution - #158

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

Copy link
Copy Markdown
Contributor

What

The answer of a function that answers for itself carries its execution. The twin of the Python pack's fix, Accenture/mercury-python#98.

  • 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. stampAnswer in bus.ts does it, called by registry.sendEvent, the one place every reply passes. The error envelope of an uncaught exception is built after the handler's context has ended, so it is stamped with the execution handed over.
  • 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 pages. The streaming guide says what the answer carries; the tracing section of the configuration guide gains the rule; one entry 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

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.

Decisions that are mine

  • 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.
  • The stream marker is read in bus.ts. event-stream.ts imports the bus and the registry, so importing streamSignal into the bus would close an import cycle.
  • 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 reply's own keys win here, the execution's in the Python 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

  • test/interceptor-answer.test.ts, nine tests: seven failed against the pack as it was; the reference test of a function that returns its answer and the guard of a call without the rpc tag passed before and after.
  • npm test: 2,945 tests, 2,869 passed, 76 skipped, none failed.
  • 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

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.sendEvent() 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.ts keeps an interceptor's execution in an AsyncLocalStorage, and
  stampAnswer 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.sendEvent calls it; the
  error envelope of an uncaught exception is stamped with the execution handed
  over, since the handler's context has ended by then.
- 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.ts 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.

test/interceptor-answer.test.ts holds it with functions that work for 300 ms:
seven 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 the entry under Fixed.

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

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@acn-ericlaw
acn-ericlaw merged commit 1dbb20a into main Dec 5, 2026
5 checks passed
acn-ericlaw added a commit that referenced this pull request Dec 5, 2026
…n answer's annotations by the Java rule (#159), both merged

Two session logs. 2026-12-05-011126: an interceptor's answer carries its execution, and the host writes the
function's record for a wire request-response call to an interceptor. 2026-12-05-013504: 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