Skip to content

feat: support dbm full and service mode propagation for pymongo#12680

Merged
lu-zhengda merged 19 commits intomainfrom
zhengda.lu/mongo-dbm-propagation
Apr 8, 2025
Merged

feat: support dbm full and service mode propagation for pymongo#12680
lu-zhengda merged 19 commits intomainfrom
zhengda.lu/mongo-dbm-propagation

Conversation

@lu-zhengda
Copy link
Contributor

@lu-zhengda lu-zhengda commented Mar 7, 2025

Description

This PR adds Database Monitoring (DBM) propagation support for pymongo. It enables linking MongoDB queries to DBM samples by injecting trace and span information as comments into MongoDB commands.
Two propagation modes are supported:

  • Full mode: Injects both service information and trace context
  • Service mode: Injects only service information

Version Support

Note: This feature requires PyMongo 3.9 and above. DBM propagation will be automatically disabled for PyMongo versions < 3.9.

Motivation

By linking traces to database queries, users can:

  • Correlate slow database operations with specific application requests
  • Identify which services generate problematic queries
  • Understand the full context of database operations

Configuration

Control with the DD_DBM_PROPAGATION_MODE environment variable:

DD_DBM_PROPAGATION_MODE=full|service|disabled

DD_DBM_PROPAGATION_MODE is disabled by default.

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/add-mongodb-dbm-propagation-support-3ff0f1423cafda8a.yaml  @DataDog/apm-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
ddtrace/propagation/_database_monitoring.py                             @DataDog/apm-sdk-api-python
ddtrace/vendor/sqlcommenter/__init__.py                                 @DataDog/apm-core-python
docker-compose.yml                                                      @DataDog/apm-core-python
tests/contrib/pymongo/test.py                                           @DataDog/apm-core-python @DataDog/apm-idm-python

@lu-zhengda lu-zhengda changed the title feat: Support DBM full and service mode propagation for pymongo feat: support dbm full and service mode propagation for pymongo Mar 7, 2025
@lu-zhengda lu-zhengda marked this pull request as draft March 7, 2025 21:44
@pr-commenter
Copy link

pr-commenter bot commented Mar 7, 2025

Benchmarks

Benchmark execution time: 2025-04-08 17:12:04

Comparing candidate commit c11c773 in PR branch zhengda.lu/mongo-dbm-propagation with baseline commit 46958d6 in branch main.

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

@lu-zhengda lu-zhengda marked this pull request as ready for review March 10, 2025 17:17
@lu-zhengda lu-zhengda enabled auto-merge (squash) April 7, 2025 22:20
Copy link
Contributor

@wconti27 wconti27 left a comment

Choose a reason for hiding this comment

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

LGTM

@lu-zhengda lu-zhengda disabled auto-merge April 8, 2025 14:21
@lu-zhengda
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Apr 8, 2025

View all feedbacks in Devflow UI.

2025-04-08 14:22:24 UTC ℹ️ Start processing command /merge


2025-04-08 14:22:43 UTC ℹ️ MergeQueue: waiting for PR to be ready

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2025-04-08 17:14:11 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 0s (p90).


2025-04-08 17:37:04 UTC ℹ️ MergeQueue: This merge request was already merged

This pull request was merged directly.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 238 ± 5 ms.

The average import time from base is: 245 ± 4 ms.

The import time difference between this PR and base is: -6.9 ± 0.2 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.221 ms (0.93%)
ddtrace.bootstrap.sitecustomize 1.539 ms (0.65%)
ddtrace.bootstrap.preload 1.539 ms (0.65%)
ddtrace.internal.products 1.539 ms (0.65%)
ddtrace.internal.remoteconfig.client 0.722 ms (0.30%)
ddtrace 0.682 ms (0.29%)

@lu-zhengda lu-zhengda merged commit 32d1e53 into main Apr 8, 2025
689 checks passed
@lu-zhengda lu-zhengda deleted the zhengda.lu/mongo-dbm-propagation branch April 8, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants