AlgoViz

OpenTelemetry

medium 30 min

OpenTelemetry is an open standard, with libraries and a Collector, for making and moving traces, metrics and logs.

Video lesson · Chapter 1 of 5

One lost order crosses two services

0:00 / 3:54

OpenTelemetry in 90 seconds

1:30Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

OpenTelemetry, or OTel, is a set of agreements and programs for telemetry: the traces, metrics and logs that a system produces about itself. It has a specification, libraries for many languages, a protocol called OTLP, agreed names for data, and a program called the Collector.

It does not store data or draw charts. That is left to backends such as Jaeger, Prometheus, the ELK Stack or a vendor.

It is a project of the Cloud Native Computing Foundation, under the Apache 2.0 licence.

Why it exists

Before, each monitoring product had its own library. Changing the product meant changing the code of every service. Library authors had to choose one product or none.

OpenTelemetry puts a common plug between. Code and frameworks speak one language, the Collector speaks it too, and the choice of backend becomes a few lines of configuration. The project puts it this way: you own the data you generate, and you learn one set of APIs.

A short history

  1. May 2019

    Two projects, OpenTracing and OpenCensus, agree to merge. The CNCF accepts OpenTelemetry on 7 May.

  2. August 2021

    The project moves to the incubating level.

  3. November 2021

    The W3C Trace Context recommendation, which defines traceparent, appears in its current edition.

  4. 2023

    The names for HTTP data are declared stable.

  5. 2026

    The specification deprecates OpenTracing compatibility in March. CNCF lists 11 May as the graduation date, and the announcement follows on 21 May. The profiles signal enters public alpha.

Words to know

Signal
One kind of telemetry: traces, metrics, logs, baggage, and profiles in development.
API
The functions that code calls. Without an SDK they do nothing.
SDK
The implementation that samples, batches and exports. The application chooses it.
Instrumentation library
A package that makes spans and metrics for a framework, such as an HTTP client.
OTLP
The OpenTelemetry protocol: gRPC on port 4317, HTTP on port 4318.
Resource
Who produced the data: service.name, version, host.
Semantic conventions
Agreed names, such as http.request.method.
Collector
A program that receives, processes and exports telemetry.
Baggage
Key and value pairs that travel with a request to other services.

How it works

Step through the idea, or press Play.

Step 1 of 3

Instrument. API calls in code and libraries

Understand it

Start here

One plug for the brass band

A brass band wants to be recorded. Every instrument has its own kind of plug, and the recorder has one socket. Imagine buying new instruments for each new recorder.

Any instrument, any recorder
RECORDER AThree plugs, one socket

The plug is the standard. The box is the Collector. The recorders are yours to choose.

The whole

Parts and borders

One protocol in, any backend out

Inside our system, a Python shop service and a Java stock service, each with API, SDK and libraries, send OTLP to one OpenTelemetry Collector. The Collector sends traces, metrics and logs to three separate backends outside.
The services do not know the backends, and hold none of their credentials.
  • Traces

    The path of a request, as spans. Stable.

  • Metrics

    Counters, gauges and histograms, summed up in the process. Stable API and protocol.

  • Logs

    Existing log libraries are bridged and get trace ids. Stable in the specification.

  • Baggage

    Values that travel with the request. Not telemetry by itself.

  • Profiles

    Which code uses the CPU. Public alpha in 2026.

  • Conventions

    The same names everywhere, so one dashboard fits all services.

Status differs by language (November 2026)

LanguageTracesMetricsLogs
Java, .NET, C++, PHPStableStableStable
GoStableStableRelease candidate
Python, JavaScriptStableStableDevelopment
Ruby, Swift, ErlangStableDevelopmentDevelopment
RustBetaStableStable
From the project's status page. A stable specification does not mean a stable library, so check your language.

In the code

API and SDK are separate on purpose

A library should be able to make spans without forcing a product on its users. So it depends on the small API only. If the application installs no SDK, the calls do almost nothing. If it does, the SDK decides about sampling, batches and export.

Who depends on what

Only the start of the application knows the SDK. The API keeps its promise for at least three years after a new major version.

Ways to instrument

