Repository navigation
feat(claude-agent-sdk): accept a TraceConfig and use the shared tracer - #840
Merged
Merged
Conversation
Drive ClaudeAgentInstrumentor through a stand-in SDK into real spans and check each content key, the error status texts and error.type against the TraceConfig settings, and that every span key is a classified named constant. The subagent nesting cases also run through FITracer. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
ClaudeAgentInstrumentor().instrument() and instrument_claude_agent_sdk() take config, a TraceConfig, as the other framework packages do; without one, settings come from the environment when instrumentation starts. Spans go through FITracer, and a small key map tells TraceConfig which of this package's keys hold input or output content. Every span and event key is now a named constant. Requires fi-instrumentation-otel 1.3.0. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
…ectly Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
…r's TraceConfig The tracker tests now start spans on a real tracer provider with an in-memory exporter. New cases cover a plain tracer with settings from the environment, a FITracer with its own TraceConfig, error ends, and that every exported key is a classified constant. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
SubagentTracker starts its spans on a FITracer with this package's key map. A FITracer it is given keeps its own TraceConfig, over the tracer underneath; a plain tracer gets a TraceConfig read from the environment. If a FITracer's TraceConfig cannot be read, the tracker logs a warning and uses one with every content and error-details setting on. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
The scan now reports any key expression that is not a ClaudeAgentAttributes attribute: names, f-strings, concatenations, dict() keywords and ** unpacking, as well as string literals. Stores into the package's own lookup tables are listed as known non-span keys. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
…xies and wrappers Rows for a FITracer inside one or two wrapt proxies, a proxy around a FITracer whose settings cannot be read, a chain of proxies past the limit, and wrappers that are not proxies, around a FITracer and around a plain tracer. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
…entTracker SubagentTracker looks through wrapt proxies for a FITracer and uses its TraceConfig. A wrapper it cannot look through, or a chain past the limit, hides all content and error details and logs a warning. Any other tracer keeps settings read from the environment. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
…er checks The wrapper with no __wrapped__ now holds a FITracer whose own settings differ from the environment's, so the row shows which ones are used. The no-warning checks count only this package's logger, like the one-warning check. Signed-off-by: khushalsonawat <khushalsonawat@gmail.com>
khushalsonawat
marked this pull request as ready for review
December 3, 2026 06:27
cdileep23
approved these changes
Dec 3, 2026
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.
What does this PR do?
traceai-claude-agent-sdknow takes aTraceConfigand starts its spans on traceAI's shared tracer (FITracer), as the other framework packages do.ClaudeAgentInstrumentor().instrument()andinstrument_claude_agent_sdk()acceptconfig, aTraceConfig. With noconfig, settings come from theFI_*environment variables when instrumentation starts. Aconfigof another type raisesTypeError.A small key map (
_privacy.py) tellsTraceConfigwhich of this package's span keys carry input content, output content, or both:claude_agent.prompt,claude_agent.system_prompt,claude_agent.tool.inputand the fields taken from it (file path, command, pattern, URL, search query), andclaude_agent.subagent.description/.prompt;claude_agent.message.content,claude_agent.tool.output;output, andclaude_agent.tool.error_message(a failing tool's output, also treated as error detail).The key names are unchanged.
SubagentTrackerapplies the same handling to the tracer it is given. Its constructor is unchanged.FITracer, or awraptproxy around one, keeps its ownTraceConfig.FITracerwhose settings cannot be read, a wrapper that is not awraptproxy but has a__wrapped__, or a chain of more than eight proxies: all content and error details hidden, and one warning naming the tracer's type.TraceConfigread from the environment. That includes a wrapper with no__wrapped__around aFITracer.Every span and event key the package writes is now a named constant in
ClaudeAgentAttributes, with the same strings as before.Requires
fi-instrumentation-otel >= 1.3.0(the Pydantic AI package's floor), and declareswrapt, which the package now imports.Why?
So that a
TraceConfig, passed asconfigor set through theFI_*environment variables, applies to the spans this package writes. traceAI's zero-code setup passesconfig=to every framework instrumentor.What changes with no setting on
These are the shared tracer's defaults, the same as in the other framework packages. They are listed in the CHANGELOG.
FI_PII_REDACTIONand traceAI's suppress-tracing switch are honoured.claude_agent.tool.output, cut at 5,000 characters as before.error.type(_OTHERfor a failing tool).How was it tested?
pytest)ruff check/mypy: no newruff checkfindings (ruff 0.17.3). Each touched file has the same count asdevor fewer. mypy not run; the package has no mypy config.TraceConfigexample) and CHANGELOG ([Unreleased])New tests, in
tests/test_trace_config.py.ClaudeAgentInstrumentorthrough a stand-in Claude Agent SDK (a fakeclaude_agent_sdkmodule whose client calls the injected hooks) into a realTracerProviderwith an in-memory exporter.TraceConfigcontent setting, and the error-details setting, is checked on its own and in combination. Also checked: settings from the environment,instrument_claude_agent_sdk(config=…), PII redaction, and settings that should change nothing.error.typewith no setting on;dict(...)and**);SubagentTrackerwith a plain tracer, aFITracer,wraptproxies around each, a chain past the limit, and wrappers that are not proxies.tests/test_subagent_tracker.pynow starts spans on a real tracer provider, not a mock. The subagent nesting cases intests/test_hooks.pyalso run throughFITracer.Results. The whole
tests/folder: 194 passed. Python 3.11.14, opentelemetry-sdk 1.45.3, wrapt 1.17.3, and this checkout'sfi-instrumentation-otelsource (1.5.2).Not run:
Checklist
devdocs/VOCABULARY.md. That file does not exist in the repo, so no check was possible.Notes for reviewers
_privacy.pyfollowstraceai_pydantic_ai/_privacy.py: anObjectProxyover the caller'sTraceConfigthat overrides onlymask, so error-detail, PII and image handling stay with the core.SubagentTrackerreads a givenFITracer's settings in one helper (_settings_of), as cohere, crewai and together read_self_config. It usesobject.__getattribute__so a wrapped tracer's settings are not picked up by mistake. If the settings cannot be read, it logs a warning and replaces all content.