You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(python): one shared attachment manager in the auto module (traceai) - #692
traceai.init (the Python auto module) now hands one attachment manager to every instrumentor it enables, as attachments=. This mirrors @traceai/auto (#687) where Python allows it. Python has no HTTP wire layer, so the TS wire capture (A03/A04) has no Python counterpart.
get_attachment_manager() returns that manager, or None before init().
A borrowed manager can only gain restrictions. Auto adds the trace_config hide and PII flags to it and never removes a flag that is already set. Auto never shuts a borrowed manager down. When borrowing, the provider is built with attachments disabled, so FI_ATTACHMENTS_ENABLED=true cannot start a second manager. attachment_manager and attachment_config cannot be passed together.
Kill switch. With FI_ATTACHMENTS_ENABLED=false at init, instrumentors get the OFF arguments. If it is set after init, the core already denies every admission, and report() / attachment_status() now show disabled; a running manager's own status() does not consult the variable. A borrowed manager is not disabled permanently.
Per-call helpers:
with_attachment_capture_policy(policy, context=None) adds a CapturePolicy restriction. It is intersected deny-wins with any policy already in the context; anything that is not a CapturePolicy denies.
with_attachment_ownership(context=None) marks calls whose media your own adapter captures, so instrumentors upload nothing for them.
Both return an OpenTelemetry context. The keys are plain strings (traceai.auto.attachment_policy.v1, traceai.auto.attachment_owner.v1), the same strings as the TypeScript traceai_auto keys. Because the keys are plain strings, no package has to import another; code inside this repo should still use media_capture.CAPTURE_POLICY_KEY / OWNER_KEY rather than repeat the literals.
report() gives a content-free view:
attachments: state, queue counters, borrowed, sources, and what is unsupported.
integrations[]: one row per instrumentor package, with status and media. media is provider_adapter only when the installed instrumentor exposes its capability descriptor: for example traceai_openai, traceai_anthropic (rows also list media_operations, for example tool_result.input) and traceai_groq; the full list is in the sections below. It is session_binding for Pipecat/LiveKit when the installed package has the bind_* entry point, and unqualified otherwise.
It contains no endpoint, header or credential, and it is not a playback claim.
fi_instrumentation/attachments/media_capture.py gains a small, additive reader for the two context keys:
local_capture_policy folds the context policy in deny-only, and an owner mark sets requested=False.
Observation is unusable under an owner mark.
New public helpers there: merge_capture_policies, context_capture_policy, owned_elsewhere, CAPTURE_POLICY_KEY and OWNER_KEY.
All three Python provider adapters (OpenAI, Anthropic, Groq) go through this helper, so they honour both helpers with no adapter edits.
With attachments OFF, nothing changes
When the manager is the disabled null object (or killed by the environment variable), instrument() receives exactly the keyword arguments it received before: tracer_provider, config, attachment_manager, attachment_policy. The existing unit test that pins them is unchanged. VM proof: the same OFF probe on base and head exports identical spans and provider requests, starts no fi- thread, and registers the same fork hooks as base, none of them from attachments (see Testing).
This branch includes #693 (feat/attachments-python-mcp-agents) by merge, now at 4901f03d (per-client Claude tool-span deferral, the live-conversation gate and more image signatures; merged clean in 50370aa4). #693's MCP/agent workflow also runs on this PR.
Registry.auto_instrument accepts openai_agents / openai-agents, claude_agent_sdk / claude-agent-sdk, smolagents and firecrawl. Each one gets an explicit entry point (OpenAIAgentsInstrumentor, ClaudeAgentInstrumentor, SmolagentsInstrumentor, FirecrawlInstrumentor) and the same keyword arguments as every other instrumentor: the shared manager when capture is on, and exactly the OFF arguments when it is off. Nothing new is enabled unless it is named.
Part of TH-2379 (Linear).
What this does
traceai.init(the Python auto module) now hands one attachment manager to every instrumentor it enables, asattachments=. This mirrors@traceai/auto(#687) where Python allows it. Python has no HTTP wire layer, so the TS wire capture (A03/A04) has no Python counterpart.init(attachment_manager=...). The instrumentors also receive it asattachment_manager=, the alias feat(python): OpenAI, Anthropic and Groq attachments (images, files, computer-use screenshots, speech) #690 accepts.get_attachment_manager()returns that manager, orNonebeforeinit().trace_confighide and PII flags to it and never removes a flag that is already set. Auto never shuts a borrowed manager down. When borrowing, the provider is built with attachments disabled, soFI_ATTACHMENTS_ENABLED=truecannot start a second manager.attachment_managerandattachment_configcannot be passed together.FI_ATTACHMENTS_ENABLED=falseat init, instrumentors get the OFF arguments. If it is set after init, the core already denies every admission, andreport()/attachment_status()now showdisabled; a running manager's ownstatus()does not consult the variable. A borrowed manager is not disabled permanently.with_attachment_capture_policy(policy, context=None)adds aCapturePolicyrestriction. It is intersected deny-wins with any policy already in the context; anything that is not aCapturePolicydenies.with_attachment_ownership(context=None)marks calls whose media your own adapter captures, so instrumentors upload nothing for them.traceai.auto.attachment_policy.v1,traceai.auto.attachment_owner.v1), the same strings as the TypeScripttraceai_autokeys. Because the keys are plain strings, no package has to import another; code inside this repo should still usemedia_capture.CAPTURE_POLICY_KEY/OWNER_KEYrather than repeat the literals.report()gives a content-free view:attachments: state, queue counters,borrowed, sources, and what is unsupported.integrations[]: one row per instrumentor package, withstatusandmedia.mediaisprovider_adapteronly when the installed instrumentor exposes its capability descriptor: for exampletraceai_openai,traceai_anthropic(rows also listmedia_operations, for exampletool_result.input) andtraceai_groq; the full list is in the sections below. It issession_bindingfor Pipecat/LiveKit when the installed package has thebind_*entry point, andunqualifiedotherwise.Cross-lane touch (shared helper from #690)
fi_instrumentation/attachments/media_capture.pygains a small, additive reader for the two context keys:local_capture_policyfolds the context policy in deny-only, and an owner mark setsrequested=False.Observationis unusable under an owner mark.merge_capture_policies,context_capture_policy,owned_elsewhere,CAPTURE_POLICY_KEYandOWNER_KEY.All three Python provider adapters (OpenAI, Anthropic, Groq) go through this helper, so they honour both helpers with no adapter edits.
With attachments OFF, nothing changes
When the manager is the disabled null object (or killed by the environment variable),
instrument()receives exactly the keyword arguments it received before:tracer_provider,config,attachment_manager,attachment_policy. The existing unit test that pins them is unchanged. VM proof: the same OFF probe on base and head exports identical spans and provider requests, starts nofi-thread, and registers the same fork hooks as base, none of them from attachments (see Testing).MCP and agent media adapters (merged from #693)
This branch includes #693 (
feat/attachments-python-mcp-agents) by merge, now at4901f03d(per-client Claude tool-span deferral, the live-conversation gate and more image signatures; merged clean in50370aa4). #693's MCP/agent workflow also runs on this PR.auto_instrumentacceptsopenai_agents/openai-agents,claude_agent_sdk/claude-agent-sdk,smolagentsandfirecrawl. Each one gets an explicit entry point (OpenAIAgentsInstrumentor,ClaudeAgentInstrumentor,SmolagentsInstrumentor,FirecrawlInstrumentor) and the same keyword arguments as every other instrumentor: the shared manager when capture is on, and exactly the OFF arguments when it is off. Nothing new is enabled unless it is named.