@@ -145,9 +145,18 @@ def trace_stream_guard(
145145 res = next (result ) # type: ignore
146146 # FIXME: This should only be called once;
147147 # 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
151160 except StopIteration :
152161 next_exists = False
153162
@@ -180,6 +189,7 @@ def trace_guard_execution(
180189 result , ValidationOutcome
181190 ):
182191 return trace_stream_guard (guard_span , result , history )
192+
183193 add_guard_attributes (guard_span , history , result )
184194 add_user_attributes (guard_span )
185195 return result
@@ -204,14 +214,14 @@ async def trace_async_stream_guard(
204214 tracer = get_tracer (__name__ )
205215 # Create a new span and link it to the previous span
206216 with tracer .start_as_current_span (
207- "new_guard_span " , # type: ignore
217+ "async_stream_span " , # type: ignore
208218 links = [Link (guard_span .get_span_context ())],
209219 ) as new_span :
210220 guard_span = new_span
211221
212222 add_guard_attributes (guard_span , history , res )
213223 add_user_attributes (guard_span )
214- yield res
224+ yield res
215225 except StopIteration :
216226 next_exists = False
217227 except StopAsyncIteration :
0 commit comments