feat(lineage): capture tool data-source refs and agent build version in span data#469
Open
max-parke-scale wants to merge 1 commit into
Open
feat(lineage): capture tool data-source refs and agent build version in span data#469max-parke-scale wants to merge 1 commit into
max-parke-scale wants to merge 1 commit into
Conversation
max-parke-scale
force-pushed
the
mparke/sgp-6513-lineage-refs
branch
2 times, most recently
from
July 22, 2026 19:41
e3f591a to
a744aa9
Compare
max-parke-scale
force-pushed
the
mparke/sgp-6513-lineage-refs
branch
2 times, most recently
from
July 22, 2026 19:49
ad6005d to
02701ce
Compare
…in span data Implements the trace data-source-ref convention (SGP-6513): tools declare which data sources they touch — statically, via an args resolver, or by name-keyed registry for MCP/unowned tools — and every tool-span path merges the resolved refs into span data under sgp.lineage.refs, which the SGP tracing processor already ships as span metadata. Capture is decoupled from lineage derivation so agents instrument from day one and edges backfill later. Also stamps __agent_version__ from a new AGENT_VERSION env var (same mechanism as __agent_name__), completing the trace-side join-key set: span -> agent version snapshot is the runtime half of SGP-6132. Convention spec: scaleapi packages/sgp-lineage/docs/specs/ 2026-07-22-sgp-6513-trace-data-source-ref-convention.md (PR #153026). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
max-parke-scale
force-pushed
the
mparke/sgp-6513-lineage-refs
branch
from
July 22, 2026 19:51
02701ce to
0361006
Compare
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.
Implements the SDK half of the trace data-source-ref convention (SGP-6513; convention spec in scaleapi#153026): tools declare which data sources they actually touch, and the refs land in span data under
sgp.lineage.refsas lineage coordinates. The SGP tracing processor already ships span data as sgp-traces span metadata, so refs are immediately filterable via the spans-searchextra_metadataDSL — no schema, processor, or service changes. Capture is decoupled from lineage derivation: agents instrument from day one and graph edges backfill later from materialized traces.Surface (
agentex.lib.adk.lineage, implementation incore/tracing/lineage.py)DataSourceRefvalidates URI-form namespaces per the lineage namespace conventions and rejects payload-shaped values; refs deduplicate by(namespace, name, version, role). Resolver failures are logged and swallowed — ref capture never breaks a tool call or its tracing.Where refs get stamped
SpanTracerresolves refs for everyOpenSpan(kind="tool")signal — one point covering all harness turns. Import is guarded so the harness stays importable without optional tracing deps (same pattern as its logger).run_agent*service paths (core/services/adk/providers/openai.py, 4 methods): refs resolve from the serializedfunction_callitems and merge onto the run span.SyncStreamingProviderand the Temporal streaming model: same item-based merge on their model spans.Agent build version stamp (
__agent_version__)The processor already env-stamps
__agent_name__/__agent_id__into every span; this adds__agent_version__from a new optionalAGENT_VERSIONenv var (image tag or git sha, set by the deployment). This completes the trace-side join-key set — span → exact agent-version snapshot instead of a temporal join against deploy history — the runtime half of SGP-6132. Unset means no stamp, so nothing changes until a deployment wires the env var; the deploy-chart wiring is a follow-up in the deployment repo.Deliberately deferred
MCP-server-side ref attachment via result
_metawith agent-side harvest (the exact-grain path for server-private dynamic sources) — needs a cross-process contract; name-keyed agent-side declaration covers current consumers.Tests
tests/lib/core/tracing/test_lineage.py(validation, registry, decorator both placements, item resolution, merge/dedupe),tests/lib/core/harness/test_tracer_lineage.py(SpanTracer stamps refs on tool spans, leaves reasoning/unregistered spans untouched), andTestSourceStampsin the SGP processor suite (__agent_version__stamped when set, omitted when unset). Full harness + tracing + temporal + adk suites green locally;ruff check/ruff formatclean.🧑💻🤖 — posted via Claude Code
Greptile Summary
This PR introduces the SDK half of the trace data-source-ref convention: tools declare which data sources they touch via
DataSourceRef, the@data_sourcesdecorator (orregister_tool_sourcesfor MCP/unowned tools), and refs land in span data undersgp.lineage.refs. It also stamps__agent_version__from a new optionalAGENT_VERSIONenv var, completing the span join-key set for trace-to-deploy-history linkage.lineage.pymodule: ImplementsDataSourceRef(Pydantic-validated URI-form namespace), a process-wide registry,resolve_refs/resolve_refs_from_itemshelpers, andmerge_refs_into_data— all with resolver-failure isolation so ref capture can never break a tool call.SpanTracerresolves refs on everyOpenSpan(kind="tool")signal; fourOpenAIServicemethods andSyncStreamingModel/TemporalStreamingModelmerge refs from serializedfunction_callitems onto their run spans.AGENT_VERSIONenv var: Added toEnvironmentVariablesand stamped by the SGP tracing processor when set; backwards-compatible (unset = no stamp).Confidence Score: 5/5
Safe to merge — changes are additive, all failure paths are swallowed by design, and no existing span data is overwritten.
The feature is purely additive: refs are merged into span.data via a copy, resolver exceptions are caught and logged, the guarded import in tracer.py keeps the harness functional if the module ever fails to import, and AGENT_VERSION is opt-in via a new optional env var. Tests cover validation, registry, decorator ordering, item resolution, merge/dedupe, and the processor stamp in both set and unset states. No existing behaviour is changed.
No files require special attention.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Tool as Tool / MCP Tool participant Registry as lineage._tool_sources participant Tracer as SpanTracer / Provider participant Span as Span.data participant Processor as SGPTracingProcessor Note over Tool,Registry: Registration (import / decorator time) Tool->>Registry: register_tool_sources(name, refs, resolver) Note over Tracer,Span: Runtime — OpenSpan(kind="tool") or function_call item Tracer->>Registry: resolve_refs(tool_name, arguments) Registry-->>Tracer: [DataSourceRef dicts] (resolver failure swallowed) Tracer->>Span: merge_refs_into_data(span.data, refs) Note over Span: sgp.lineage.refs = deduplicated refs Note over Processor,Span: On span end Processor->>Span: _add_source_to_span → __source__, __agent_name__, __agent_id__, __agent_version__ Processor->>Processor: ship span as SGP metadata (sgp-traces)Reviews (2): Last reviewed commit: "feat(lineage): capture tool data-source ..." | Re-trigger Greptile