Agent Wranglers

STK-62Default Open source

Use OpenTelemetry to instrument your code

Add traces, metrics and log context to your code with the OpenTelemetry API and SDK, and send them over OTLP to any backend.

Review by

2027-04-20

How to do it

OpenTelemetry is the vendor-neutral standard of the Cloud Native Computing Foundation, under the Apache-2.0 licence. Its Python SDK reached 1.0 in March 2021 and its JavaScript API in June 2021. Python 1.45.1 came out on 6 October 2026. The npm package @opentelemetry/api had about 55 million downloads in the week to 18 October 2026. opentelemetry-api on PyPI had about 145 million in the week to 21 October. The JavaScript core packages, such as @opentelemetry/core, reached 3.0 on 20 October 2026. Stay on 2.x for six months, as Pick what AI tools already know says. Every major backend reads OTLP, so you can change backends without touching code. What to trace is in Trace requests across services. Choose something else when one small service only needs metrics, and a Prometheus client library is simpler.

Examples

JavaScript example

import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

const sdk = new NodeSDK({
  serviceName: 'orders-api',
  traceExporter: new OTLPTraceExporter({ url: 'https://otel.example.com/v1/traces' }),
});
sdk.start();

Python example

from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

provider = TracerProvider(resource=Resource.create({"service.name": "orders-api"}))
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(endpoint="https://otel.example.com/v1/traces")))
trace.set_tracer_provider(provider)

How to check

Every service starts the OpenTelemetry SDK at boot and exports over OTLP. A test request shows one trace with spans from at least 2 services in the backend.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/operations-tools/opentelemetry">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.