diff --git a/src/instana/options.py b/src/instana/options.py index f63ed9c7..d12c5213 100644 --- a/src/instana/options.py +++ b/src/instana/options.py @@ -115,6 +115,11 @@ def set_trace_configurations(self) -> None: "trace_correlation", True ) + if "INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION" in os.environ: + config["asyncio_task_context_propagation"]["enabled"] = is_truthy( + os.environ["INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION"] + ) + self.set_disable_trace_configurations() self.set_stack_trace_configurations() self.set_span_filter_configurations() diff --git a/tests/test_options.py b/tests/test_options.py index d0004e09..f92e85db 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -842,6 +842,23 @@ def test_tracing_filter_environment_variables(self) -> None: ], } + def test_asyncio_task_context_propagation_default(self) -> None: + """INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION is False by default.""" + self.base_options = BaseOptions() + assert config["asyncio_task_context_propagation"]["enabled"] is False + + @patch.dict(os.environ, {"INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION": "true"}) + def test_asyncio_task_context_propagation_enabled_via_env(self) -> None: + """INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION=true enables the flag.""" + self.base_options = BaseOptions() + assert config["asyncio_task_context_propagation"]["enabled"] is True + + @patch.dict(os.environ, {"INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION": "false"}) + def test_asyncio_task_context_propagation_disabled_via_env(self) -> None: + """INSTANA_ASYNCIO_TASK_CONTEXT_PROPAGATION=false keeps the flag disabled.""" + self.base_options = BaseOptions() + assert config["asyncio_task_context_propagation"]["enabled"] is False + class TestStandardOptions: @pytest.fixture(autouse=True)