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(pymongo): use bytecode wrapping to trace pymongo clients #10516

Merged
merged 23 commits into from
Sep 10, 2024

Conversation

mabdinur
Copy link
Contributor

@mabdinur mabdinur commented Sep 5, 2024

Resolves: #10344

  • Uses bytecode wrapping instead of wrapt's objectproxys to instrument mongo clients and socket connections
  • Previously the pin object used in the MongoClient was different from the ones used to trace socket connections. Updates usages of the Pin object to ensure sever, socket, and client objects use the same Pin. This sublte fix required updating the span counts in tests (now the DummyTracer used in tests is expected to capture one more span per trace).
  • Updates the mongoengine integration to simply use the pymongo integration. This integration no longer does anything special and can be removed.
  • Improves the test coverage of the pymongo integration. Ensures every pymongo version range with custom patching has test coverage.

Checklist

  • 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
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

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

Copy link
Contributor

github-actions bot commented Sep 5, 2024

CODEOWNERS have been resolved as:

.riot/requirements/12616cb.txt                                          @DataDog/apm-python
.riot/requirements/14b37e6.txt                                          @DataDog/apm-python
.riot/requirements/167d6de.txt                                          @DataDog/apm-python
.riot/requirements/1fd0884.txt                                          @DataDog/apm-python
.riot/requirements/3343686.txt                                          @DataDog/apm-python
.riot/requirements/d66afaf.txt                                          @DataDog/apm-python
releasenotes/notes/munir-pymongo-fix-patching-545f3947644c91cd.yaml     @DataDog/apm-python
ddtrace/contrib/internal/mongoengine/patch.py                           @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/mongoengine/trace.py                           @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/pymongo/client.py                              @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/pymongo/patch.py                               @DataDog/apm-core-python @DataDog/apm-idm-python
riotfile.py                                                             @DataDog/apm-python
tests/contrib/mongoengine/test.py                                       @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/pymongo/test.py                                           @DataDog/apm-core-python @DataDog/apm-idm-python

@pr-commenter
Copy link

pr-commenter bot commented Sep 5, 2024

Benchmarks

Benchmark execution time: 2024-09-09 22:55:43

Comparing candidate commit 139ec05 in PR branch munir/pymongo-fix-patching with baseline commit bdeb1ad in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 354 metrics, 46 unstable metrics.

@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Sep 5, 2024

Datadog Report

Branch report: munir/pymongo-fix-patching
Commit report: 139ec05
Test service: dd-trace-py

✅ 0 Failed, 8026 Passed, 2046 Skipped, 1h 37m 56.07s Total duration (34m 25.39s time saved)

mabdinur and others added 2 commits September 5, 2024 18:29
Co-authored-by: datadog-datadog-prod-us1[bot] <88084959+datadog-datadog-prod-us1[bot]@users.noreply.github.com>
@mabdinur mabdinur marked this pull request as ready for review September 5, 2024 23:49
@mabdinur mabdinur requested review from a team as code owners September 5, 2024 23:49
@mabdinur mabdinur requested a review from a team as a code owner September 6, 2024 16:57
Co-authored-by: datadog-datadog-prod-us1[bot] <88084959+datadog-datadog-prod-us1[bot]@users.noreply.github.com>
@mabdinur mabdinur enabled auto-merge (squash) September 6, 2024 20:16
@mabdinur mabdinur enabled auto-merge (squash) September 9, 2024 13:50
@mabdinur mabdinur changed the title fix(pymongo): use bytecode wrapping for pymongo client fix(pymongo): use bytecode wrapping to trace pymongo client Sep 9, 2024
@mabdinur mabdinur changed the title fix(pymongo): use bytecode wrapping to trace pymongo client fix(pymongo): use bytecode wrapping to trace pymongo clients Sep 9, 2024
Copy link
Contributor

@erikayasuda erikayasuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few questions for my own clarification. LGTM!

ddtrace/contrib/internal/pymongo/patch.py Outdated Show resolved Hide resolved
ddtrace/contrib/internal/mongoengine/patch.py Show resolved Hide resolved
ddtrace/contrib/internal/pymongo/client.py Show resolved Hide resolved
tests/contrib/mongoengine/test.py Show resolved Hide resolved
tests/contrib/pymongo/test.py Outdated Show resolved Hide resolved
@mabdinur mabdinur merged commit b7c4612 into main Sep 10, 2024
496 of 499 checks passed
@mabdinur mabdinur deleted the munir/pymongo-fix-patching branch September 10, 2024 01:32
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.

dd-trace-py is only reporting get-socket in APM spans
4 participants