@@ -135,14 +135,11 @@ def test_llm_start_and_stop_creates_span(self): # pylint: disable=no-self-use
135
135
)
136
136
137
137
# Start and stop LLM invocation using context manager
138
- invocation = LLMInvocation (
139
- request_model = "test-model" ,
140
- input_messages = [message ],
141
- provider = "test-provider" ,
142
- attributes = {"custom_attr" : "value" },
143
- )
144
-
145
- with self .telemetry_handler .llm (invocation ):
138
+ with self .telemetry_handler .llm () as invocation :
139
+ invocation .request_model = "test-model"
140
+ invocation .input_messages = [message ]
141
+ invocation .provider = "test-provider"
142
+ invocation .attributes = {"custom_attr" : "value" }
146
143
assert invocation .span is not None
147
144
invocation .output_messages = [chat_generation ]
148
145
invocation .attributes .update ({"extra" : "info" })
@@ -234,20 +231,16 @@ def test_parent_child_span_relationship(self):
234
231
role = "AI" , parts = [Text (content = "ok" )], finish_reason = "stop"
235
232
)
236
233
237
- # Start parent and child using nested contexts (child becomes child span of parent)
238
- parent_invocation = LLMInvocation (
239
- request_model = "parent-model" ,
240
- input_messages = [message ],
241
- provider = "test-provider" ,
242
- )
243
- child_invocation = LLMInvocation (
244
- request_model = "child-model" ,
245
- input_messages = [message ],
246
- provider = "test-provider" ,
247
- )
248
-
249
- with self .telemetry_handler .llm (parent_invocation ):
250
- with self .telemetry_handler .llm (child_invocation ):
234
+ with self .telemetry_handler .llm () as parent_invocation :
235
+ parent_invocation .request_model = "parent-model"
236
+ parent_invocation .input_messages = [message ]
237
+ parent_invocation .provider = "test-provider"
238
+ # Perform things here, calling a tool, processing, etc.
239
+ with self .telemetry_handler .llm () as child_invocation :
240
+ child_invocation .request_model = "child-model"
241
+ child_invocation .input_messages = [message ]
242
+ child_invocation .provider = "test-provider"
243
+ # Perform things here, calling a tool, processing, etc.
251
244
# Stop child first by exiting inner context
252
245
child_invocation .output_messages = [chat_generation ]
253
246
# Then stop parent by exiting outer context
0 commit comments