|
17 | 17 | from guardrails.classes.output_type import OT |
18 | 18 | from guardrails.classes.validation_outcome import ValidationOutcome |
19 | 19 | from guardrails.stores.context import get_guard_name |
20 | | -from guardrails.telemetry.common import get_tracer |
| 20 | +from guardrails.telemetry.common import get_tracer, add_user_attributes, serialize |
21 | 21 | from guardrails.utils.safe_get import safe_get |
22 | | -from guardrails.utils.serialization_utils import serialize |
23 | 22 | from guardrails.version import GUARDRAILS_VERSION |
24 | 23 |
|
25 | 24 |
|
@@ -73,10 +72,12 @@ def trace_step_wrapper(*args, **kwargs) -> Iteration: |
73 | 72 | try: |
74 | 73 | response = fn(*args, **kwargs) |
75 | 74 | add_step_attributes(step_span, response, *args, **kwargs) |
| 75 | + add_user_attributes(step_span) |
76 | 76 | return response |
77 | 77 | except Exception as e: |
78 | 78 | step_span.set_status(status=StatusCode.ERROR, description=str(e)) |
79 | 79 | add_step_attributes(step_span, None, *args, **kwargs) |
| 80 | + add_user_attributes(step_span) |
80 | 81 | raise e |
81 | 82 | else: |
82 | 83 | return fn(*args, **kwargs) |
@@ -112,6 +113,7 @@ def trace_stream_step_generator( |
112 | 113 | call = safe_get(args, 8, kwargs.get("call_log", None)) |
113 | 114 | iteration = call.iterations.last if call else None |
114 | 115 | add_step_attributes(step_span, iteration, *args, **kwargs) |
| 116 | + add_user_attributes(step_span) |
115 | 117 | if exception: |
116 | 118 | raise exception |
117 | 119 |
|
@@ -145,10 +147,12 @@ async def trace_async_step_wrapper(*args, **kwargs) -> Iteration: |
145 | 147 | ) as step_span: |
146 | 148 | try: |
147 | 149 | response = await fn(*args, **kwargs) |
| 150 | + add_user_attributes(step_span) |
148 | 151 | add_step_attributes(step_span, response, *args, **kwargs) |
149 | 152 | return response |
150 | 153 | except Exception as e: |
151 | 154 | step_span.set_status(status=StatusCode.ERROR, description=str(e)) |
| 155 | + add_user_attributes(step_span) |
152 | 156 | add_step_attributes(step_span, None, *args, **kwargs) |
153 | 157 | raise e |
154 | 158 |
|
|
0 commit comments