> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenTelemetry API

> Overview of the OpenTelemetry API, a language agnostic contract for generating traces metrics and logs, contrasts with SDK, and offers instrumentation best practices and examples

Hello, OTel architecture experts.

In this lesson/article we'll take a focused look at the OpenTelemetry API: what it is, how it differs from the SDK, and best practices for instrumenting applications and libraries. This article preserves the original diagrams and their order so you can follow the architecture visually as you read.

Why a language-agnostic telemetry API?

Modern systems are polyglot: Java, Go, Python, PHP, Ruby, Swift, JavaScript and more all produce telemetry. Language-specific approaches (for example, print statements or ad-hoc logging) are not portable across ecosystems. OpenTelemetry provides a vendor-neutral, cross-language standard API so you can generate traces, metrics, and logs without coupling instrumentation to a particular backend or SDK.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-cross-language-bridge-diagram.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=54a1e54556267dc8166bd8d4d0f6870f" alt="The image illustrates how OpenTelemetry acts as a cross-language bridge, supporting multiple programming languages like C++, Python, and JavaScript, and connecting them to a standard telemetry API." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-cross-language-bridge-diagram.jpg" />
</Frame>

What is the OpenTelemetry API?

The OpenTelemetry API is the language-agnostic specification for generating telemetry data—traces, metrics, and logs. It defines the interfaces and data types (the contract) that application code and libraries call. Each supported language exposes an idiomatic API that implements that contract.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-vendor-neutral-tool.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=6cb2b6ad330920c882e6e0ec16b328c9" alt="The image explains the OpenTelemetry API as a vendor-neutral tool for handling traces, metrics, and logs, with standardized specifications for language-specific APIs." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-vendor-neutral-tool.jpg" />
</Frame>

Specification vs implementation

The OpenTelemetry specification describes the data model and operations for telemetry and can evolve to include additional signals (such as profiling). Language-specific APIs and SDKs implement the spec; find the current status and releases in the project documentation.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-status-releases-documentation.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=7599d6071cd763a7e3a9d0320b20b0d5" alt="The image shows a section of the OpenTelemetry documentation focusing on &#x22;Status and Releases&#x22; with a table listing various programming languages and their component statuses. The sidebar features a menu with links to related documentation sections." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-status-releases-documentation.jpg" />
</Frame>

Quick Python example (install + basic tracer provider)

To try OpenTelemetry in Python, install the API and SDK packages, configure a tracer provider, and add a span processor/exporter:

```bash theme={null}
pip install opentelemetry-api
pip install opentelemetry-sdk
```

```python theme={null}
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
    BatchSpanProcessor,
    ConsoleSpanExporter,
)

provider = TracerProvider()
processor = BatchSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(processor)

# Set global tracer provider (application-level configuration)
trace.set_tracer_provider(provider)

# Create a tracer from the global tracer provider
tracer = trace.get_tracer("my.tracer.name")
```

The above shows how the API is used by application code. The SDK is the component that provides batching, sampling, and exporting behavior you configure at deployment time.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-standardized-interfaces.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=3c36f92142b0561cd84b37a63b726a3c" alt="The image describes the OpenTelemetry API, highlighting its role in defining standardized interfaces for creating and managing traces, metrics, logs, and propagating context across service boundaries. It enables telemetry generation without relying on a specific backend or SDK implementation." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-standardized-interfaces.jpg" />
</Frame>

Key characteristics of the OpenTelemetry API

Your application and third-party libraries call the OpenTelemetry API to record telemetry without needing knowledge of how it will be processed or where it will be sent. The API provides:

* Standardized contracts (tracer, meter, logger interfaces).
* A minimal no-op (NOP) implementation so instrumentation is safe even if no SDK is installed.
* The ability to plug in a full SDK later for sampling, processing, and exporting—without changing instrumented code.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/api-key-characteristics-dependency-telemetry.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=c2bcbbad0b48af88d8539db4d2c4c7a6" alt="The image outlines three API key characteristics: self-sufficient dependency, no telemetry output by default, and minimal default implementation, with brief descriptions of each." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/api-key-characteristics-dependency-telemetry.jpg" />
</Frame>

Runtime behavior when no SDK is present

If only the API artifacts are available, calls like `trace.get_tracer()` or `meter.get_meter()` succeed and return functional objects. Spans and metrics created in this state are no-op (silently discarded). This design makes library and framework instrumentation safe: instrumentation remains present but harmless if the application never configures an SDK.

