Convert opencode transcripts to otel (or agent) traces
Rust 100.0%
32 1 0

Clone this repository

https://tangled.org/jauntywk.bsky.social/exp2span https://tangled.org/did:plc:zjbq26wybii5ojoypkso2mso/exp2span
git@knot.tangled.wizardry.systems:jauntywk.bsky.social/exp2span git@knot.tangled.wizardry.systems:did:plc:zjbq26wybii5ojoypkso2mso/exp2span

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

exp2span#

Converts opencode logs to OpenTelemetry traces using MCP semantic conventions.

Usage#

# Export a log file to OpenTelemetry traces
exp2span export <log-file>

# Validate a log file format
exp2span validate <log-file>

# Show log metadata and statistics
exp2span info <log-file>

# With verbose output
exp2span --verbose export <log-file>

# With dry-run mode (no actual export)
exp2span export --dry-run <log-file>

# Export to custom OTLP endpoint
exp2span export <log-file> --otlp-endpoint http://localhost:4318

# Export with gRPC protocol
exp2span export <log-file> --otlp-protocol grpc --otlp-endpoint http://localhost:4317

# Export with authentication headers
exp2span export <log-file> --otlp-header "Authorization=Bearer $TOKEN"

# Export to production collector
exp2span export <log-file> \
  --otlp-endpoint https://otel-collector.example.com:4318 \
  --otlp-protocol http \
  --otlp-service-name my-app \
  --otlp-header "Authorization=Bearer $TOKEN" \
  --batch-size 200 \
  --otlp-timeout-secs 60

MCP Semantic Conventions#

This project implements the OpenTelemetry semantic conventions for Model Context Protocol (MCP):

  • PR: #2083
  • Status: Merged (Jan 12, 2026)
  • Author: lmolkova
  • File: .test-agent/sem/docs/gen-ai/mcp.md

Key Attributes#

Client Spans#

  • mcp.session.id - Session identifier
  • mcp.method.name - Request/notification method (e.g., tools/call, initialize)
  • mcp.protocol.version - MCP version (e.g., 2025-06-18)
  • gen_ai.operation.name - Operation type (e.g., execute_tool)
  • gen_ai.tool.name - Tool name
  • jsonrpc.protocol.version - JSON-RPC version (default: 2.0)
  • network.transport - Transport protocol (tcp, quic, pipe)
  • network.protocol.name - OSI application layer (e.g., http, websocket)

Metrics#

  • mcp.client.operation.duration - Histogram of operation durations
  • mcp.server.operation.duration - Server-side operation duration

Well-Known MCP Methods#

Common methods from the specification:

  • tools/call - Execute a tool
  • tools/list - List available tools
  • initialize - Initialize MCP client
  • resources/list - List available resources
  • resources/read - Read a resource

Implementation#

The parser extracts:

  • Session ID from header metadata
  • Assistant/User messages with timestamps
  • Tool usage information (when available)
  • Thinking sections for context analysis

Each assistant message is converted to an OpenTelemetry span with appropriate MCP attributes.

OTLP Export#

The exporter supports real-time export to OpenTelemetry-compatible backends:

Protocols:

  • HTTP (default) - Exports to http://localhost:4318 or custom endpoint
  • gRPC - Exports to http://localhost:4317 or custom endpoint

Configuration:

  • --otlp-endpoint - OTLP collector URL
  • --otlp-protocol - http or grpc
  • --otlp-service-name - Service name for traces (default: exp2span)
  • --otlp-header - Custom headers (e.g., Authorization=Bearer $TOKEN)
  • --batch-size - Number of spans to batch (default: 100)
  • --otlp-timeout-secs - Request timeout (default: 30)
  • --otlp-max-retries - Maximum retry attempts (default: 3)
  • --otlp-retry-delay-ms - Initial retry delay (default: 100)

Supported Collectors:

  • Jaeger (http://localhost:4318 for HTTP, http://localhost:4317 for gRPC)
  • Tempo (any OTLP endpoint)
  • Zipkin (via OTLP)
  • Grafana Tempo (via OTLP)
  • Any OpenTelemetry-compatible collector

Dependencies#

  • opentelemetry - Core tracing API
  • opentelemetry_sdk - SDK implementation
  • opentelemetry-otlp - OTLP exporter with HTTP and gRPC support
  • jiff - Datetime parsing and handling with DST support
  • regex - Log parsing
  • serde_json - JSON parsing

References#