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
Commit fbaac8e
Browse filesBrowse the repository at this point in the historyBrowse files
fix(ag2): honour the latest setup() TraceConfig and traceAI context
R4: a second setup(..., config=TraceConfig(hide_inputs=True,
hide_outputs=True)) on a provider that already had an AG2SpanProcessor
was silently ignored, so content was exported despite the hide request
(reviewer probe: gen_ai.input/output.messages still on the chat span).
install_span_processor now applies an explicit config to the installed
processor (AG2SpanProcessor.update_config; most recent call wins) and
logs a warning when it changes. config=None keeps the installed config,
so a later setup() never re-exposes content.
R5: on_start did nothing, so using_session / using_user / using_metadata /
using_attributes were ignored on AG2 spans. on_start now copies
fi_instrumentation get_attributes_from_context() onto AG2-scope spans
without overriding keys AG2 already set (later AG2 set_attribute calls
still win), except session.id: the context session is re-applied in
on_end so it beats a static span_attributes value. Pending sessions are
kept in a bounded map keyed by (trace_id, span_id) and released on end.
Foreign-scope spans are untouched.
README (setup, sessions, conformance table), setup()/processor docstrings
and CHANGELOG updated.
Tests first, red on ec9fc07: test_later_setup_config_replaces_installed_
processor_config, test_using_session_sets_session_on_every_ag2_span,
test_using_attributes_context_reaches_ag2_spans,
test_context_session_wins_but_other_ag2_keys_are_not_overridden,
test_pending_context_sessions_are_bounded_and_released_on_end (also red
against a no-eviction mutant: 40 == 16). Guards that stay green:
test_later_setup_without_config_keeps_installed_config,
test_context_attributes_skip_foreign_scope_spans. 70 passed on ag2 1.1.2.
approved: Nikhil 2026-10-03 blanket
Refs: TH-8236
Call `setup(tracer_provider=trace_provider)` once in that case too, so the span
89
89
processor is installed. `setup` is idempotent: an agent that already has a
90
-
`TelemetryMiddleware` is skipped.
90
+
`TelemetryMiddleware` is skipped. One `AG2SpanProcessor` serves the provider:
91
+
a later `setup(..., config=TraceConfig(...))` replaces its `TraceConfig` (the
92
+
most recent call wins and a warning is logged when it changes), while
93
+
`config=None` keeps the current one.
94
+
95
+
Sessions and users come from traceAI's context helpers, as with the other
96
+
traceAI integrations:
97
+
98
+
```python
99
+
from fi_instrumentation import using_attributes, using_session
100
+
101
+
with using_session("chat-123"):
102
+
reply =await agent.ask("Hello") # every AG2 span gets session.id="chat-123"
103
+
104
+
with using_attributes(session_id="chat-123", user_id="user-7", metadata={"tier": "pro"}):
105
+
reply =await agent.ask("Hello")
106
+
```
91
107
92
108
`provider_name` is never invented. Pass it if you want it on every span;
93
109
otherwise AG2 fills it from the model response when the client reports one.
@@ -117,8 +133,8 @@ setup(agent, tracer_provider=trace_provider, capture_content=True) # opt in
117
133
| Model |`gen_ai.request.model`, `gen_ai.response.model` pass through | When AG2 did not set them |
118
134
| Provider |`gen_ai.provider.name` from `provider_name` or the model response | When neither is known |
119
135
| Tokens |`gen_ai.usage.input_tokens` / `output_tokens` pass through; cache and thinking tokens are aliased and kept | When the usage field is zero/absent. Cost is not emitted |
120
-
| Session | Not emitted by AG2| Set it yourself: `setup(..., span_attributes={"session.id": "..."})`|
121
-
| User| Not emitted | Always|
136
+
| Session | Not emitted by AG2. `session.id` from traceAI's `using_session` / `using_attributes` context, which wins over a static value; or set it yourself: `setup(..., span_attributes={"session.id": "..."})`| When neither is set|
137
+
| User, metadata, tags |`user.id`, `metadata`, `tag.tags` (and the other traceAI context keys) from `using_user` / `using_metadata` / `using_tags` / `using_attributes`; a key AG2 or `span_attributes` already set is not overridden | When the context does not set them|
122
138
| Tools |`gen_ai.tool.name`, `gen_ai.tool.call.id`, `gen_ai.tool.type`; arguments/result only with `capture_content=True`||
123
139
| Errors | OTel status `ERROR` on failing tool / model / agent spans ||
0 commit comments