Skip to content

Commit ccdee00

Browse files
authored
distro: set default sampler to parentbased_traceidratio (#351)
1 parent 26d8fb1 commit ccdee00

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/elasticotel/distro/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
OTEL_EXPERIMENTAL_RESOURCE_DETECTORS,
3636
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
3737
OTEL_EXPORTER_OTLP_PROTOCOL,
38+
OTEL_TRACES_SAMPLER,
3839
)
3940
from opentelemetry.sdk.resources import OTELResourceDetector
4041
from opentelemetry.util._importlib_metadata import EntryPoint
@@ -114,6 +115,7 @@ def _configure(self, **kwargs):
114115
os.environ.setdefault(OTEL_METRICS_EXEMPLAR_FILTER, "always_off")
115116
# preference to use DELTA temporality as we can handle only this kind of Histograms
116117
os.environ.setdefault(OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, "DELTA")
118+
os.environ.setdefault(OTEL_TRACES_SAMPLER, "parentbased_traceidratio")
117119

118120
base_resource_detectors = ["process_runtime", "os", "otel", "telemetry_distro", "service_instance"]
119121
detectors = base_resource_detectors + get_cloud_resource_detectors()

tests/distro/test_distro.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
OTEL_EXPERIMENTAL_RESOURCE_DETECTORS,
3333
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE,
3434
OTEL_EXPORTER_OTLP_PROTOCOL,
35+
OTEL_TRACES_SAMPLER,
3536
)
37+
from opentelemetry.sdk.trace import sampling
3638
from opentelemetry._opamp.proto import opamp_pb2 as opamp_pb2
3739

3840

@@ -51,6 +53,20 @@ def test_default_configuration(self):
5153
)
5254
self.assertEqual("always_off", os.environ.get(OTEL_METRICS_EXEMPLAR_FILTER))
5355
self.assertEqual("DELTA", os.environ.get(OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE))
56+
self.assertEqual("parentbased_traceidratio", os.environ.get(OTEL_TRACES_SAMPLER))
57+
58+
@mock.patch.dict("os.environ", {}, clear=True)
59+
def test_sampler_configuration(self):
60+
distro = ElasticOpenTelemetryDistro()
61+
distro._configure()
62+
parent_sampler = sampling._get_from_env_or_default()
63+
64+
assert isinstance(parent_sampler, sampling.ParentBasedTraceIdRatio)
65+
66+
sampler = parent_sampler._root
67+
68+
assert isinstance(sampler, sampling.TraceIdRatioBased)
69+
assert sampler.rate == 1.0
5470

5571
@mock.patch.dict("os.environ", {}, clear=True)
5672
def test_load_instrumentor_call_with_default_kwargs_for_SystemMetricsInstrumentor(self):

0 commit comments

Comments
 (0)