Skip to content
tezvyn:
Menu

OpenTelemetry API: The Stable Interface for Your Code

Source: opentelemetry.ioEasyHow cards are made

The OpenTelemetry API provides stable interfaces for your code to generate telemetry. This lets you instrument your application once, while the SDK implementation handles the actual data processing and export, which can be swapped out later.

Why it exists

To decouple instrumentation from implementation. Before OpenTelemetry, if you instrumented your code for one monitoring vendor and wanted to switch to another, you had to rewrite all your instrumentation code. A stable, vendor-neutral API was needed to solve this vendor lock-in and make instrumentation portable.

The mental model

The OpenTelemetry API is like a universal electrical outlet standard. Your application (the appliance) is built to plug into this standard. The API defines the shape of the plug and the voltage, but provides no power itself. The OpenTelemetry SDK is the power plant and wiring behind the wall. You can change your electricity provider (the SDK and its configuration) without re-wiring your appliance (your application code).

How it works

The API package in any language (e.g., opentelemetry-api in Java or Python) contains interfaces like Tracer and Meter. Your code calls methods on these interfaces to create spans or record metrics. By default, if no SDK is configured, these calls do nothing; they are "no-op". In your final application, you include and configure an SDK package (e.g., opentelemetry-sdk). The SDK provides the concrete implementations that process this data and send it to a configured backend like Jaeger, Prometheus, or a vendor platform.

When to use it

Always depend ONLY on the API package when writing code within a shared library. This allows consumers of your library to use it with any OpenTelemetry-compatible backend they choose. Application code also uses the API to generate telemetry signals.

When not to use it

You don't use the API alone if you actually want to export data. An executable service that needs to emit telemetry must also include and configure an SDK. The rule is: libraries depend on the API; executables depend on the API and configure an SDK.

One canonical example

A Python library author adds a dependency on opentelemetry-api. They add tracing to a function with tracer = trace.get_tracer(name) and with tracer.start_as_current_span("process_data"). They publish the library. An application developer then uses this library. In their main application, they add dependencies on opentelemetry-sdk and an exporter. Now, the library's tracing calls are activated and seamlessly integrated into the application's traces.

Interview question

What happens if an application uses the OpenTelemetry API but does not configure an SDK?

  • a.The application will buffer telemetry data until an SDK is initialized.
  • b.A basic, default OpenTelemetry SDK will automatically activate to provide minimal tracing.
  • c.The application will encounter runtime errors due to unfulfilled interface implementations.
  • d.The API calls will execute as "no-op" operations, effectively generating no telemetry.Correct
Why?

The card explicitly states that "By default, if no SDK is configured, these calls do nothing; they are 'no-op'". This means no telemetry data is generated or buffered, and a default SDK is not automatically activated.

Just read this? Test yourself on what you have been reading.

Read the original → opentelemetry.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on opentelemetry — each one lists the topics its interview covers.

See open roles