Skip to content

feat(azure_servicebus): add azure servicebus integration and function trigger distributed tracing #13691

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

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

Conversation

duncanpharvey
Copy link
Contributor

@duncanpharvey duncanpharvey commented Jun 17, 2025

This PR adds an integration for tracing the producer of the azure-servicebus package and adds support for distributed tracing for Azure Functions consuming the service bus messages.

Instrumentation details:

  • Both azure.servicebus and azure.servicebus.aio (async package) are patched
  • Methods patched
    • ServiceBusSender.send_messages
    • ServiceBusSender.schedule_messages
  • Trace context injected into application_properties of each service bus message passed to above methods
    • Handles single ServiceBusMessage or AmqpAnnotatedMessage in addition to a list of ServiceBusMessage or AmqpAnnotatedMessage
    • Will handle trace context propagation of ServiceBusMessageBatch in a future PR
  • Trace context extracted from application_properties in Azure Function service bus consumer
  • Azure Service Bus Producer span attributes
    • component: azure_servicebus
    • span.kind: producer
    • span.type: worker
    • operation: azure.servicebus.produce
    • `resource: <queue/topic name>
    • messaging.destination_kind - not set, instances of ServiceBusSender don't specify whether it is a queue or topic they are sending to
    • messaging.destination.name: <queue/topic name>
    • messaging.destination.system: servicebus
    • messaging.operation: send
    • network.destination.name: <fully qualified host name for Service Bus namespace>
    • network.destination.port - not set, no port specified on instances of ServiceBusSender

Additional Notes:

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

@duncanpharvey duncanpharvey requested review from a team as code owners June 17, 2025 15:02
@duncanpharvey duncanpharvey requested review from a team as code owners June 17, 2025 15:02
Copy link
Contributor

github-actions bot commented Jun 17, 2025

CODEOWNERS have been resolved as:

.riot/requirements/10f86d9.txt                                          @DataDog/apm-python
.riot/requirements/1170953.txt                                          @DataDog/apm-python
.riot/requirements/156842b.txt                                          @DataDog/apm-python
.riot/requirements/1670b58.txt                                          @DataDog/apm-python
.riot/requirements/16ae446.txt                                          @DataDog/apm-python
.riot/requirements/1826cd3.txt                                          @DataDog/apm-python
.riot/requirements/18a650f.txt                                          @DataDog/apm-python
.riot/requirements/1d35b33.txt                                          @DataDog/apm-python
.riot/requirements/1e1c2b7.txt                                          @DataDog/apm-python
.riot/requirements/3f34788.txt                                          @DataDog/apm-python
.riot/requirements/5b956b7.txt                                          @DataDog/apm-python
.riot/requirements/6c15ef8.txt                                          @DataDog/apm-python
.riot/requirements/803d32f.txt                                          @DataDog/apm-python
.riot/requirements/a1026b8.txt                                          @DataDog/apm-python
.riot/requirements/ade49fb.txt                                          @DataDog/apm-python
.riot/requirements/b43c003.txt                                          @DataDog/apm-python
ddtrace/contrib/_azure_servicebus.py                                    @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/azure_servicebus/patch.py                      @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/azure_servicebus/utils.py                      @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/ext/azure_servicebus.py                                         @DataDog/apm-core-python @DataDog/apm-idm-python
releasenotes/notes/feat-add-azure-servicebus-integration-4034143c46abe1c6.yaml  @DataDog/apm-python
tests/contrib/azure_servicebus/__init__.py                              @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/azure_servicebus/test_azure_servicebus_patch.py           @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/azure_servicebus/test_azure_servicebus_snapshot.py        @DataDog/apm-core-python @DataDog/apm-idm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_service_bus_distributed_tracing[disabled].json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_service_bus_distributed_tracing[enabled].json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_servicebus.test_azure_servicebus_snapshot.test_schedule_messages.json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_servicebus.test_azure_servicebus_snapshot.test_schedule_messages_async.json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_servicebus.test_azure_servicebus_snapshot.test_send_messages[default_config].json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_servicebus.test_azure_servicebus_snapshot.test_send_messages[distributed_tracing_disabled].json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_servicebus.test_azure_servicebus_snapshot.test_send_messages_async.json  @DataDog/apm-python
.gitlab/services.yml                                                    @DataDog/python-guild @DataDog/apm-core-python
ddtrace/_monkey.py                                                      @DataDog/apm-core-python
ddtrace/_trace/trace_handlers.py                                        @DataDog/apm-sdk-api-python
ddtrace/contrib/_azure_functions.py                                     @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/integration_registry/registry.yaml                      @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/azure_functions/patch.py                       @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/internal/constants.py                                           @DataDog/apm-core-python
ddtrace/settings/_config.py                                             @DataDog/apm-core-python
docker-compose.yml                                                      @DataDog/apm-core-python
riotfile.py                                                             @DataDog/apm-python
supported_versions_output.json                                          @DataDog/apm-core-python
supported_versions_table.csv                                            @DataDog/apm-core-python
tests/contrib/azure_functions/azure_function_app/function_app.py        @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/azure_functions/azure_function_app/local.settings.json    @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/azure_functions/test_azure_functions_patch.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
tests/contrib/patch.py                                                  @DataDog/apm-core-python @DataDog/apm-idm-python
tests/contrib/suitespec.yml                                             @DataDog/apm-core-python @DataDog/apm-idm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_http_get_distributed_tracing[disabled].json  @DataDog/apm-python
tests/snapshots/tests.contrib.azure_functions.test_azure_functions_snapshot.test_http_get_distributed_tracing[enabled].json  @DataDog/apm-python
.riot/requirements/1241599.txt                                          @DataDog/apm-python
.riot/requirements/1ac22db.txt                                          @DataDog/apm-python
.riot/requirements/9b11151.txt                                          @DataDog/apm-python
.riot/requirements/e7ef4bc.txt                                          @DataDog/apm-python

@duncanpharvey duncanpharvey changed the title feat(azure_servicebus): add azure servicebus integration and distributed tracing with azure function service bus triggers feat(azure_servicebus): add azure servicebus integration and function trigger distributed tracing Jun 17, 2025
Copy link
Contributor

github-actions bot commented Jun 17, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 277 ± 3 ms.

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

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

The difference is not statistically significant (z = 0.41).

Import time breakdown

The following import paths have appeared:

ddtrace.auto 0.325 ms (0.12%)
ddtrace.bootstrap.sitecustomize 0.325 ms (0.12%)
ddtrace._trace.trace_handlers 0.325 ms (0.12%)
ddtrace.ext.azure_servicebus 0.325 ms (0.12%)

The following import paths have grown:

ddtrace.auto 0.068 ms (0.02%)
ddtrace.bootstrap.sitecustomize 0.068 ms (0.02%)
ddtrace.contrib.internal.subprocess.constants 0.068 ms (0.02%)

The following import paths have shrunk:

ddtrace.auto 1.823 ms (0.66%)
ddtrace.bootstrap.sitecustomize 1.154 ms (0.42%)
ddtrace.bootstrap.preload 1.154 ms (0.42%)
ddtrace.internal.remoteconfig.client 0.616 ms (0.22%)
ddtrace 0.669 ms (0.24%)
ddtrace.internal._unpatched 0.028 ms (0.01%)
json 0.028 ms (0.01%)
json.decoder 0.028 ms (0.01%)
re 0.028 ms (0.01%)
enum 0.028 ms (0.01%)
types 0.028 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 17, 2025

Benchmarks

Benchmark execution time: 2025-06-23 22:25:31

Comparing candidate commit 7a55f4d in PR branch duncan-harvey/azure-servicebus-integration with baseline commit 5592908 in branch main.

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

scenario:iastaspects-upper_aspect

  • 🟥 execution_time [+189.327ns; +233.352ns] or [+8.383%; +10.332%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+521.334ns; +708.327ns] or [+12.281%; +16.686%]

scenario:iastaspectsospath-ospathjoin_aspect

  • 🟥 execution_time [+720.083ns; +918.272ns] or [+11.761%; +14.998%]

Copy link
Collaborator

@emmettbutler emmettbutler left a comment

Choose a reason for hiding this comment

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

Very nice use of ddtrace.internal.core!

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