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

chore(propagation): only call extract once per request for flask and django #11871

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZStriker19
Copy link
Contributor

Currently core will call start_span for each flask span and django span generated. Each start_span call calls activate_distribute_headers, which in turn call HTTP_PROPAGATOR.extract. This leads to around 4-8 unneeded calls of that method per request. The logic in activate_distributed_headers is what's currently saving us from not re-activating the same context over and over again when each new span is generated.

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 Jan 7, 2025

CODEOWNERS have been resolved as:

ddtrace/_trace/trace_handlers.py                                        @DataDog/apm-sdk-api-python
ddtrace/contrib/internal/flask/patch.py                                 @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/wsgi/wsgi.py                                   @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/trace_utils.py                                          @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/internal/core/__init__.py                                       @DataDog/apm-core-python

# this returns ddtrace.settings.integration.IntegrationConfig, we should change the naming to reflect this
# from distributed_headers_config to integration_config. Need to do this for calls of method too
integration_config = ctx.get_item("distributed_headers_config")
activate_distributed_headers = ctx.get_item("activate_distributed_headers")
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

variable name is the same as a function parameter (...read more)

A function parameter should only be read and not be modified. If your intent is to modify the value of the parameter, return the value in the function and handle the new value in the caller of the function.

View in Datadog  Leave us feedback  Documentation

@pr-commenter
Copy link

pr-commenter bot commented Jan 7, 2025

Benchmarks

Benchmark execution time: 2025-01-07 19:47:07

Comparing candidate commit 0d228eb in PR branch zachg/extract_once_per_request_django_and_flask with baseline commit 5f1aefc in branch main.

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

scenario:flasksimple-appsec-get

  • 🟩 execution_time [-1.715ms; -1.703ms] or [-48.111%; -47.761%]
  • 🟩 max_rss_usage [-5.400MB; -5.322MB] or [-9.036%; -8.905%]

scenario:flasksimple-appsec-post

  • 🟩 execution_time [-1.551ms; -1.540ms] or [-50.082%; -49.729%]
  • 🟩 max_rss_usage [-5.524MB; -5.334MB] or [-9.240%; -8.922%]

scenario:flasksimple-appsec-telemetry

  • 🟩 execution_time [-1.699ms; -1.687ms] or [-47.783%; -47.452%]
  • 🟩 max_rss_usage [-4.339MB; -4.263MB] or [-7.263%; -7.135%]

scenario:flasksimple-tracer

  • 🟩 execution_time [-1.714ms; -1.703ms] or [-48.087%; -47.772%]
  • 🟩 max_rss_usage [-5.439MB; -5.242MB] or [-9.118%; -8.788%]

scenario:flasksqli-appsec-enabled

  • 🟩 execution_time [-1.636ms; -1.628ms] or [-71.131%; -70.756%]
  • 🟩 max_rss_usage [-5.430MB; -5.156MB] or [-9.108%; -8.647%]

scenario:flasksqli-iast-enabled

  • 🟩 execution_time [-1.646ms; -1.638ms] or [-71.233%; -70.884%]
  • 🟩 max_rss_usage [-5.434MB; -5.239MB] or [-9.095%; -8.768%]

scenario:flasksqli-tracer-enabled

  • 🟩 execution_time [-1.638ms; -1.630ms] or [-71.146%; -70.790%]
  • 🟩 max_rss_usage [-5.571MB; -5.307MB] or [-9.323%; -8.881%]

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.

1 participant