Skip to content

Commit

Permalink
update exporter to have the attributes in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-gtokernliang committed Dec 20, 2024
1 parent 8004a55 commit f35f2b0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/trulens/experimental/otel_tracing/core/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from opentelemetry.sdk.trace import ReadableSpan
from opentelemetry.sdk.trace.export import SpanExporter
from opentelemetry.sdk.trace.export import SpanExportResult
from opentelemetry.trace import StatusCode
from trulens.core.database import connector as core_connector
from trulens.core.schema import event as event_schema

Expand All @@ -20,7 +21,7 @@ def to_timestamp(timestamp: Optional[int]) -> datetime:

class TruLensDBSpanExporter(SpanExporter):
"""
Implementation of :class:`SpanExporter` that flushes the spans to the database in the TruLens session.
Implementation of `SpanExporter` that flushes the spans to the database in the TruLens session.
"""

connector: core_connector.DBConnector
Expand All @@ -37,8 +38,15 @@ def _construct_event(self, span: ReadableSpan) -> event_schema.Event:

return event_schema.Event(
event_id=str(context.span_id),
record=span.attributes,
record_attributes={},
record={
"name": span.name,
"kind": "SPAN_KIND_TRULENS",
"parent_span_id": str(parent.span_id if parent else ""),
"status": "STATUS_CODE_ERROR"
if span.status.status_code == StatusCode.ERROR
else "STATUS_CODE_UNSET",
},
record_attributes=span.attributes,
record_type=event_schema.EventRecordType.SPAN,
resource_attributes=span.resource.attributes,
start_timestamp=to_timestamp(span.start_time),
Expand Down

0 comments on commit f35f2b0

Please sign in to comment.