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

feat: integration with dd-trace-api #12057

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

emmettbutler
Copy link
Collaborator

@emmettbutler emmettbutler commented Jan 23, 2025

This change adds an integration for the dd-trace-api-py package. That package is still in pre-release development, so the code this change adds will not be exercised except in CI.

The basic integration added here instruments the interface exposed by the dd-trace-api package, proxying its calls to real Tracer and Span objects. The basic functionality of tracing is implemented, including start_span, trace, finish, and current_span. More operations, like setting links or tags on spans, will be implemented in a future pull request. Other parts of the public API like Pin and data_streams will also be included in future pull requests.

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

@emmettbutler emmettbutler requested review from a team as code owners January 23, 2025 21:06
@emmettbutler emmettbutler marked this pull request as draft January 23, 2025 21:06
Copy link
Contributor

github-actions bot commented Jan 23, 2025

CODEOWNERS have been resolved as:

.riot/requirements/10e65d1.txt                                          @DataDog/apm-python
.riot/requirements/1261872.txt                                          @DataDog/apm-python
.riot/requirements/14d1688.txt                                          @DataDog/apm-python
.riot/requirements/668f2f5.txt                                          @DataDog/apm-python
.riot/requirements/d5f777e.txt                                          @DataDog/apm-python
.riot/requirements/e49670c.txt                                          @DataDog/apm-python
ddtrace/contrib/internal/dd_trace_api/__init__.py                       @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/dd_trace_api/patch.py                          @DataDog/apm-core-python @DataDog/apm-idm-python
releasenotes/notes/dd-trace-api-integration-0fa7ea051a4d6ce1.yaml       @DataDog/apm-python
tests/contrib/dd_trace_api/__init__.py                                  @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/dd_trace_api/test_dd_trace_api_patch.py                   @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/dd_trace_api/test_integration.py                          @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/_monkey.py                                                      @DataDog/apm-core-python
lib-injection/sources/min_compatible_versions.csv                       @DataDog/apm-core-python
min_compatible_versions.csv                                             @DataDog/apm-core-python
riotfile.py                                                             @DataDog/apm-python
tests/contrib/suitespec.yml                                             @DataDog/apm-core-python @DataDog/apm-idm-python

@pr-commenter
Copy link

pr-commenter bot commented Jan 23, 2025

Benchmarks

Benchmark execution time: 2025-02-04 20:55:19

Comparing candidate commit e043f22 in PR branch emmett.butler/dd-trace-api-integration with baseline commit af9098c in branch main.

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

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

datadog-dd-trace-py-rkomorn bot commented Jan 24, 2025

Datadog Report

Branch report: emmett.butler/dd-trace-api-integration
Commit report: db87343
Test service: dd-trace-py

✅ 0 Failed, 130 Passed, 1468 Skipped, 4m 38.63s Total duration (35m 46.84s time saved)

@emmettbutler emmettbutler changed the title stub integration with dd-trace-api feat: integration with dd-trace-api Jan 27, 2025
@emmettbutler emmettbutler marked this pull request as ready for review January 27, 2025 19:54
def test_set_exc_info(self):
with dd_trace_api.tracer.trace("web.request") as span:
try:
raise Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Exception is too generic (...read more)

Do not raise Exception and BaseException. These are too generic. Having generic exceptions makes it difficult to differentiate errors in a program. Use a specific exception, for example, ValueError, or create your own instead of using generic ones.

Learn More

View in Datadog  Leave us feedback  Documentation

def test_set_traceback(self):
with dd_trace_api.tracer.trace("web.request") as span:
try:
raise Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Violation

Exception is too generic (...read more)

Do not raise Exception and BaseException. These are too generic. Having generic exceptions makes it difficult to differentiate errors in a program. Use a specific exception, for example, ValueError, or create your own instead of using generic ones.

Learn More

View in Datadog  Leave us feedback  Documentation

ddtrace/contrib/dd_trace_api/__init__.py Outdated Show resolved Hide resolved
return getattr(dd_trace_api, "__version__", "")


def patch(tracer=None):
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure the integration patch/unpatch approach makes sense here, should we always register an audit hook that listens for these events?

are there ever any cases when we wouldn't want to listen to the events? it would probably be better to have dd_trace_api not emit events if you want to "disable" vs having that handled here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

patch, unpatch and get_version are here just to make this code work with the existing contrib structure. The contrib is enabled by default, and it can be disabled by the same method as any other default-on contrib. As far as I can tell, this code makes sense as a contrib because that provides lazy loading.

ddtrace/contrib/internal/dd_trace_api/patch.py Outdated Show resolved Hide resolved
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.

2 participants