Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tracing): lazy importing asyncio should not reset existing trace context [backport 2.7] #9334

Merged
merged 4 commits into from
May 28, 2024

Conversation

github-actions[bot]
Copy link
Contributor

Backport 06b8494 from #9272 to 2.7.

This PR introduces two main changes:

  1. Do not reset _DD_CONTEXTVAR when initializing a DefaultContextProvider
  2. Explicitly clear _DD_CONTEXTVAR after every test in dd-trace-py CI
    1. We also emit a warning, so pytest will show them to us

Motivation

Currently, when

  1. asyncio auto instrumentation is patched
  2. and there's an existing trace context
  3. and asyncio is imported
    Then the existing trace context will be reset to None.
    The expected behavior is that the existing trace context should not be reset for this kind of lazy imports

Checklist

  • Change(s) are motivated and described in the PR description
  • Testing strategy is described if automated tests are not included in the PR
  • Risks are described (performance impact, potential for breakage, maintainability)
  • Change is maintainable (easy to change, telemetry, documentation)
  • Library release note guidelines are followed or label changelog/no-changelog is set
  • Documentation is included (in-code, generated user docs, public corp docs)
  • Backport labels are set (if applicable)
  • If this PR changes the public interface, I've notified @DataDog/apm-tees.

Reviewer Checklist

  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Description motivates each change
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Change is maintainable (easy to change, telemetry, documentation)
  • Release note makes sense to a user of the library
  • Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

…ontext (#9272)

This PR introduces two main changes:

1. Do not reset `_DD_CONTEXTVAR` when initializing a
`DefaultContextProvider`
2. Explicitly clear `_DD_CONTEXTVAR` after every test in dd-trace-py CI
  1. We also emit a warning, so pytest will show them to us

## Motivation
Currently, when
1. asyncio auto instrumentation is patched
5. and there's an existing trace context
6. and `asyncio` is imported
Then the existing trace context will be reset to None.
The expected behavior is that the existing trace context should not be
reset for this kind of lazy imports

## 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

- [ ] Title is accurate
- [ ] All changes are related to the pull request's stated goal
- [ ] Description motivates each change
- [ ] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [ ] Testing strategy adequately addresses listed risks
- [ ] Change is maintainable (easy to change, telemetry, documentation)
- [ ] Release note makes sense to a user of the library
- [ ] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [ ] 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: Brett Langdon <[email protected]>
(cherry picked from commit 06b8494)
@github-actions github-actions bot requested review from a team as code owners May 21, 2024 18:29
@brettlangdon brettlangdon reopened this May 21, 2024
@brettlangdon brettlangdon enabled auto-merge (squash) May 21, 2024 18:31
@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented May 21, 2024

Datadog Report

Branch report: backport-9272-to-2.7
Commit report: b05e334
Test service: dd-trace-py

✅ 0 Failed, 86 Passed, 976 Skipped, 26m 43.99s Total duration (58m 32.88s time saved)

@pr-commenter
Copy link

pr-commenter bot commented May 21, 2024

Benchmarks

Benchmark execution time: 2024-05-28 19:37:40

Comparing candidate commit ffecbec in PR branch backport-9272-to-2.7 with baseline commit 3d33fb1 in branch 2.7.

Found 1 performance improvements and 0 performance regressions! Performance is the same for 200 metrics, 9 unstable metrics.

scenario:span-add-metrics

  • 🟩 max_rss_usage [-23.118MB; -23.039MB] or [-41.278%; -41.136%]

@datadog-datadog-prod-us1
Copy link
Contributor

datadog-datadog-prod-us1 bot commented May 28, 2024

Software Composition Analysis

We found vulnerabilities in the following libraries (compared ffecbec against 307fb17):

@brettlangdon brettlangdon merged commit 113c9dd into 2.7 May 28, 2024
162 of 187 checks passed
@brettlangdon brettlangdon deleted the backport-9272-to-2.7 branch May 28, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants