Convert an ErrorEvent to a Span
(
self,
trace_id: Optional[str] = None,
parent_span_id: Optional[str] = None,
project_id: Optional[str] = None,
)
| 585 | timestamp: Optional[datetime] = None |
| 586 | |
| 587 | async def to_span( |
| 588 | self, |
| 589 | trace_id: Optional[str] = None, |
| 590 | parent_span_id: Optional[str] = None, |
| 591 | project_id: Optional[str] = None, |
| 592 | ) -> Span: |
| 593 | """Convert an ErrorEvent to a Span""" |
| 594 | span_attributes = { |
| 595 | "error.type": self.error_type or "unknown_error", |
| 596 | "error.code": self.code if self.code else "", |
| 597 | "session.id": str(self.session_id), |
| 598 | "trigger_event.id": str(self.trigger_event_id) if self.trigger_event_id else "", |
| 599 | "trigger_event.type": str(self.trigger_event_type) if self.trigger_event_type else "", |
| 600 | } |
| 601 | |
| 602 | timestamp_ns = datetime_to_ns(self.timestamp) |
| 603 | events = [] |
| 604 | if self.details: |
| 605 | events.append( |
| 606 | { |
| 607 | "timestamp": timestamp_ns, |
| 608 | "name": "error.details", |
| 609 | "attributes": {"error.details": self.details}, |
| 610 | } |
| 611 | ) |
| 612 | if self.logs: |
| 613 | events.append( |
| 614 | {"timestamp": timestamp_ns, "name": "logs", "attributes": {"log.message": self.logs}} |
| 615 | ) |
| 616 | |
| 617 | return Span( |
| 618 | name=f"error:{self.error_type or 'unknown'}", |
| 619 | trace_id=trace_id, |
| 620 | span_id=str(self.id), |
| 621 | parent_span_id=parent_span_id, |
| 622 | kind=SpanKind.INTERNAL, |
| 623 | start_time=timestamp_ns, |
| 624 | end_time=timestamp_ns, # same as start for point-in-time event |
| 625 | project_id=project_id, |
| 626 | service_name=DEFAULT_SERVICE_NAME, |
| 627 | scope_name=f"{DEFAULT_SCOPE_NAME}.error", |
| 628 | scope_version=DEFAULT_VERSION, |
| 629 | resource_attributes={}, |
| 630 | span_attributes=span_attributes, |
| 631 | status_code="ERROR", |
| 632 | status_message=self.details |
| 633 | if self.details and len(self.details) < 100 |
| 634 | else (self.error_type or "unknown_error"), |
| 635 | events=events, |
| 636 | ) |
no test coverage detected