ErrorEvent becomes a (child) Span
| 570 | |
| 571 | |
| 572 | class ErrorEvent(BaseModel): |
| 573 | """ |
| 574 | ErrorEvent becomes a (child) Span |
| 575 | """ |
| 576 | |
| 577 | id: Optional[int] = pydantic.Field(default=uuid4()) |
| 578 | session_id: Optional[UUID] = None |
| 579 | trigger_event_id: Optional[UUID] = None |
| 580 | trigger_event_type: Optional[str] = None |
| 581 | error_type: Optional[str] = None |
| 582 | code: Optional[str] = None |
| 583 | details: Optional[str] = None |
| 584 | logs: 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={}, |
no outgoing calls
no test coverage detected
searching dependent graphs…