WayEffortYou get
Zero-code agent or wrapperChange the start commandHTTP, database and messaging spans of known libraries
eBPF instrumentationRun a program on the hostHTTP and gRPC spans without touching the process
Instrumentation librariesA few lines at startThe same, chosen by you
Manual spans and metricsCode in business functionsWhat only you know: order value, cache hit, plan
Start with the first, add manual spans where questions stay open.
Shell
pip install opentelemetry-distro opentelemetry-exporter-otlpopentelemetry-bootstrap -a installexport OTEL_SERVICE_NAME=checkoutexport OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufexport OTEL_TRACES_SAMPLER=parentbased_traceidratioexport OTEL_TRACES_SAMPLER_ARG=0.1opentelemetry-instrument python app.py
Zero-code instrumentation in Python. Other languages use the same variable names, with more or less support.

Context

How a trace crosses a border

Inject and extract

traceparent: 00-0af7…319c-b7ad…3331-01

PartLengthMeaning
Version2 hex digits00 today, ff is forbidden
Trace id32 hex digits16 bytes, not all zero
Parent id16 hex digitsThe calling span, 8 bytes, not all zero
Flags2 hex digits01 means sampled
The default propagators are tracecontext and baggage. For queues, the same values go into message headers.

Metrics

Aggregated in the process, limited by attributes

A counter in OpenTelemetry does not send each increment. The SDK adds them up for each combination of attributes and exports the sums, every 60 seconds by default. Cumulative sums count from the start of the process, delta sums since the last export. Prometheus wants cumulative.

How many series does one metric make?

20 routes×4 methods×5 status codes=400× 10,000 users=4,000,00020\ \text{routes} \times 4\ \text{methods} \times 5\ \text{status codes} = 400 \qquad \times\, 10{,}000\ \text{users} = 4{,}000{,}000
The SDK's default limit is 2,000 combinations per metric. What goes beyond is added to one series marked otel.metric.overflow.

So a user id belongs on a span, not on a metric. Exemplars build the bridge: a histogram can carry a few trace ids as examples. By default these come from sampled traces.

OTLP

The protocol

OTLP over gRPCOTLP over HTTP
Port43174318
AddressOne service/v1/traces, /v1/metrics, /v1/logs
EncodingProtobufProtobuf or JSON
Good forInside the clusterProxies, browsers, the default of SDK exporters
The exporter's default time limit is 10 seconds.

The receiver can say: all accepted, partly accepted, or try later. Errors such as UNAVAILABLE are retried with growing pauses. If an answer is lost, the client sends again, so a backend may get duplicates. The specification calls that the right trade-off for telemetry.

Collector

Receivers, processors, exporters

YAML
receivers:  otlp:    protocols:      grpc: { endpoint: localhost:4317 }      http: { endpoint: localhost:4318 }processors:  memory_limiter:    check_interval: 1s    limit_percentage: 80    spike_limit_percentage: 20  attributes/mask:    actions:      - { key: http.request.header.authorization, action: delete }      - { key: user.email, action: hash }  batch:    send_batch_size: 8192    timeout: 200msexporters:  otlp_grpc/traces:    endpoint: jaeger:4317    tls: { ca_file: /etc/otel/ca.crt }  otlp_http/vendor:    endpoint: https://otlp.vendor.example    headers: { api-key: "${env:VENDOR_KEY}" }service:  pipelines:    traces:      receivers: [otlp]      processors: [memory_limiter, attributes/mask, batch]      exporters: [otlp_grpc/traces, otlp_http/vendor]
Order matters: the memory limiter first. Older files write otlp and otlphttp for the exporters. A part that is not named in a pipeline is not used.

Agent and gateway

Two hosts, each with apps and an agent collector. Both agents send OTLP to one gateway collector, which sends OTLP with TLS to backends outside our system.
The agent is close and adds host data. The gateway holds credentials and rules.

Where to run a Collector

PatternGoodCost
None: SDK to backendSimple, fine for a trialCredentials and retries in every service
Agent on each hostQuick handover, host metadata, log filesConfiguration on every host
Gateway, several copiesOne place for rules and keysA service to scale and to keep up
Agent and gatewayBothTwo layers to watch

The project ships several builds: core, contrib with very many components, k8s, otlp and one for profiling. For production, build your own with the builder tool (ocb) and include only what you use.

Sampling

Keeping less, but the right things

The SDK default is parentbased_always_on: keep everything, and follow the caller. With parentbased_traceidratio the first service decides from the trace id, and the others follow the flag. The documentation suggests thinking about sampling from about 1,000 traces a second.

Tail sampling needs two layers

