Skip to content

Commit 50c9b5e

Browse files
committed
renable some tracing cleanup
1 parent bdbb82c commit 50c9b5e

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

guardrails/telemetry/guard_tracing.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
)
1212

1313
from opentelemetry import context, trace
14-
from opentelemetry.trace import StatusCode, Tracer, Span
14+
from opentelemetry.trace import StatusCode, Tracer, Span, Link, get_tracer
1515

1616
from guardrails.settings import settings
1717
from guardrails.classes.generic.stack import Stack
@@ -145,18 +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-
# 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)
159-
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
160160
except StopIteration:
161161
next_exists = False
162162

@@ -209,19 +209,19 @@ async def trace_async_stream_guard(
209209
while next_exists:
210210
try:
211211
res = await anext(result) # type: ignore
212-
# if not guard_span.is_recording():
213-
# Assuming you have a tracer instance
214-
# tracer = get_tracer(__name__)
215-
# # Create a new span and link it to the previous span
216-
# with tracer.start_as_current_span(
217-
# "new_guard_span", # type: ignore
218-
# links=[Link(guard_span.get_span_context())],
219-
# ) as new_span:
220-
# guard_span = new_span
221-
222-
# add_guard_attributes(guard_span, history, res)
223-
# add_user_attributes(guard_span)
224-
yield res
212+
if not guard_span.is_recording():
213+
# Assuming you have a tracer instance
214+
tracer = get_tracer(__name__)
215+
# Create a new span and link it to the previous span
216+
with tracer.start_as_current_span(
217+
"async_stream_span", # type: ignore
218+
links=[Link(guard_span.get_span_context())],
219+
) as new_span:
220+
guard_span = new_span
221+
222+
add_guard_attributes(guard_span, history, res)
223+
add_user_attributes(guard_span)
224+
yield res
225225
except StopIteration:
226226
next_exists = False
227227
except StopAsyncIteration:

0 commit comments

Comments
 (0)