Skip to content

Commit

Permalink
fix(internal): writer recreate maintain extra headers [backport 2.7] (#…
Browse files Browse the repository at this point in the history
…9429)

Backport 9e637e7 from #9424 to 2.7.

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)

Co-authored-by: Federico Mon <[email protected]>
  • Loading branch information
github-actions[bot] and gnufede authored May 29, 2024
1 parent 113c9dd commit ece781c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddtrace/internal/writer/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ def recreate(self):
dogstatsd=self.dogstatsd,
sync_mode=self._sync_mode,
api_version=self._api_version,
headers=self._headers,
)

@property
Expand Down
10 changes: 10 additions & 0 deletions tests/tracer/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit ece781c

Please sign in to comment.