Commit 20197de
fix(telemetry): emit gen_ai.workflow.nested for nested workflows
The `gen_ai.workflow.nested=true` attribute/dimension was never produced for
any nested workflow in `gen_ai.invoke_workflow.duration` metric, so root and
nested workflow invocations could not be distinguished.
Root cause was a lost OpenTelemetry context value in
`_use_invoke_workflow_span`. The "entrypoint workflow active" marker was only
`set_value`'d onto the local `otel_context` handed to
`tracer.start_as_current_span(context=...)`. OTel uses that argument solely to
resolve the new span's parent; it does not attach it as the current context.
The child telemetry context was then captured from `context_api.get_current()`,
which never carried the marker, so every downstream workflow computed
`nested=False`.
Fix: after starting the span, `context_api.attach` the marker onto the current
context (and `detach` on exit) so child nodes capturing `get_current()` observe
`nested=True`. The now-redundant `set_value` onto the local context is removed.
Extend the telemetry functional tests so the scenario runs a workflow nested
inside a workflow. All expected span trees and the invoke_workflow duration
metric now assert the inner workflow carries `gen_ai.workflow.nested=true` while
the root omits it. This case previously went uncovered.
Co-authored-by: Max Ind <maxind@google.com>
PiperOrigin-RevId: 9431536311 parent e6df097 commit 20197de
3 files changed
Lines changed: 232 additions & 47 deletions
File tree
- src/google/adk/telemetry
- tests/unittests/telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 189 | | |
194 | 190 | | |
195 | 191 | | |
| |||
207 | 203 | | |
208 | 204 | | |
209 | 205 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
215 | 214 | | |
216 | 215 | | |
217 | 216 | | |
| |||
221 | 220 | | |
222 | 221 | | |
223 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
0 commit comments