Course contents · Lesson 21 of 22

What Is OpenTelemetry? One Standard for All Signals

Putting It Together · Lesson 21 of 22 · 11 min Engineer

Imagine your team has spent two years adding a monitoring vendor's agent and library calls to twenty services. Then the price doubles, or you want to try an open-source backend, and you find that switching means editing code in every one of those services. That lock-in is the problem behind this lesson's question: what is OpenTelemetry, and why have so many teams standardised on it?

One standard instead of one plug per vendor

Telemetry is the data a program sends out about itself: the metrics, logs, traces and profiles from the four signals lesson. Before a common standard, each monitoring product shipped its own agent (a helper library or program that runs with your app) and its own data format. Your code called that vendor's functions, so the vendor was built into your code.

OpenTelemetry (OTel for short) is an open standard plus a set of free tools for creating, collecting and sending telemetry. It is a Cloud Native Computing Foundation (CNCF) project, formed in 2019 by merging two earlier projects, OpenTracing and OpenCensus. It covers traces, metrics and logs today. Profiles are being added as a fourth signal, but that work is newer, so check its status for your language before you depend on it.

Major open-source tools and most commercial vendors now accept OpenTelemetry data, so you instrument once and choose the backend separately. The diagram shows the difference: on the left every vendor has a hook inside your app, on the right the app knows only OpenTelemetry.

Left panel: an app containing five vendor agents, each wired to its own backend. Right panel: an app with one OpenTelemetry SDK sending OTLP to a Collector that fans out to the same five backends.
The backends stay the same; what changes is that only one standard library lives inside your code.

The five pieces: API, SDK, conventions, OTLP, Collector

OpenTelemetry is not one program but five pieces that fit together. Knowing which is which saves confusion when you read the docs.

  • API: the functions your code and libraries call, such as "start a span" or "add 1 to this counter". On its own the API does nothing (it is a no-op), so a library author can add OTel calls without forcing any setup on the people who use the library.
  • SDK: the implementation the app owner installs once, at startup. It decides which traces to keep (sampling), groups data into batches, and attaches the resource: attributes such as service.name that say which program the data came from.
  • Semantic conventions: agreed names for common attributes, such as http.request.method, http.route and http.response.status_code. A Java service and a Python service then describe a request the same way, so one dashboard query works for both. Older instrumentation used http.method; the stable name is http.request.method.
  • OTLP, the OpenTelemetry Protocol: the one wire format for all signals, sent over gRPC on port 4317 or over HTTP on port 4318 (for example POST /v1/traces).
  • The Collector: a separate program that receives telemetry, processes it and exports it to one or more backends.
Four stacked layers inside one application: your code and libraries, the API, the SDK and exporters, with semantic conventions shown beside them and the Collector as a separate process receiving OTLP.
Libraries touch only the API layer, so changing sampling or exporters at startup never means changing the code above it.

Notice where the line falls in the diagram. Everything above the SDK is written once and shared by everyone; everything from the SDK down is chosen by whoever runs the app. That split is what lets a database driver ship with OTel calls built in.

How data flows: SDK, OTLP, Collector, backend

In a typical setup, each service runs the SDK and sends OTLP to a Collector. The Collector is built from three kinds of parts. Receivers take data in. Processors change it: they batch it, drop or redact fields, add attributes such as the environment name, or apply the tail sampling rules from the sampling lesson. Exporters send it out in the format each backend expects.

Flowchart: a checkout service with the OTel SDK sends OTLP over gRPC port 4317 or HTTP port 4318 to the Collector, whose receivers, processors and exporters route metrics to Prometheus, traces to Jaeger and logs to Loki.
The app only knows one destination, the Collector, which is why swapping a backend never touches the service.

A Collector is configured with one YAML file. This minimal example receives OTLP on both ports and batches everything. It then sends traces to Jaeger, exposes metrics on port 8889 for Prometheus to scrape, and prints logs to the Collector's own output with the debug exporter:

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
processors:
  batch: {}
exporters:
  otlp_grpc/jaeger:
    endpoint: jaeger:4317
    tls:
      insecure: true
  prometheus:
    endpoint: 0.0.0.0:8889
  debug: {}
service:
  pipelines:
    traces:  {receivers: [otlp], processors: [batch], exporters: [otlp_grpc/jaeger]}
    metrics: {receivers: [otlp], processors: [batch], exporters: [prometheus]}
    logs:    {receivers: [otlp], processors: [batch], exporters: [debug]}

Read service.pipelines last: it wires the parts together, one pipeline per signal. otlp_grpc/jaeger is the otlp_grpc exporter (OTLP over gRPC; its old name otlp still works but logs a deprecation warning) with a name after the slash, which lets you run several exporters of one type. The endpoints say 0.0.0.0 because recent Collector versions listen only on localhost by default, which other containers cannot reach.

You can run the Collector as an agent next to each app or host, as a central gateway that many services send to, or both. Either way, moving traces to a different backend means editing this file and restarting the Collector.

Auto-instrumentation and your own spans

Instrumentation is the code that produces telemetry, and OpenTelemetry offers two kinds. Auto-instrumentation, also called zero-code instrumentation, hooks into popular libraries for you: the web framework, HTTP clients and database drivers. For a Python service it takes a few commands and no code changes:

pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
export OTEL_SERVICE_NAME=checkout
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
opentelemetry-instrument python app.py

opentelemetry-bootstrap checks which packages you have installed and adds the matching instrumentation, for Flask, requests and others. The OTEL_* environment variables are the same in every language: they name the service and point the exporter at the Collector. Each incoming request now creates a span, and outgoing calls carry the W3C traceparent header, the context propagation you met earlier.

Auto-instrumentation sees libraries, not your business logic. It can tell you a request took 900 ms, but not that most of that went into applying discount codes. For that, you add a manual span with the API:

from opentelemetry import trace

tracer = trace.get_tracer("checkout")

def apply_discounts(cart):
    with tracer.start_as_current_span("apply_discounts") as span:
        span.set_attribute("app.cart.items", len(cart.items))
        return pricing.apply(cart)

The new span becomes a child of the request span that auto-instrumentation already started, so it appears in the same trace waterfall. Keep span names fixed (apply_discounts, not one name per order) and put changing values in attributes, with a prefix of your own such as app. so they never clash with official names.

What OpenTelemetry is not

OpenTelemetry stops at the edge of your telemetry pipeline. It is not a backend: it keeps no long-term storage, has no query language, draws no dashboards and sends no alerts. You still need somewhere to put the data, such as Prometheus for metrics, Jaeger or Grafana Tempo for traces, Loki or Elasticsearch for logs, or a commercial service that accepts OTLP.

It also does not decide what is worth measuring. It gives every team a common way to describe a request, but choosing signals, labels and targets for your app is still your job. The capstone lesson that follows does exactly that for a small web shop.

Check yourself

A library calls the OpenTelemetry API, but the app using it never installed an SDK. What happens?

Nothing breaks and no telemetry is produced, because the API on its own is a no-op; that is why libraries can depend on it safely.

You want traces to go to a new backend while the old one keeps receiving them for a month. Where do you change that?

In the Collector config: add a second exporter to the traces pipeline, because the services only send OTLP to the Collector and need no redeploy.

Auto-instrumentation shows a 900 ms request span, but nothing explains where the time went. What do you add?

A manual span around the business step, such as apply_discounts, because auto-instrumentation only sees libraries, not your own logic.

Go deeper