Services send all spans to a layer 1 Collector that routes by trace id. Trace 1 goes to layer 2 A and trace 2 to layer 2 B. Each decides and sends the kept traces to trace storage.
All spans of a trace must reach the same second-layer Collector. The first layer uses the load_balancing exporter with the trace id.

Is the default memory enough?

5000 tracess×30 s=150,000 open traces>50,000150,000×8×500 B=600 MB5000\ \tfrac{\text{traces}}{\text{s}} \times 30\ \text{s} = 150{,}000\ \text{open traces} > 50{,}000 \qquad 150{,}000 \times 8 \times 500\ \text{B} = 600\ \text{MB}
The tail sampling processor waits 30 seconds and holds 50,000 traces by default; beyond that the oldest are pushed out. Assumed: 8 spans of 500 bytes, data only.

Sample well

  • Let the first service decide, and pass the flag on
  • Make metrics from spans before sampling
  • Keep all errors and slow traces with tail sampling
  • Different shares for loud and quiet services

Sample badly

  • Each service rolls its own dice
  • Two Collectors behind a plain balancer decide on halves of a trace
  • Rates computed from kept traces
  • 1 percent everywhere, also for ten requests a day

Limits

Every queue ends somewhere

Where data can be dropped

PlaceDefaultWhen it is full
SDK span queue2,048 spans, batches of 512, at least every 5 sNew spans are dropped
Span attributes, events128 eachMore are ignored
Collector memory limiterYou set itData is refused, the sender retries
Collector sending queue1,000 requests, 10 sendersNew data is rejected
Collector retriesFrom 5 s up to 30 s, for 300 s in allThe batch is dropped

The fastest one SDK can export

512 spans0.2 s per export=2560 spanss\frac{512\ \text{spans}}{0.2\ \text{s per export}} = 2560\ \tfrac{\text{spans}}{\text{s}}
One batch at a time, with an assumed 200 ms for each. A nearby agent that answers in 5 ms allows about 102,400.

The backend is down

The memory queue is lost with the process. A file queue survives a restart. Kafka survives the loss of a machine.

Operate

Running the Collector

  1. 1

    Watch it

    It reports its own metrics: accepted, refused, sent, failed, queue size and capacity. Scale up when a queue stays at 60 to 70 percent.

  2. 2

    Know what scales

    OTLP receivers are stateless and go behind a balancer. Tail sampling needs routing by trace id. Prometheus scraping needs targets shared out.

  3. 3

    Do not scale against a slow backend

    More Collectors press harder on the part that is already too slow.

  4. 4

    Listen narrowly

    Since 0.110 the default address is localhost. If others must reach it, use a specific address, TLS and authentication.

  5. 5

    Pin versions

    The Collector releases often, and its components have different levels of stability. Read the changelog before an upgrade.

  6. 6

    Mask early

    OpenTelemetry cannot know what is personal in your data. Collect less, delete or hash attributes before they leave.

Move

Changing a running system

Move without a gap

Collectors accept other formats too: Zipkin, Jaeger's older ones, Prometheus scraping, log files. So services can move one at a time. The OpenTracing bridge is deprecated since March 2026, so plan to replace such code.

Choose

When it fits and when not

SituationChoiceWhy
Several languages, several backendsOpenTelemetryOne way for all
You publish a libraryThe OpenTelemetry API onlyUsers choose the SDK
Only Prometheus metrics in Go servicesThe Prometheus client is fineSimple, and the Collector can scrape it later
A vendor feature that needs its own agentThe vendor's agent for that partNot everything is in the standard
A small scriptLogsA pipeline would be larger than the script
You need a database and dashboardsA backendOpenTelemetry has none

Summary

The whole topic in one minute.

Libraries call the API, the application installs the SDK, and the SDK sends OTLP. Context travels in headers so that spans of different services form one trace.

The Collector stands between services and backends: receive, protect memory, filter, sample, batch, export. That is where you change vendors, remove secrets and keep credentials.

Everything has a queue with a limit. Telemetry is dropped before it hurts the application, so measure the drops, and watch the number of attribute combinations.

  • OpenTelemetry makes and moves telemetry. It stores nothing.
  • API in libraries, SDK in the application, OTLP on the wire, Collector in between.
  • Context travels in traceparent. Baggage travels too, and is not secret.
  • Metrics: keep attribute combinations few. 2,000 is the default limit.
  • Tail sampling needs all spans of a trace in one Collector, and memory.
  • Every queue has a limit: measure what is dropped.
  • The Collector is the place for keys, masks and the change of backend.

Sources