maple-agent-tracing-openrouter
Maple agent tracing: OpenRouter Broadcast
Goal: every conversation = one Maple Agent Session with each OpenRouter model call, its tokens, cost (gen_ai.usage.total_cost, OpenRouter's real charge) and prompt/completion. If the app already exports its own traces to Maple, the Broadcast spans nest inside them and each call is counted once.
Mechanism: OpenRouter Broadcast, configured in the OpenRouter dashboard, exports one OTLP/HTTP JSON trace per request (scope and service.name = openrouter, root span LLM Generation, children provider attempt N: <provider>). Maple reads session.id as the session key. OpenRouter sets session.id from the request's session_id body field or x-session-id header, and uses trace.trace_id / trace.parent_span_id from the body verbatim as the OTLP trace id / parent span id.
You cannot change the OpenRouter dashboard. Your job: (1) edit the app's OpenRouter calls, (2) hand the user the exact destination settings.
What Broadcast cannot give (tell the user, don't try to fix it here): tool spans, tool failures, agent names / sub-agent lanes. Those need the app's framework instrumentation (router skill maple-agent-tracing).
Step 0: Detect
- Find every OpenRouter call site:
openrouter.aibase URLs (https://openrouter.ai/api/v1,https://eu.openrouter.ai/api/v1),OPENROUTER_API_KEY,@openrouter/ai-sdk-provider,@openrouter/sdk, theopenrouterPyPI package,openaiclients with an OpenRouterbaseURL/base_url, LiteLLMopenrouter/models, framework model classes pointed at OpenRouter. - Find where the conversation id lives per request: chat thread id, conversation id, session id, agent run id. It must be per conversation, never a process constant or a per-client default.
- Existing OTel exporting to Maple? Search for
TracerProvider,NodeSDK,registerOTel,registerTelemetry,OTEL_EXPORTER_OTLP_ENDPOINT,ingest.maple.dev,logfire.configure, OpenInference / OpenLLMetry instrumentors.- Yes → do Step 2 and Step 3 (nesting).
- No → Step 2 only (Broadcast-only). Mention that the app's framework skill adds tool spans and agent structure.
- Which endpoint region the app calls (
openrouter.aivseu.openrouter.ai), for the destination's data regions.