API vs SDK — responsibilities comparison

* API: defines the "what" — interfaces for creating and managing spans, metrics, logs, and context propagation.
* SDK: defines the "how" — sampling, batching, exporting, and advanced processing.

Common SDK responsibilities:

* Sampling policies to limit telemetry volume.
* Batching spans and metrics for efficient export.
* Exporters that send telemetry to collectors or observability backends.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-sdk-roles-explained.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=460424277844dc55c54ff41428d0299c" alt="The image explains the roles of OpenTelemetry API and SDK, highlighting the API's focus on defining the creation and management of spans, metrics, and logs, and the SDK's role in managing context propagation, sampling, batching, and exporting data to backends." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-sdk-roles-explained.jpg" />
</Frame>

Binding contract and portability

The API + SDK form a binding contract between application code and the telemetry implementation. As long as SDK implementations follow the API contract, instrumented code remains unchanged when switching SDKs or backends. This enables consistent instrumentation across languages and flexible backend choices.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/api-sdk-separation-benefits-diagram.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=9fa042af98dcb9c37f24c1d8bd0b9fd7" alt="The image illustrates the benefits of separating APIs and SDKs, showing app code interfacing with an API layer that includes language-specific APIs (Java, Python, Node.js, Go) and a language-agnostic core specification. It highlights consistent instrumentation across languages and the ability to swap or update SDKs without changing code." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/api-sdk-separation-benefits-diagram.jpg" />
</Frame>

Practical benefits

* Instrumentation patterns remain similar across languages while staying idiomatic.
* Exporters or SDK implementations can be swapped without touching instrumentation code.
* Application owners choose SDK configuration (exporters, samplers, processors) at deployment time.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-benefits-code-instrumentation.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=93a2c075ced08c26d28f5118658523a5" alt="The image illustrates the OpenTelemetry API benefits, highlighting consistent code instrumentation across different environments and the ability to update SDKs without changing instrumentation logic." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-benefits-code-instrumentation.jpg" />
</Frame>

Guidelines for library authors

Most apps rely on third-party libraries (DB clients, HTTP clients, messaging libraries). Library authors should instrument using only the OpenTelemetry API (not the SDK) so applications remain free to choose the SDK and configuration.

Do:

