Commit e11fcdd
authored
feat: HYBIM-518 Mark root GenAI span with
Change:
1. gen_ai.conversation_root attribute
Adds a new gen_ai.conversation_root = true boolean span attribute that explicitly marks the invocation-level root GenAI span in a trace. This gives the backend a reliable way to find the "one span" that represents the entire AI invocation — carrying the user's input and the final assistant output — without relying on topology traversal.
The attribute is independent of gen_ai.conversation.id: it marks the per-trace entry point for both multi-turn conversations (where conversation.id groups turns) and single invocations (where no conversation exists).
2. Root span promoted to AgentInvocation (was Workflow)
Root spans now default to AgentInvocation (invoke_agent) instead of Workflow (invoke_workflow). This better reflects that the top-level entity in a LangGraph/CrewAI trace is an agent invocation.
Workflow root spans are still available via two opt-in mechanisms:
Environment variable: OTEL_INSTRUMENTATION_GENAI_ROOT_SPAN_AS_WORKFLOW=true
LangGraph config metadata: config = {"metadata": {"workflow_name": "My Workflow"}, ...}
When workflow_name is provided in metadata, it also becomes the span name (e.g. workflow My Workflow instead of workflow LangGraph).
The root agent span also includes improved output capture: when the LangGraph state has no AIMessages (common pattern — nodes update structured state fields), the agent's output falls back to serializing non-message state fields (triage_result, confidence_score, etc.) as a JSON summary.
3. Resume detection fix
Fixed a timing bug where gen_ai.command="resume" was set on the Python entity AFTER start_agent() had already created the OTel span (so the attribute never appeared). Now set in the attrs dict BEFORE _start_agent_invocation().
4. Renamed gen_ai.workflow.command → gen_ai.command
The command attribute (used for resume detection with value "resume") was renamed to be entity-agnostic since it now applies to both Workflow and AgentInvocation root spans.
5. Interrupt status bubbles up to root span
When a child entity (step, tool, LLM invocation) encounters a GraphInterrupt or NodeInterrupt, the root span now receives gen_ai.finish_reason="interrupted" attribute. This ensures the root span clearly reflects that the conversation was interrupted, even if the interrupt occurred deeper in the call hierarchy.gen_ai.conversation_root + promote root to AgentInvocation (#236)1 parent a769522 commit e11fcdd
19 files changed
Lines changed: 1679 additions & 270 deletions
File tree
- instrumentation-genai
- opentelemetry-instrumentation-crewai
- src/opentelemetry/instrumentation/crewai
- tests
- opentelemetry-instrumentation-langchain
- docs
- examples/sre_incident_copilot
- src/opentelemetry/instrumentation/langchain
- tests
- util/opentelemetry-util-genai
- src/opentelemetry/util/genai
- emitters
- tests
Lines changed: 32 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
182 | 187 | | |
183 | 188 | | |
184 | 189 | | |
185 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
186 | 195 | | |
187 | | - | |
| 196 | + | |
| 197 | + | |
188 | 198 | | |
189 | 199 | | |
190 | 200 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 201 | + | |
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
203 | | - | |
204 | | - | |
205 | 206 | | |
206 | | - | |
207 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
208 | 214 | | |
209 | 215 | | |
210 | 216 | | |
211 | 217 | | |
| 218 | + | |
212 | 219 | | |
213 | 220 | | |
214 | 221 | | |
215 | 222 | | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
219 | | - | |
| 226 | + | |
220 | 227 | | |
221 | | - | |
222 | | - | |
| 228 | + | |
223 | 229 | | |
224 | 230 | | |
225 | 231 | | |
| |||
228 | 234 | | |
229 | 235 | | |
230 | 236 | | |
231 | | - | |
| 237 | + | |
232 | 238 | | |
233 | 239 | | |
234 | 240 | | |
| 241 | + | |
| 242 | + | |
235 | 243 | | |
236 | 244 | | |
237 | 245 | | |
| |||
264 | 272 | | |
265 | 273 | | |
266 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
267 | 280 | | |
268 | 281 | | |
269 | 282 | | |
| |||
Lines changed: 64 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
101 | 165 | | |
102 | 166 | | |
103 | 167 | | |
| |||
0 commit comments