Skip to content

Commit 355faa6

Browse files
committed
chore(types): Type-clean tracing (10 errors) (#1388)
* Cleaned tracing/ directory * Add nemoguardrails/tracing to pyright pre-commit list
1 parent 077df2b commit 355faa6

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

nemoguardrails/tracing/interaction_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ def extract_interaction_log(
7878
return InteractionLog(
7979
id=interaction_output.id,
8080
activated_rails=generation_log.activated_rails,
81-
events=generation_log.internal_events,
81+
events=generation_log.internal_events or [],
8282
trace=spans,
8383
)

nemoguardrails/tracing/span_extractors.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def extract_spans(
5959
self, activated_rails: List[ActivatedRail]
6060
) -> List[Union[SpanLegacy, SpanOpentelemetry]]:
6161
"""Extract v1 spans from activated rails."""
62-
spans: List[SpanLegacy] = []
62+
spans: List[Union[SpanLegacy, SpanOpentelemetry]] = []
6363
if not activated_rails:
6464
return spans
6565

@@ -165,9 +165,9 @@ def __init__(
165165

166166
def extract_spans(
167167
self, activated_rails: List[ActivatedRail]
168-
) -> List[Union[SpanLegacy, SpanOpentelemetry, TypedSpan]]:
168+
) -> List[Union[SpanLegacy, SpanOpentelemetry]]:
169169
"""Extract v2 spans from activated rails with OpenTelemetry attributes."""
170-
spans: List[TypedSpan] = []
170+
spans: List[Union[SpanLegacy, SpanOpentelemetry]] = []
171171
ref_time = activated_rails[0].started_at or 0.0
172172

173173
interaction_span = InteractionSpan(
@@ -219,17 +219,11 @@ def extract_spans(
219219
for k, v in (action.action_params or {}).items()
220220
if isinstance(v, (str, int, float, bool))
221221
},
222-
error=True if hasattr(action, "error") and action.error else None,
223-
error_type=(
224-
type(action.error).__name__
225-
if hasattr(action, "error") and action.error
226-
else None
227-
),
228-
error_message=(
229-
str(action.error)
230-
if hasattr(action, "error") and action.error
231-
else None
232-
),
222+
# TODO: There is no error field in ExecutedAction. The fields below are defined on BaseSpan but
223+
# will never be set if using an ActivatedRail object to populate an ActivatedRail object.
224+
error=None,
225+
error_type=None,
226+
error_message=None,
233227
)
234228
spans.append(action_span)
235229

nemoguardrails/tracing/tracer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def generate_interaction_log(
6666
if generation_log is None:
6767
generation_log = self._generation_log
6868

69+
# At this point generation_log should not be None since it comes from self._generation_log
70+
if generation_log is None:
71+
raise Exception("Can't generate interaction log without Generation log")
72+
6973
interaction_log = extract_interaction_log(
7074
interaction_output,
7175
generation_log,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pyright = "^1.1.405"
157157
include = [
158158
"nemoguardrails/rails/**",
159159
"nemoguardrails/actions/**",
160+
"nemoguardrails/tracing/**",
160161
"tests/test_callbacks.py",
161162
]
162163

0 commit comments

Comments
 (0)