Skip to content

Commit

Permalink
Fixed OTEL sampler test warnings; set ignore parent envvar to True st…
Browse files Browse the repository at this point in the history
…ring.
  • Loading branch information
ddmclav committed May 24, 2024
1 parent e12969d commit 0828f94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions ddtrace/settings/_otel_remapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _remap_traces_sampler(otel_value):
"""Remaps the otel trace sampler to ddtrace trace sampler"""
if otel_value in ["always_on", "always_off", "traceidratio"]:
log.warning("Trace sampler set to %s; setting DD_TRACE_SAMPLE_IGNORE_PARENT to True.", otel_value)
os.environ["DD_TRACE_SAMPLE_IGNORE_PARENT"] = "True"
if otel_value == "always_on" or otel_value == "parentbased_always_on":
return "1.0"
elif otel_value == "always_off" or otel_value == "parentbased_always_off":
Expand Down
23 changes: 6 additions & 17 deletions tests/opentelemetry/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ def test_otel_log_level_configuration_debug():
assert config._debug_mode is True, config._debug_mode


@pytest.mark.subprocess(env={
"OTEL_LOG_LEVEL": "trace"
},
err=b"ddtrace does not support otel log level 'trace'. setting ddtrace to log level info.\n"
@pytest.mark.subprocess(
env={"OTEL_LOG_LEVEL": "trace"},
err=b"ddtrace does not support otel log level 'trace'. setting ddtrace to log level info.\n",
)
def test_otel_log_level_configuration_info():
from ddtrace import config
Expand Down Expand Up @@ -130,27 +129,17 @@ def test_otel_propagation_style_configuration_unsupportedwarning():

@pytest.mark.subprocess(
env={"OTEL_TRACES_SAMPLER": "always_on"},
err=b"Trace sampler set to always_on; only parent based sampling is supported.\n",
err=b"Trace sampler set to always_on; setting DD_TRACE_SAMPLE_IGNORE_PARENT to True.\n",
)
def test_otel_traces_sampler_configuration_alwayson():
from ddtrace import config

assert config._trace_sample_rate == 1.0, config._trace_sample_rate


@pytest.mark.subprocess(
env={"OTEL_TRACES_SAMPLER": "always_on"},
err=b"Trace sampler set to always_on; only parent based sampling is supported.\n",
)
def test_otel_traces_sampler_configuration_ignore_parent():
from ddtrace import config

assert config._trace_sample_rate == 1.0, config._trace_sample_rate


@pytest.mark.subprocess(
env={"OTEL_TRACES_SAMPLER": "always_off"},
err=b"Trace sampler set to always_off; only parent based sampling is supported.\n",
err=b"Trace sampler set to always_off; setting DD_TRACE_SAMPLE_IGNORE_PARENT to True.\n",
)
def test_otel_traces_sampler_configuration_alwaysoff():
from ddtrace import config
Expand All @@ -163,7 +152,7 @@ def test_otel_traces_sampler_configuration_alwaysoff():
"OTEL_TRACES_SAMPLER": "traceidratio",
"OTEL_TRACES_SAMPLER_ARG": "0.5",
},
err=b"Trace sampler set to traceidratio; only parent based sampling is supported.\n",
err=b"Trace sampler set to traceidratio; setting DD_TRACE_SAMPLE_IGNORE_PARENT to True.\n",
)
def test_otel_traces_sampler_configuration_traceidratio():
from ddtrace import config
Expand Down

0 comments on commit 0828f94

Please sign in to comment.