From 9e637e77b5111d6433f65db6e3494ee314d40f73 Mon Sep 17 00:00:00 2001 From: Federico Mon Date: Wed, 29 May 2024 16:19:29 +0200 Subject: [PATCH] fix(internal): writer recreate maintain extra headers (#9424) internal: this fixes an issue where a writer recreate call would make it drop extra headers passed to the ``__init__``. ## Checklist - [x] Change(s) are motivated and described in the PR description - [x] Testing strategy is described if automated tests are not included in the PR - [x] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)) - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --- ddtrace/internal/writer/writer.py | 1 + tests/tracer/test_writer.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/ddtrace/internal/writer/writer.py b/ddtrace/internal/writer/writer.py index ca3ef232b5b..f43a68b2788 100644 --- a/ddtrace/internal/writer/writer.py +++ b/ddtrace/internal/writer/writer.py @@ -539,6 +539,7 @@ def recreate(self): dogstatsd=self.dogstatsd, sync_mode=self._sync_mode, api_version=self._api_version, + headers=self._headers, ) @property diff --git a/tests/tracer/test_writer.py b/tests/tracer/test_writer.py index 3e5504d765a..0114d248696 100644 --- a/tests/tracer/test_writer.py +++ b/tests/tracer/test_writer.py @@ -706,6 +706,16 @@ def test_writer_recreate_api_version(init_api_version, api_version, endpoint, en assert isinstance(writer._encoder, encoder_cls) +def test_writer_recreate_keeps_headers(): + writer = AgentWriter("http://dne:1234", headers={"Datadog-Client-Computed-Stats": "yes"}) + assert "Datadog-Client-Computed-Stats" in writer._headers + assert writer._headers["Datadog-Client-Computed-Stats"] == "yes" + + writer = writer.recreate() + assert "Datadog-Client-Computed-Stats" in writer._headers + assert writer._headers["Datadog-Client-Computed-Stats"] == "yes" + + @pytest.mark.parametrize( "sys_platform, api_version, ddtrace_api_version, priority_sampling, raises_error, expected", [