@@ -145,9 +145,18 @@ def trace_stream_guard(
145
145
res = next (result ) # type: ignore
146
146
# FIXME: This should only be called once;
147
147
# Accumulate the validated output and call at the end
148
- add_guard_attributes (guard_span , history , res )
149
- add_user_attributes (guard_span )
150
- yield res
148
+ if not guard_span .is_recording ():
149
+ # Assuming you have a tracer instance
150
+ tracer = get_tracer (__name__ )
151
+ # Create a new span and link it to the previous span
152
+ with tracer .start_as_current_span (
153
+ "stream_guard_span" , # type: ignore
154
+ links = [Link (guard_span .get_span_context ())],
155
+ ) as new_span :
156
+ guard_span = new_span
157
+ add_guard_attributes (guard_span , history , res )
158
+ add_user_attributes (guard_span )
159
+ yield res
151
160
except StopIteration :
152
161
next_exists = False
153
162
@@ -180,6 +189,7 @@ def trace_guard_execution(
180
189
result , ValidationOutcome
181
190
):
182
191
return trace_stream_guard (guard_span , result , history )
192
+
183
193
add_guard_attributes (guard_span , history , result )
184
194
add_user_attributes (guard_span )
185
195
return result
@@ -204,14 +214,14 @@ async def trace_async_stream_guard(
204
214
tracer = get_tracer (__name__ )
205
215
# Create a new span and link it to the previous span
206
216
with tracer .start_as_current_span (
207
- "new_guard_span " , # type: ignore
217
+ "async_stream_span " , # type: ignore
208
218
links = [Link (guard_span .get_span_context ())],
209
219
) as new_span :
210
220
guard_span = new_span
211
221
212
222
add_guard_attributes (guard_span , history , res )
213
223
add_user_attributes (guard_span )
214
- yield res
224
+ yield res
215
225
except StopIteration :
216
226
next_exists = False
217
227
except StopAsyncIteration :
0 commit comments