* feat: add provider trace backend abstraction for multi-backend telemetry Introduces a pluggable backend system for provider traces: - Base class with async/sync create and read interfaces - PostgreSQL backend (existing behavior) - ClickHouse backend (via OTEL instrumentation) - Socket backend (writes to Unix socket for crouton sidecar) - Factory for instantiating backends from config Refactors TelemetryManager to use backends with support for: - Multi-backend writes (concurrent via asyncio.gather) - Primary backend for reads (first in config list) - Graceful error handling per backend Config: LETTA_TELEMETRY_PROVIDER_TRACE_BACKEND (comma-separated) Example: "postgres,socket" for dual-write to Postgres and crouton 🐙 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com> * feat: add protocol version to socket backend records Adds PROTOCOL_VERSION constant to socket backend: - Included in every telemetry record sent to crouton - Must match ProtocolVersion in apps/crouton/main.go - Enables crouton to detect and reject incompatible messages 🐙 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com> * fix: remove organization_id from ProviderTraceCreate calls The organization_id is now handled via the actor parameter in the telemetry manager, not through ProviderTraceCreate schema. This fixes validation errors after changing ProviderTraceCreate to inherit from BaseProviderTrace which forbids extra fields. 🐙 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com> * consolidate provider trace * add clickhouse-connect to fix bug on main lmao * auto generated sdk changes, and deployment details, and clikchouse prefix bug and added fields to runs trace return api * auto generated sdk changes, and deployment details, and clikchouse prefix bug and added fields to runs trace return api * consolidate provider trace * consolidate provider trace bug fix --------- Co-authored-by: Letta <noreply@letta.com>
46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Any, Dict, Optional
|
|
|
|
from pydantic import Field
|
|
|
|
from letta.helpers.datetime_helpers import get_utc_time
|
|
from letta.schemas.enums import PrimitiveType
|
|
from letta.schemas.letta_base import OrmMetadataBase
|
|
|
|
|
|
class BaseProviderTrace(OrmMetadataBase):
|
|
__id_prefix__ = PrimitiveType.PROVIDER_TRACE.value
|
|
|
|
|
|
class ProviderTrace(BaseProviderTrace):
|
|
"""
|
|
Letta's internal representation of a provider trace.
|
|
|
|
Attributes:
|
|
id (str): The unique identifier of the provider trace.
|
|
request_json (Dict[str, Any]): JSON content of the provider request.
|
|
response_json (Dict[str, Any]): JSON content of the provider response.
|
|
step_id (str): ID of the step that this trace is associated with.
|
|
agent_id (str): ID of the agent that generated this trace.
|
|
agent_tags (list[str]): Tags associated with the agent for filtering.
|
|
call_type (str): Type of call (agent_step, summarization, etc.).
|
|
run_id (str): ID of the run this trace is associated with.
|
|
organization_id (str): The unique identifier of the organization.
|
|
created_at (datetime): The timestamp when the object was created.
|
|
"""
|
|
|
|
id: str = BaseProviderTrace.generate_id_field()
|
|
request_json: Dict[str, Any] = Field(..., description="JSON content of the provider request")
|
|
response_json: Dict[str, Any] = Field(..., description="JSON content of the provider response")
|
|
step_id: Optional[str] = Field(None, description="ID of the step that this trace is associated with")
|
|
|
|
# Telemetry context fields
|
|
agent_id: Optional[str] = Field(None, description="ID of the agent that generated this trace")
|
|
agent_tags: Optional[list[str]] = Field(None, description="Tags associated with the agent for filtering")
|
|
call_type: Optional[str] = Field(None, description="Type of call (agent_step, summarization, etc.)")
|
|
run_id: Optional[str] = Field(None, description="ID of the run this trace is associated with")
|
|
|
|
created_at: datetime = Field(default_factory=get_utc_time, description="The timestamp when the object was created.")
|