Repository navigation
feat(telemetry): every sample of one MCP tool call carries its operation id (#733, slice 3) - #967
Merged
Merged
Conversation
…ion id (#733, slice 3) The samples a tool call caused were joined only by op and ts: a nested handler's sample, a worker thread's and work that outlived the call had nothing pointing to the call. capture_records() now sets a fresh operation_id in a ContextVar, so record() stamps it on every sample of that context and of contexts copied from it, including late ones. A sample outside any tool call (hooks, capture worker) carries None. Refs #733 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018kyZYuFrgtexu7G9TLud4P
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
5 tasks
Review 1 of 3: PR #967, commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #733, slice 3 (
Refs #733, the issue stays open). Root cause: the samples one MCP tool call causes were joined only byopandts(docs/audits/operation-consumption-inventory-2026-11-05.md, "No operation identity"). A nested handler's sample, a worker thread's sample and a sample recorded by work that outlives the call had nothing pointing to the call.telemetry.capture_records()(opened byTelemetryMiddlewarefor everytools/call) now sets a freshoperation_id(uuid4 hex) in aContextVar.record()stamps it on eachTelemetrySample. Every sample recorded in that context carries the same id, and so does every sample recorded in a context copied from it: arun_in_executorworker or a task that records after the call has closed. A sample recorded outside a tool call (hooks, capture worker) carriesoperation_id: null, an explicit "not attributed", not an invented id. The field reachestelemetry.jsonland the exporter's sample dict. The OTLP exporter reads onlyopand the outcome, so the id never becomes a metric attribute (unbounded cardinality, written in theTelemetryExportercontract).record()delegates its capture-or-publish tail to_deliver()so it stays under the 40-line method rule.Refs #733
Type of change
Test plan
tests_py/core/test_operation_identity_733.py(4 tests): nested and outer samples share one id; two calls get distinct ids; a worker-thread sample and a sample recorded after the call keep the caller's id; a sample outside a call hasNone. Removing theoperation_idstamp, or resetting it per sample, fails them.pytest tests_py/core tests_py/test_telemetry_middleware.py tests_py/handlers tests_py/hooks: 6735 passed, 276 skipped, 3 failed. All 3 fail the same way onmainin this container:test_wiki_coverage_dashboard.py::test_unreadable_page_is_skipped_not_fatal(runs as root, so the file is still readable) and 2 cases oftest_entry_auto_dispatch.py.pytest tests_py/infrastructure tests_py/*.py tests_py/observability tests_py/server tests_py/invariants tests_py/architecture: the only failures are 4sentence_transformers/torchtests. torch is not installed here because the proxy refusesdownload-r2.pytorch.org. This diff does not touch that code.ruff checkandruff format --check(0.17.3, the version inuv.lock) on the changed files: clean.python scripts/check_craftsmanship.py: OK.Audit notes
capture_processed, resident worker) does not run in the tool call's context, so it still carriesnulland needs the id passed explicitly through the spool; retry count; CPU time; provider usage beyondtotal_cost_usd.Coding-standards compliance
coreuses only stdlibuuid, ascore/wiki_identity.pydoes).Breaking changes
None.
telemetry.jsonllines gain one key,operation_id.Generated by Claude Code