Registry / observability / opentelemetry-container-distro

opentelemetry-container-distro

JSON →
library0.2.0pypypi✓ verified 22d ago

An OpenTelemetry distro which automatically discovers container attributes from the environment. This distribution extends the standard `opentelemetry-distro` to automatically include additional resource detectors tailored for container environments, such as Docker or Kubernetes. It aims to simplify OpenTelemetry setup by providing automatic configuration, while largely preserving the behavior of `opentelemetry-distro`. The current version is 0.2.0, released on September 18, 2022, indicating a slower release cadence compared to core OpenTelemetry components.

pip install opentelemetry-container-distro
INSTALL
IMPORT
SIG · OPENTELEMETRY-CONT
O
opentelemetry-container-distro
observabilitypythonv0.2.0
Install
5.3s avg
Import
757ms
Disk
51MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.798s · 52.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.3s · import 0.716s · 51MB
51MB installed
● package 51MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OpenTelemetryContainerDistro
from opentelemetry_container_distro import OpenTelemetryContainerDistro
from opentelemetry.sdk.resources import get_resource
DockerResourceDetector
from opentelemetry_container_distro import DockerResourceDetector
get_aggregated_resources
from opentelemetry_container_distro import get_aggregated_resources

This quickstart demonstrates how to use the `opentelemetry-container-distro` by simply installing it and then interacting with the standard OpenTelemetry Python API. The key takeaway is how to retrieve and inspect the resource attributes, which should automatically include container-specific metadata if the application is running within a recognized container environment (e.g., Docker, Kubernetes). An OpenTelemetry Collector is typically needed to receive and export telemetry data.

import os from opentelemetry import trace from opentelemetry.sdk.resources import get_resource # Ensure an OTLP collector is available if you want to export traces. # For example, by running 'docker run -p 4317:4317 -p 4318:4318 otel/opentelemetry-collector:latest' # or configure your OTLP endpoint via environment variables like OTEL_EXPORTER_OTLP_ENDPOINT. # The distro is installed and auto-configures the tracer provider and resource detectors. # We can directly get the tracer and retrieve the resource. tracer = trace.get_tracer("my-container-app") with tracer.start_as_current_span("my-container-operation"): print("Performing an operation within a container context...") # Retrieve the resource and print its attributes to show container detection resource = get_resource() print("\nDetected Resource Attributes (should include container.* if running in a container):") for key, value in resource.attributes.items(): print(f" {key}: {value}") print("\nTrace generated. Check your OTLP collector for exported data.")
opentelemetry --version
Debug
Known issues
gotchaThis distro, like `opentelemetry-distro`, primarily configures an OTLP SpanExporter, which typically sends data to a running OpenTelemetry Collector. Users must ensure a Collector is deployed and accessible to actually receive and process the telemetry. The Collector itself has frequent breaking changes and its Docker image registry moved from DockerHub to GitHub Container Registry, requiring updates to deployment configurations.
fix
Ensure an OpenTelemetry Collector is running and correctly configured to receive OTLP data (gRPC default on port 4317, HTTP on 4318). Regularly check Collector release notes for breaking changes and update image references (e.g., from `otel/opentelemetry-collector-contrib` to `ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib`).
affects: All versions
gotchaFor automatic container attribute detection to work, the application or the underlying OpenTelemetry SDK components need appropriate access to the container runtime's information, typically via the Docker socket (`/var/run/docker.sock`) or similar mechanisms for other container runtimes. Without this access, container attributes will not be automatically populated.
fix
When running in a container, ensure the Docker socket is mounted (e.g., `-v /var/run/docker.sock:/var/run/docker.sock`) or that the execution environment grants the necessary permissions and access to container metadata APIs (e.g., ECS task metadata endpoint for AWS ECS). 
affects: All versions
gotchaThe `opentelemetry-container-distro` has seen infrequent updates (last release 0.2.0 in September 2022). In contrast, the upstream OpenTelemetry Python SDK and `opentelemetry-distro` are under active and rapid development (e.g., `opentelemetry-distro 0.62b0` in April 2026). This disparity means that `opentelemetry-container-distro` might depend on older versions of the SDK, potentially missing out on newer features, performance improvements, or important bug fixes available in more recent OpenTelemetry releases.
fix
Monitor the project's GitHub repository for new releases. If using the latest OpenTelemetry SDK features is critical, users might need to manually configure resource detectors or consider a more actively maintained OpenTelemetry distribution, or contribute to updating this distro.
affects: <0.3.0
gotchaThe core concept of an OpenTelemetry 'distro' is to provide auto-configuration, meaning much of the setup happens implicitly upon installation and application startup. New users might expect explicit `init()` or `configure()` calls directly on the distro package, but the primary interaction remains through the standard `opentelemetry` API (e.g., `opentelemetry.trace`).
fix
Understand that the distro's role is to pre-configure the global OpenTelemetry SDK components. After installation, applications should interact with OpenTelemetry using its standard APIs (e.g., `from opentelemetry import trace`). Refer to the `opentelemetry-distro` documentation for general usage patterns if explicit configuration is needed beyond defaults.
affects: All versions
Upgrade
Version history
0.2.0latest on PyPI · released Sep 18, 2022
Audit
Dependencies
opentelemetry-distrorequiredThis package builds upon and extends the core OpenTelemetry Python distribution, inheriting its setup and default configurations.
opentelemetry-sdkrequiredFundamental OpenTelemetry SDK components for tracing and metrics, including resource detection.
Agent activity
15 hits · last 30 days
node
10
OpenAI (training)
2
Resources
opentelemetry-container-distro — pip install opentelemetry-container-distro · libregistry