Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nemoguardrails/tracing/interaction_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ def extract_interaction_log(
return InteractionLog(
id=interaction_output.id,
activated_rails=generation_log.activated_rails,
events=generation_log.internal_events,
events=generation_log.internal_events or [],
trace=spans,
)
22 changes: 8 additions & 14 deletions nemoguardrails/tracing/span_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def extract_spans(
self, activated_rails: List[ActivatedRail]
) -> List[Union[SpanLegacy, SpanOpentelemetry]]:
"""Extract v1 spans from activated rails."""
spans: List[SpanLegacy] = []
spans: List[Union[SpanLegacy, SpanOpentelemetry]] = []
if not activated_rails:
return spans

Expand Down Expand Up @@ -165,9 +165,9 @@ def __init__(

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

interaction_span = InteractionSpan(
Expand Down Expand Up @@ -219,17 +219,11 @@ def extract_spans(
for k, v in (action.action_params or {}).items()
if isinstance(v, (str, int, float, bool))
},
error=True if hasattr(action, "error") and action.error else None,
error_type=(
type(action.error).__name__
if hasattr(action, "error") and action.error
else None
),
error_message=(
str(action.error)
if hasattr(action, "error") and action.error
else None
),
# TODO: There is no error field in ExecutedAction. The fields below are defined on BaseSpan but
# will never be set if using an ActivatedRail object to populate an ActivatedRail object.
error=None,
error_type=None,
error_message=None,
)
spans.append(action_span)

Expand Down
4 changes: 4 additions & 0 deletions nemoguardrails/tracing/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def generate_interaction_log(
if generation_log is None:
generation_log = self._generation_log

# At this point generation_log should not be None since it comes from self._generation_log
if generation_log is None:
raise Exception("Can't generate interaction log without Generation log")

interaction_log = extract_interaction_log(
interaction_output,
generation_log,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pyright = "^1.1.405"
include = [
"nemoguardrails/rails/**",
"nemoguardrails/actions/**",
"nemoguardrails/tracing/**",
"tests/test_callbacks.py",
]

Expand Down