Skip to content

Commit 59117cc

Browse files
committed
fix span error
1 parent ec60285 commit 59117cc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

guardrails/telemetry/guard_tracing.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,17 @@ 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)
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+
"new_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)
150159
yield res
151160
except StopIteration:
152161
next_exists = False

0 commit comments

Comments
 (0)