-
Notifications
You must be signed in to change notification settings - Fork 418
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
chore(ci_visibility): only import ddtrace when pytest ddtrace module is enabled #8999
Merged
romainkomorn-exdatadog
merged 8 commits into
main
from
romain.komorn/CIVIS-9657/pytest_dont_import_ddtrace_by_default
Apr 19, 2024
Merged
chore(ci_visibility): only import ddtrace when pytest ddtrace module is enabled #8999
romainkomorn-exdatadog
merged 8 commits into
main
from
romain.komorn/CIVIS-9657/pytest_dont_import_ddtrace_by_default
Apr 19, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
romainkomorn-exdatadog
added
the
changelog/no-changelog
A changelog entry is not required for this PR.
label
Apr 16, 2024
BenchmarksBenchmark execution time: 2024-04-18 16:08:55 Comparing candidate commit 0a47b44 in PR branch Found 2 performance improvements and 4 performance regressions! Performance is the same for 195 metrics, 9 unstable metrics. scenario:flasksimple-appsec-get
scenario:flasksimple-appsec-telemetry
scenario:httppropagationextract-datadog_tracecontext_tracestate_not_propagated_on_trace_id_no_match
scenario:httppropagationinject-ids_only
scenario:httppropagationinject-with_dd_origin
scenario:httppropagationinject-with_tags_max_size
|
juan-fernandez
approved these changes
Apr 18, 2024
emmettbutler
approved these changes
Apr 18, 2024
…ddtrace_by_default
romainkomorn-exdatadog
deleted the
romain.komorn/CIVIS-9657/pytest_dont_import_ddtrace_by_default
branch
April 19, 2024 10:04
Merged
2 tasks
brettlangdon
pushed a commit
that referenced
this pull request
Aug 16, 2024
…s to try-except blocks (#10196) There are two changes in this commit: 1- remove "sub plugin" strategy introduced in #8999 The sub-plugin strategy was originally implemented to delay the import of `ddtrace`, however that import is (in the current scenario) inevitable because the `pyproject.toml` entry-points that tell `pytest` where to find plugins already import `ddtrace`, and the original motivation of the change in (#8281 and #4845) was instead addressed by #9141 . The motivation to revert this change is that some hooks (eg: `pytest_load_inital_conftests`) added by the class-based plugins do not execute when the plugin is loaded in the `pytest_configure()` hook in the `plugin.py` file itself. All the methods in the plugin classes use the `@staticmethod` decorator and do not benefit from being in a class. This change allows the versioned plugin files to implement hooks by virtue of being imported into the original plugin module. 2- move v2 functions to try-except blocks Since CI Visibility should never affect `pytest`'s execution (or, at the very least, should never prevent it from running to completion), the hooks themselves should never raise exceptions. With this change, some functions simply wrap the entire body in a try/except block, while some others define a separate function that is then called in a try/except block. A decorator was not used for this purpose because some hooks yield, while others don't, and logging relevant errors is also a little simpler. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, 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)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This defers importing ddtrace in the
pytest
,pytest-bdd
, andpytest-benchmark
plugins until after it's been determined that the plugin is enabled with (eg: by runningpytest --ddtrace
).The fixtures that use
ddtrace
defer importing until the feature is actually requested due to the fact that fixtures imported later (eg: after plugins have loaded) are not usable.Even though this doesn't actually address the issues reported in #8281 or #4845 (due to the side effects of
ddtrace/__init__.py
), this change is still helpful in other ways (in particular since I'll be introducing a new version of thepytest
plugin shortly).Fixtures were confirmed to still be working by:
--ddtrace-patch-all
ddspan
fixtureddtracer
fixture returns the tracer object.Checklist
changelog/no-changelog
is set@DataDog/apm-tees
.Reviewer Checklist