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
3 times, most recently
from
July 22, 2026 19:51
02701ce to
0361006
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 29, 2026 18:57
0361006 to
74b013a
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 implements the SDK side of the trace data-source-ref convention (SGP-6513): tools declare which data sources they touch via
DataSourceRef/@data_sources/register_tool_sources, and the refs are stamped into span data undersgp.lineage.refsat every capture point. It also addsAGENT_VERSIONstamping to the SGP tracing processor from a new optionalAGENT_VERSIONenv var.lineage.py: New module withDataSourceRef(URI-form namespace validation, dedup by(namespace, name, version, role)), a process-wide registry, a@data_sourcesdecorator, and helpers (resolve_refs,resolve_refs_from_items,merge_refs_into_data,record) consumed by all integration points.SpanTracer(harness, tool spans), all fourrun_agent*methods inopenai.py,SyncStreamingModel, andTemporalStreamingModel— each resolves refs from serializedfunction_callitems and merges them onto the relevant span; resolver failures are swallowed so ref capture never breaks a tool call.AGENT_VERSION: Optional env var added toEnvironmentVariablesand stamped in_add_source_to_spanalongside the existing__agent_name__/__agent_id__fields; no-op until a deployment wires the env var.Confidence Score: 5/5
Safe to merge; the change is additive and self-contained — ref capture never affects tool execution or tracing correctness, and the new env var is a no-op until wired in deployment.
All integration points follow the same defensive pattern: resolver failures are logged and swallowed, refs are only merged when non-empty, and the harness import is guarded so the module stays importable without optional tracing deps. The only finding is a misleading inline comment in the regex.
Files Needing Attention: No files require special attention.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["@data_sources decorator\nor register_tool_sources()"] --> R[("_tool_sources\nprocess-wide registry")] B["lineage.record(span, refs)"] --> M subgraph Capture["Ref capture sites"] C["SpanTracer\nOpenSpan(kind='tool')"] -->|resolve_refs| M D["OpenAIService\nrun_agent*"] -->|resolve_refs_from_items| M E["SyncStreamingModel\nget_response / stream_response"] -->|resolve_refs_from_items| M F["TemporalStreamingModel\nstream_response"] -->|resolve_refs_from_items| M end R -->|lookup by tool name| C R -->|lookup by tool name| D R -->|lookup by tool name| E R -->|lookup by tool name| F M["merge_refs_into_data()\ndedup by (ns, name, ver, role)"] --> S["span.data\nsgp.lineage.refs"] subgraph SGP["SGP processor"] G["_add_source_to_span"] -->|"__agent_version__\n(AGENT_VERSION env var)"| S endReviews (3): Last reviewed commit: "feat(lineage): capture tool data-source ..." | Re-trigger Greptile