* Depend only on the OpenTelemetry API.
* Obtain tracer/meter from the global provider (safe when SDK is absent).
* Propagate and respect context across call paths.
* Use official semantic conventions for spans and attributes: [https://opentelemetry.io/docs/reference/specification/semantic\_conventions/](https://opentelemetry.io/docs/reference/specification/semantic_conventions/)

Don't:

* Leak SDK classes or types in public library signatures.
* Configure exporters, samplers, or processors inside library code.

<Callout icon="lightbulb" color="#1CB2FE">
  Library authors: prefer API-only instrumentation. This ensures your instrumented library works regardless of which SDK or exporter the application selects.
</Callout>

<Callout icon="warning" color="#FF6B6B">
  Do not configure SDK components (exporters, processors, samplers) inside libraries. SDK setup belongs to the application or deployment environment.
</Callout>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-guidelines-do-avoid.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=1462866a5bfdc6ef2af1d4a5791b79b2" alt="The image provides guidelines for using the OpenTelemetry API, recommending library authors to use the API for its advantages and application developers to choose the SDK while listing &#x22;do&#x22; and &#x22;avoid&#x22; practices." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-guidelines-do-avoid.jpg" />
</Frame>

Instrumenting libraries — a small Python example

Instrument libraries with API-only calls so the host application decides the SDK:

```python theme={null}
from opentelemetry import trace

tracer = trace.get_tracer(__name__)  # API-only

def handler(req):
    # Start a span (API usage only)
    with tracer.start_as_current_span("lib.operation") as span:
        span.set_attribute("http.route", "/items/{id}")
        # perform library work...
```

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-instrumentation-guide.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=7dbf25b6bf1b24ce7bababd3622b76be" alt="The image is a guide on using the OpenTelemetry API for instrumenting libraries, suggesting that library authors use the API to maintain self-sufficiency and portability, while applications should choose the SDK for components like exporters and processors. It includes a &#x22;Do&#x22; list for using OpenTelemetry effectively." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-instrumentation-guide.jpg" />
</Frame>

Language-neutral specification and idiomatic APIs

The specification is language-neutral and does not mandate exact method names. Each language provides idiomatic APIs:

* Python: `start_as_current_span()`
* Java: `SpanBuilder().startSpan()`
* JavaScript: `tracer.startSpan()`
* Go: language-idiomatic start functions

The core principle: use the OpenTelemetry API for spans, metrics, and context propagation; method names are idiomatic per language.

Roles and responsibilities

OpenTelemetry encourages clear role separation so the system remains modular:

* Instrumentation authors: use the API to generate telemetry (spans, metrics, logs). API stability minimizes churn for authors.
* Application owners: configure the SDK at deployment time—choose sampling, exporters, and processing strategies.
* Plugin/SDK authors: implement exporters, processors, and samplers to connect telemetry to backends or to transform/filter data.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-sdk-roles-flowchart.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=bbe85ef1f18f74395b0f148fae8f0738" alt="The image is a flowchart showing how different roles interact with the OpenTelemetry SDK, including Instrumentation Authors using API, Application Owners for setup, and Plugin Authors with plugin interfaces." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-sdk-roles-flowchart.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-roles-interaction-diagram.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=6fca35bc2ce909018f618398a38cdb64" alt="The image illustrates how different roles, such as instrumentation authors, application owners, and plugin authors, interact with the OpenTelemetry SDK through various components like API, setup, and plugin interfaces. It highlights interactions involving traces, metrics, configurations, exporters, and processors." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-roles-interaction-diagram.jpg" />
</Frame>

Together these roles let developers add telemetry, operators decide how to handle it, and plugin authors extend the platform to integrate with backends.

Knowledge check

Use these quick questions to verify your understanding.

1. What is the primary purpose of the OpenTelemetry API?

* Options: Export telemetry to backends; provide language-specific SDKs; define the interface for creating telemetry; collect and store telemetry locally.
* Correct: Define the interface for creating telemetry data (traces, metrics, logs). Exporting is handled by SDKs/plugins.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-knowledge-check-slide.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=6e3f33d5759e4131716aa7452265962b" alt="The image is a &#x22;Knowledge Check&#x22; slide asking about the primary purpose of the OpenTelemetry API, with three options listed as answers." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-knowledge-check-slide.jpg" />
</Frame>

2. In OpenTelemetry, what does a tracer object do?

* Options: Collect metrics; export spans; create and manage spans; aggregate logs.
* Correct: Create and manage spans to trace operations. Exporting is done by SDK/exporters.

3. Which statement about OpenTelemetry API and SDK is correct?

* Options: API and SDK are tightly coupled; Applications only use the SDK directly; The API is designed to be used independently of the SDK; The API requires a specific backend at compile time.
* Correct: The API is designed to be used independently of the SDK. It is no-op-safe.

4. What happens if an application only uses the OpenTelemetry API and no SDK is configured?

* Options: Application fails to start; Telemetry is generated and exported by default; The API operates in no-op mode without errors; The API throws runtime exceptions for missing SDKs.
* Correct: The API operates in a no-op mode without errors; telemetry is discarded unless an SDK is configured.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/BBtH5GyNI0zR7M4h/images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-knowledge-check-slide-2.jpg?fit=max&auto=format&n=BBtH5GyNI0zR7M4h&q=85&s=aa5c05d0b03a3b7a5c01f87125ef2dac" alt="The image is a knowledge check slide asking what happens if an application uses the OpenTelemetry API without configuring an SDK, with three possible answers provided." width="1920" height="1080" data-path="images/Prep-Course-OpenTelemetry-Certified-Associate-OTCA-Certification/OpenTelemetry-Core-Concepts/OpenTelemetry-API/opentelemetry-api-knowledge-check-slide-2.jpg" />
</Frame>

That’s it for this lesson/article.

Links and references

* OpenTelemetry documentation: [https://opentelemetry.io/docs/](https://opentelemetry.io/docs/)
* Python instrumentation guide: [https://opentelemetry.io/docs/instrumentation/python/](https://opentelemetry.io/docs/instrumentation/python/)
* Semantic conventions: [https://opentelemetry.io/docs/reference/specification/semantic\_conventions/](https://opentelemetry.io/docs/reference/specification/semantic_conventions/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/prep-course-opentelemetry-certified-associate-certification-otca/module/da1c735f-c606-45b0-9bbf-04fe366fbd23/lesson/81da0512-b628-459a-941a-7ed90b163b3c" />
</CardGroup>
