From 9b36d7ab2dda1e23a93cf5354e8d44fb0e718402 Mon Sep 17 00:00:00 2001 From: Teo Date: Fri, 13 Dec 2024 16:24:14 -0600 Subject: [PATCH] docs: add entity mapping example for OpenTelemetry concepts --- docs/dev/OTEL/entity_mapping.md | 74 +++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 docs/dev/OTEL/entity_mapping.md diff --git a/docs/dev/OTEL/entity_mapping.md b/docs/dev/OTEL/entity_mapping.md new file mode 100644 index 00000000..abc7ca13 --- /dev/null +++ b/docs/dev/OTEL/entity_mapping.md @@ -0,0 +1,74 @@ +An example of how AgentOps components could map to OpenTelemetry concepts: + +1. **Core Mapping** +```mermaid +graph LR + subgraph AgentOps + A[Session] --> B[Events] + B --> C[LLMEvent] + B --> D[ActionEvent] + B --> E[ToolEvent] + end + + subgraph OpenTelemetry + F[Trace] --> G[Spans] + G --> H[LLM Spans] + G --> I[Action Spans] + G --> J[Tool Spans] + K[Metrics] --> L[LLM Metrics] + end + + A -.->|Maps to| F + C -.->|Maps to| H + D -.->|Maps to| I + E -.->|Maps to| J +``` + +Let's look at specific examples: + +1. **Session to Trace** +````python +# When AgentOps starts a session: +class Session: + def __init__(self): + # Create root span for the session + self.trace = tracer.start_span( + name="agentops.session", + attributes={ + "session.id": self.session_id, + "agent.id": self.agent_id + } + ) +```` + +2. **LLMEvent to Span** +````python +# When AgentOps records an LLM event: +class LLMEvent: + def to_span(self): + return tracer.start_span( + name="llm.completion", + attributes={ + "llm.model": self.model, + "llm.tokens.prompt": self.prompt_tokens, + "llm.tokens.completion": self.completion_tokens, + "llm.cost": self.cost + } + ) +```` + +3. **LLM Metrics** +````python +# In LlmTracker: +class LlmTracker: + def __init__(self): + self.calls_counter = meter.create_counter( + name="llm.calls", + description="Number of LLM API calls" + ) + + self.token_histogram = meter.create_histogram( + name="llm.tokens", + description="Distribution of token usage" + ) +````