5

I'm confused as why OpenTelemetry documentaion has OpenTelemetry Python API and OpenTelemetry Python SDK.
Like when using the specification in python when we should consider pip install opentelemetry-api over pip install opentelemetry-sdk

user5319825
  • 491
  • 1
  • 6
  • 16

3 Answers3

2

There's no need to specify both the API and SDK dependencies in Python as the SDK has a dependency on the API:

https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-sdk/pyproject.toml#L29

The short answer for when to use each is that the API should be specified as a dependency for packages/libraries and the SDK for applications.

The reason for this is that API contains the interface for instrumenting code with traces, metrics and logs. The SDK contains the additional functionality to collect, process and export that data.

For example, if I wanted to include instrumentation in a PyPI package that I've created, I would add the API as a dependency and use that to instrument my code. Then if someone were to use my PyPI package in their application, they could include the instrumentation data that my package generates. However, they would have to install the SDK in order to configure their application to do anything with that telemetry data other than simply generate it, e.g. sending it to an OpenTelemetry collector or third party.

Sernst
  • 469
  • 1
  • 4
  • 8
-1

From the github pages of the implementation.

(note: could not fit this into a comment and did not want to just post a link alone)

This repository includes multiple installable packages. The opentelemetry-api package includes abstract classes and no-op implementations that comprise the OpenTelemetry API following the OpenTelemetry specification. The opentelemetry-sdk package is the reference implementation of the API.

Libraries that produce telemetry data should only depend on opentelemetry-api, and defer the choice of the SDK to the application developer. Applications may depend on opentelemetry-sdk or another package that implements the API.

Ramachandran.A.G
  • 4,788
  • 1
  • 12
  • 24
  • thanks, could you please explain in simple terms? – user5319825 Jul 13 '22 at 12:07
  • I think it is an extension of OpenTelemetry itself (API vs SDK) , This is on : https://opentelemetry.io/docs/reference/specification/overview/. The API provides common interfaces for Logs/Traces/Metrics like a specification with NoOp implementations. The SDK uses this API spec and then provides a concrete implementation of this specification – Ramachandran.A.G Jul 13 '22 at 12:12
-1

In simple terms imagine a plain python or JAVA interface. An interface by itself is just a contract saying what all things it can do. But you cannot use that in your code anywhere without implementing the interface first. So interfaces are just abstract contracts(API) which needs to be have concrete implementations(SDK). It is only then can you use the SDK.

Such strategies normally help with unifying the implementations of software libraries across industry under a consistent and constant contract. There are multiple vendors out there like Datadog, New Relic, DynaTrace, Signoz and more who can now implement their own SDK if needed but at the same time comply with a standard contract that everyone abides by. This allows you as application developers to not get coupled to any one vendor. But have the option to choose the best one among them and make the swap when necessary without breaking anything in your software system.

Hope this helps answering why application may only depend on SDK.