Skip to content

distro: enable containerid resource detector #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/elasticotel/distro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ def _configure(self, **kwargs):
os.environ.setdefault(OTEL_TRACES_SAMPLER, "parentbased_traceidratio")
os.environ.setdefault(OTEL_TRACES_SAMPLER_ARG, "1.0")

base_resource_detectors = ["process_runtime", "os", "otel", "telemetry_distro", "service_instance"]
base_resource_detectors = [
"process_runtime",
"os",
"otel",
"telemetry_distro",
"service_instance",
"containerid",
]
detectors = base_resource_detectors + get_cloud_resource_detectors()
os.environ.setdefault(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS, ",".join(detectors))
2 changes: 1 addition & 1 deletion tests/distro/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_default_configuration(self):
self.assertEqual("otlp", os.environ.get(OTEL_LOGS_EXPORTER))
self.assertEqual("grpc", os.environ.get(OTEL_EXPORTER_OTLP_PROTOCOL))
self.assertEqual(
"process_runtime,os,otel,telemetry_distro,service_instance,_gcp,aws_ec2,aws_ecs,aws_elastic_beanstalk,azure_app_service,azure_vm",
"process_runtime,os,otel,telemetry_distro,service_instance,containerid,_gcp,aws_ec2,aws_ecs,aws_elastic_beanstalk,azure_app_service,azure_vm",
os.environ.get(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS),
)
self.assertEqual("always_off", os.environ.get(OTEL_METRICS_EXEMPLAR_FILTER))
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import pytest

from opentelemetry.resource.detector.containerid import (
ContainerResourceDetector,
)

from .utils import ElasticIntegrationTestCase, OTEL_INSTRUMENTATION_VERSION, ROOT_DIR


Expand Down Expand Up @@ -49,6 +53,10 @@ def test_traces_default_resource_attributes(self):
self.assertTrue(resource["os.type"])
self.assertTrue(resource["os.version"])

container_id = ContainerResourceDetector().detect().attributes.get("container.id")
if container_id:
self.assertEqual(resource["container.id"], container_id)

def test_traces_sets_resource_attributes_from_env(self):
env = {"OTEL_RESOURCE_ATTRIBUTES": "service.name=my-service"}
stdout, stderr, returncode = self.run_script(
Expand Down