feat(telemetry): add sampling and validator tracing spans via hooks - #1488
Open
ajbozarth wants to merge 1 commit into
Open
feat(telemetry): add sampling and validator tracing spans via hooks#1488ajbozarth wants to merge 1 commit into
ajbozarth wants to merge 1 commit into
Conversation
Add SamplingTracingPlugin and ValidationTracingPlugin, emitting `sampling` and `validation` application spans through the existing sampling and validation lifecycle hooks. - Add observe-only correlation-id fields (`sampling_id`, `validation_id`) to the sampling/validation hook payloads, minted at the dispatch sites so the paired open/close hooks correlate. - Add `start/finish_sampling_span`, `start/finish_validation_span`, and a generic `add_span_event` (renamed from `add_streaming_event`) to tracing.py; iterations and repairs are recorded as span events on the sampling span. - Fire the sampling/validation end hooks on the error path (via try/finally with an optional `exception` field) so a raised loop/check still closes its span with ERROR status; a routine budget-exhaustion or failing check closes with default status. Metrics and builtin_debug plugins skip the outcome on the exception path. - Document the new spans and corrected span hierarchy in the observability docs. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
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.
Pull Request
Issue
Fixes #1050
Description
Adds
samplingandvalidationtracing spans, emitted by two new plugins (SamplingTracingPlugin,ValidationTracingPlugin) that subscribe to the sampling and validation lifecycle hooks already dispatched byBaseSamplingStrategy.sample()andavalidate().#1050 also named the formatter, which is intentionally left out: it's a synchronous render step with no duration or place in the trace tree of its own, so it isn't a meaningful span. The data worth capturing from that path — the prompt template and its variables — is component-level information the formatter merely renders, and it belongs as attributes on the backend
chatspan, which is #1067's scope (llm.prompt_template.*).Two new plugins in
mellea/telemetry/tracing_plugins.py:SamplingTracingPlugin— emits asamplingapplication span per sampling loop, opened onsampling_loop_startand closed onsampling_loop_end. Each attempt and repair is recorded as a span event (iteration/repair) rather than a child span, so the markers stay on the one span alongside the backendchatspans the same calls emit.ValidationTracingPlugin— emits avalidationapplication span per requirement-validation batch, opened onvalidation_pre_checkand closed onvalidation_post_check.Supporting changes:
sampling_id/validation_idfields to the sampling and validation hook payloads, minted once at each dispatch site (sample()andavalidate()) so the paired open/close hooks correlate.tracing.py:start/finish_sampling_span,start/finish_validation_span, and a genericadd_span_event(renamed from the streaming-specificadd_streaming_event, now shared).sample()andavalidate()fire their end hook from atry/finallywith an optionalexceptionfield, so a raised loop/check still closes its span. ERROR status is driven only by an exception — a routine budget-exhausted loop or failing check closes with default status. The metrics andbuiltin_debugplugins skip the outcome on the exception path.samplingandvalidationspans and corrected the span-hierarchy diagrams intracing.md/telemetry.md(they referenced arequirement_validationspan that never existed — the real span isvalidation).Notes for reviewers
session → action → sampling → {chat, validation}on Python 3.12+; on ≤3.11 hook-attached spans collapse tosession(same documented degradation as all existing tracing plugins).add_streaming_event→add_span_eventrename updatesStreamingTracingPlugin's call sites; no compat shim.samplingspan covers strategies that use theBaseSamplingStrategyloop. Strategies that overridesample()with a custom loop (SOFAI, budget-forcing, majority-voting) don't emit it — that coupling is tracked as a follow-up in fix(sampling): sampling span missing for strategies that override sample() #1487, out of scope here.loop_budget/requirement_count). Relative order is unchanged: tracing (1040–1045) still precedes metrics (1050–1057).Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.