opentelemetry-resourcedetector-docker is a Python package for OpenTelemetry that automatically enriches telemetry data with resource attributes derived from the Docker container environment where the application is running. Currently at version 0.4.0, it is actively maintained with releases as needed to align with OpenTelemetry Python SDK and address Docker-related detection specifics.
pip install opentelemetry-resourcedetector-dockerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the OpenTelemetry SDK with the `DockerResourceDetector` to automatically gather Docker-related resource attributes. The collected attributes are then used by a `TracerProvider` and printed to the console via a `ConsoleSpanExporter`. Ensure Docker is running and the application has permissions to access the Docker socket for successful detection.
Ensure the user running the application has read permissions for the Docker socket. Mount the Docker socket into the container (e.g., `-v /var/run/docker.sock:/var/run/docker.sock`) and configure appropriate user/group permissions.
Consider alternatives like manually setting `OTEL_RESOURCE_ATTRIBUTES` or using other detectors that might be available for macOS container environments if Docker-specific attributes are crucial.
Verify that the Docker daemon is running and accessible from the application's environment. Check logs for connection errors (e.g., 'connect ETIMEDOUT') and ensure proper socket configuration.
Be mindful of the order of detectors when aggregating resources. If conflicts are observed, adjust the order or explicitly set desired attributes through other means (e.g., `OTEL_RESOURCE_ATTRIBUTES` environment variable, which takes precedence over code-based attributes).
Ensure the package is installed using pip: `pip install opentelemetry-resourcedetector-docker`. If running in a Docker container or virtual environment, verify that pip installs into the correct environment, potentially by using `python -m pip install opentelemetry-resourcedetector-docker`.
Ensure the `opentelemetry-resourcedetector-docker` package is installed (`pip install opentelemetry-resourcedetector-docker`) and that `DockerResourceDetector` is correctly passed to `get_aggregated_resources` or `TracerProvider` initialization.
Ensure the OpenTelemetry Collector or the application running the detector has read permissions to the Docker socket by mounting it as read-only: `-v /var/run/docker.sock:/var/run/docker.sock:ro`. Also, ensure the `/proc` filesystem is mounted if in a restricted container: `-v /proc:/host/proc:ro`.
Avoid using `network_mode: host` with resource detection that relies on container names, or ensure the container's hostname is distinct from the host's. For host metrics, consider using the `system` detector instead of `docker` detector if container-specific details are not strictly required, or ensure proper container naming and lookup mechanisms.
No dependency data recorded yet.