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 identifiermcp.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 namejsonrpc.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 durationsmcp.server.operation.duration- Server-side operation duration
Well-Known MCP Methods#
Common methods from the specification:
tools/call- Execute a tooltools/list- List available toolsinitialize- Initialize MCP clientresources/list- List available resourcesresources/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:4318or custom endpoint - gRPC - Exports to
http://localhost:4317or custom endpoint
Configuration:
--otlp-endpoint- OTLP collector URL--otlp-protocol-httporgrpc--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:4318for HTTP,http://localhost:4317for gRPC) - Tempo (any OTLP endpoint)
- Zipkin (via OTLP)
- Grafana Tempo (via OTLP)
- Any OpenTelemetry-compatible collector
Dependencies#
opentelemetry- Core tracing APIopentelemetry_sdk- SDK implementationopentelemetry-otlp- OTLP exporter with HTTP and gRPC supportjiff- Datetime parsing and handling with DST supportregex- Log parsingserde_json- JSON parsing
References#
- MCP Semantic Conventions (PR #2083) - Official OpenTelemetry semantic conventions for Model Context Protocol