Skip to content

Commit

Permalink
Phs 602 traceviewer backend (#930)
Browse files Browse the repository at this point in the history
* fix: add missing exports

* refac: Type discrimination via Literal when validating BaseModel
  • Loading branch information
FelixFehse authored Jun 26, 2024
1 parent fa52ada commit 4a82a2d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
...

### Fixes
...
- Serialization and Deserialization of `Union[SpanAttributes, TaskSpanAttributes]` is working now.

### Deprecations
...
Expand Down
5 changes: 5 additions & 0 deletions src/intelligence_layer/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@
from .tracer.persistent_tracer import StartSpan as StartSpan
from .tracer.persistent_tracer import StartTask as StartTask
from .tracer.persistent_tracer import TracerLogEntryFailed as TracerLogEntryFailed
from .tracer.tracer import Context as Context
from .tracer.tracer import ErrorValue as ErrorValue
from .tracer.tracer import Event as Event
from .tracer.tracer import ExportedSpan as ExportedSpan
from .tracer.tracer import ExportedSpanList as ExportedSpanList
from .tracer.tracer import JsonSerializer as JsonSerializer
from .tracer.tracer import NoOpTracer as NoOpTracer
from .tracer.tracer import PydanticSerializable as PydanticSerializable
from .tracer.tracer import Span as Span
from .tracer.tracer import SpanAttributes as SpanAttributes
from .tracer.tracer import SpanStatus as SpanStatus
from .tracer.tracer import SpanType as SpanType
from .tracer.tracer import TaskSpan as TaskSpan
Expand Down
10 changes: 5 additions & 5 deletions src/intelligence_layer/core/tracer/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime, timezone
from enum import Enum
from types import TracebackType
from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, Literal, Optional, Union
from uuid import UUID, uuid4

import requests
Expand Down Expand Up @@ -60,17 +60,17 @@ class Event(BaseModel):
timestamp: datetime = Field(default_factory=utc_now)


class SpanType(Enum):
class SpanType(str, Enum):
SPAN = "SPAN"
TASK_SPAN = "TASK_SPAN"


class SpanAttributes(BaseModel):
type: SpanType = SpanType.SPAN
type: Literal[SpanType.SPAN] = SpanType.SPAN


class TaskSpanAttributes(BaseModel):
type: SpanType = SpanType.TASK_SPAN
type: Literal[SpanType.TASK_SPAN] = SpanType.TASK_SPAN
input: SerializeAsAny[PydanticSerializable]
output: SerializeAsAny[PydanticSerializable]

Expand All @@ -91,7 +91,7 @@ class ExportedSpan(BaseModel):
parent_id: UUID | None
start_time: datetime
end_time: datetime
attributes: Union[SpanAttributes, TaskSpanAttributes]
attributes: Union[SpanAttributes, TaskSpanAttributes] = Field(discriminator="type")
events: Sequence[Event]
status: SpanStatus
# we ignore the links concept
Expand Down

0 comments on commit 4a82a2d

Please sign in to comment.