Skip to content

fix(azure_functions): add await so async functions are instrumented without errors #13280

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

Merged
merged 6 commits into from
May 1, 2025

Conversation

duncanpharvey
Copy link
Contributor

@duncanpharvey duncanpharvey commented Apr 25, 2025

Add await for async Azure Functions to prevent errors on instrumentation.

https://datadoghq.atlassian.net/browse/SVLS-6703

Screenshot 2025-04-24 at 8 58 00 PM

Additional Notes:

There is an opportunity for some refactoring in order to better reuse code. In the interest of getting this fix out as quickly as possible I plan on handling that refactor in a separate PR.

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 Apr 25, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/fix-azure-functions-async-b9f61567dfb7eaba.yaml      @DataDog/apm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_http_get_ok_async.json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_http_get_ok_async_obfuscated.json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_http_get_ok_obfuscated.json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_timer_async.json  @DataDog/apm-python
ddtrace/contrib/internal/azure_functions/patch.py                       @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/azure_functions/azure_function_app/function_app.py        @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/azure_functions/test_azure_functions_snapshot.py          @DataDog/apm-core-python @DataDog/apm-idm-python

Copy link
Contributor

github-actions bot commented Apr 25, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 231 ± 2 ms.

The average import time from base is: 233 ± 2 ms.

The import time difference between this PR and base is: -2.2 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.010 ms (0.87%)
ddtrace.bootstrap.sitecustomize 1.305 ms (0.57%)
ddtrace.bootstrap.preload 1.305 ms (0.57%)
ddtrace.internal.products 1.305 ms (0.57%)
ddtrace.internal.remoteconfig.client 0.637 ms (0.28%)
ddtrace 0.705 ms (0.31%)
ddtrace._logger 0.035 ms (0.02%)
logging 0.035 ms (0.02%)
traceback 0.035 ms (0.02%)
contextlib 0.035 ms (0.02%)

@pr-commenter
Copy link

pr-commenter bot commented Apr 25, 2025

Benchmarks

Benchmark execution time: 2025-05-01 12:24:09

Comparing candidate commit 5c0587f in PR branch duncan-harvey/azure-functions-async with baseline commit 1f98157 in branch main.

Found 14 performance improvements and 3 performance regressions! Performance is the same for 484 metrics, 7 unstable metrics.

scenario:iast_aspects-ospathbasename_aspect

  • 🟥 execution_time [+453.230ns; +605.747ns] or [+10.911%; +14.583%]

scenario:iast_aspects-ospathjoin_aspect

  • 🟥 execution_time [+846.928ns; +929.022ns] or [+13.852%; +15.194%]

scenario:iast_aspects-rsplit_aspect

  • 🟥 execution_time [+124.882ns; +149.787ns] or [+8.373%; +10.042%]

scenario:packagesupdateimporteddependencies-import_many

  • 🟩 execution_time [-27.240ms; -27.106ms] or [-99.676%; -99.188%]

scenario:packagesupdateimporteddependencies-import_many_cached

  • 🟩 execution_time [-27.150µs; -25.435µs] or [-18.345%; -17.187%]

scenario:packagesupdateimporteddependencies-import_many_stdlib

  • 🟩 execution_time [-726.296ms; -722.767ms] or [-100.142%; -99.655%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • 🟩 execution_time [-726.796ms; -723.826ms] or [-100.181%; -99.772%]

scenario:packagesupdateimporteddependencies-import_many_unknown

  • 🟩 execution_time [-29.995ms; -29.851ms] or [-97.535%; -97.067%]

scenario:packagesupdateimporteddependencies-import_many_unknown_cached

  • 🟩 execution_time [-237.555µs; -225.172µs] or [-23.172%; -21.964%]

scenario:packagesupdateimporteddependencies-import_one

  • 🟩 execution_time [-11.258ms; -11.213ms] or [-100.023%; -99.624%]

scenario:packagesupdateimporteddependencies-import_one_cache

  • 🟩 execution_time [-693.802ns; -594.242ns] or [-9.953%; -8.525%]

scenario:packagesupdateimporteddependencies-import_one_stdlib

  • 🟩 execution_time [-10.329ms; -10.282ms] or [-100.044%; -99.594%]

scenario:packagesupdateimporteddependencies-import_one_stdlib_cache

  • 🟩 execution_time [-716.285ns; -632.607ns] or [-10.345%; -9.136%]

scenario:packagesupdateimporteddependencies-import_one_unknown

  • 🟩 execution_time [-19.720ms; -19.624ms] or [-100.011%; -99.526%]

scenario:packagesupdateimporteddependencies-import_one_unknown_cache

  • 🟩 execution_time [-724.526ns; -634.092ns] or [-10.366%; -9.072%]

scenario:samplingrules-average_match

  • 🟩 execution_time [-185.810µs; -181.575µs] or [-36.003%; -35.182%]

scenario:samplingrules-low_match

  • 🟩 execution_time [-348.943µs; -345.156µs] or [-67.548%; -66.815%]

@duncanpharvey duncanpharvey marked this pull request as ready for review April 28, 2025 14:32
@duncanpharvey duncanpharvey requested review from a team as code owners April 28, 2025 14:32
Copy link
Contributor

@hghotra hghotra left a comment

Choose a reason for hiding this comment

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

@duncanpharvey duncanpharvey merged commit bc56c53 into main May 1, 2025
344 of 345 checks passed
@duncanpharvey duncanpharvey deleted the duncan-harvey/azure-functions-async branch May 1, 2025 15:50
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.

3 participants