Cookbook
OpenTelemetry Integration
Already using OpenTelemetry? Send your OTLP/JSON traces directly to 2Signal — no SDK changes needed. Your existing OTel instrumentation works as-is; just point the exporter at the 2Signal endpoint.
Endpoint
POST /api/v1/otel/tracesHeaders
Authorization: Bearer your-api-keyContent-Type: application/json
Step 1: Configure Your OTel Exporter
Python
Using opentelemetry-sdk with the OTLP HTTP exporter:
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
exporter = OTLPSpanExporter(
endpoint="https://your-instance.2signal.dev/api/v1/otel/traces",
headers={"Authorization": "Bearer your-api-key"},
)
provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(exporter))
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("my-agent")
with tracer.start_as_current_span("agent-run") as span:
span.set_attribute("ai.model", "gpt-4o")
span.set_attribute("ai.prompt_tokens", 150)
span.set_attribute("ai.completion_tokens", 200)
# your agent logic hereNode.js
Using @opentelemetry/exporter-trace-otlp-http:
const { OTLPTraceExporter } = require("@opentelemetry/exporter-trace-otlp-http");
const exporter = new OTLPTraceExporter({
url: "https://your-instance.2signal.dev/api/v1/otel/traces",
headers: { Authorization: "Bearer your-api-key" },
});Step 2: Attribute Mapping
2Signal automatically converts standard OpenTelemetry attributes into native fields. The table below shows how key attributes are mapped.
| OTel Attribute | 2Signal Field | Description |
|---|---|---|
span.name | span name | Span display name |
span.kind | span type | Maps SERVER→AGENT, CLIENT→TOOL, INTERNAL→CHAIN |
ai.model | model | LLM model name |
ai.prompt_tokens | usage.promptTokens | Input token count |
ai.completion_tokens | usage.completionTokens | Output token count |
span.status | status | OK or ERROR |
Step 3: Verify Traces
After sending, open the Traces page in the 2Signal dashboard. OTel traces appear alongside SDK traces and go through the same evaluation pipeline — any evaluators enabled on your project will automatically score the incoming traces.
When to Use OTel vs the 2Signal SDK
- Use the 2Signal SDK for new projects — it provides richer auto-instrumentation of LLM calls, capturing prompts, completions, token usage, and cost out of the box.
- Use OTel if you already have OTel instrumentation — add 2Signal to your stack without any code changes.
- You can mix both — use OTel for general observability and the 2Signal SDK for detailed LLM tracing. Both feed into the same project and evaluation pipeline.
See the full OTel Traces API reference for request/response schemas and error codes.