{"id":21660,"library":"opentelemetry-resource-detector-containerid","title":"OpenTelemetry Container Resource Detector","description":"Detects container ID from cgroup or container runtime to enrich OpenTelemetry resource attributes. Current version 0.62b1, beta release. Part of opentelemetry-python-contrib releases, cadence aligned with OpenTelemetry Python releases.","status":"active","version":"0.62b1","language":"python","source_language":"en","source_url":"https://github.com/open-telemetry/opentelemetry-python-contrib","tags":["opentelemetry","container","resource-detector","observability"],"install":[{"cmd":"pip install opentelemetry-resource-detector-containerid","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for Resource class and SDK integration","package":"opentelemetry-sdk","optional":false},{"reason":"Provides base types and API","package":"opentelemetry-api","optional":false}],"imports":[{"note":"The package name uses hyphens, but import path uses underscores as per Python convention.","wrong":"from opentelemetry_resource_detector_container import ContainerIDResourceDetector","symbol":"ContainerIDResourceDetector","correct":"from opentelemetry.resource.detector.container import ContainerIDResourceDetector"}],"quickstart":{"code":"from opentelemetry import trace\nfrom opentelemetry.resource.detector.container import ContainerIDResourceDetector\nfrom opentelemetry.sdk.resources import get_aggregated_resources\n\n# Create a resource detector instance\ndetector = ContainerIDResourceDetector()\n# For the latest SDK, use get_aggregated_resources to merge multiple detectors\nresource = get_aggregated_resources([detector])\n# Or if using older SDK (pre-1.25):\n# resource = detector.detect()\nprint(resource.attributes.get('container.id', 'no container ID found'))","lang":"python","description":"Detect container ID and merge into a resource. Newer SDKs require get_aggregated_resources; detect() is deprecated."},"warnings":[{"fix":"Use `get_aggregated_resources([detector])` instead of `detector.detect()`.","message":"The method `detect()` on ContainerIDResourceDetector is deprecated in favor of `get_aggregated_resources` from opentelemetry.sdk.resources.","severity":"deprecated","affected_versions":">=1.25.0"},{"fix":"Ensure the container runtime exposes cgroup files. Use `container.id` attribute only when the detector succeeds; fall back to a default value if needed.","message":"Container ID detection requires access to /proc/self/cgroup or /proc/1/cgroup and may fail in environments without cgroup v1 or v2. On some container runtimes (e.g., Podman), the ID format differs.","severity":"gotcha","affected_versions":"All"},{"fix":"Install opentelemetry-sdk: `pip install opentelemetry-sdk`.","message":"The detector is part of `opentelemetry-python-contrib` and does not include OpenTelemetry SDK itself. Users must install `opentelemetry-sdk` separately.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from opentelemetry.resource.detector.container import ContainerIDResourceDetector","cause":"Incorrect import path: using hyphens instead of underscores.","error":"ModuleNotFoundError: No module named 'opentelemetry_resource_detector_container'"},{"fix":"Update to use get_aggregated_resources from opentelemetry.sdk.resources, or install compatible older SDK. Example: resource = get_aggregated_resources([detector])","cause":"In older versions of opentelemetry-sdk, detect() exists but is deprecated; in newer versions the method may have been removed or renamed.","error":"AttributeError: 'ContainerIDResourceDetector' object has no attribute 'detect'"},{"fix":"Check that resource is not None before accessing attributes, or use get_aggregated_resources which always returns a Resource.","cause":"The detector may return None if container ID is not found, and code tries to access attributes.","error":"TypeError: 'NoneType' object is not subscriptable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}