Skip to content

Commit 1f8c272

Browse files
fix(tracer): add extra service names for all spans [backport 3.10] (#13943)
Backport ab14f5c from #13922 to 3.10. Add extra service names for all finished spans. From a suggestion of @brettlangdon APPSEC-58108 ## Checklist - [x] 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](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] 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](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) 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](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: brettlangdon <brett.langdon@datadoghq.com>
1 parent 68d1e96 commit 1f8c272

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

ddtrace/_trace/processor/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ def on_span_finish(self, span: Span) -> None:
394394
log.error("error applying processor %r", tp, exc_info=True)
395395

396396
self._queue_span_count_metrics("spans_finished", "integration_name")
397+
if spans is not None:
398+
for span in spans:
399+
if span.service:
400+
# report extra service name as it may have been set after the span creation by the customer
401+
config._add_extra_service(span.service)
397402
self.writer.write(spans)
398403
return
399404

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Tracer: This fix resolves an issue where programmatically set span services names would not get reported to Remote Configuration.

tests/internal/service_name/test_extra_services_names.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,28 @@ def test_config_extra_service_names_rc_disabled(run_python_code_in_subprocess):
8585
env["DD_REMOTE_CONFIGURATION_ENABLED"] = "false"
8686
stdout, stderr, status, _ = run_python_code_in_subprocess(code, env=env)
8787
assert status == 0, (stdout, stderr, status)
88+
89+
90+
def test_config_extra_service_names_customer_changes(run_python_code_in_subprocess):
91+
code = """
92+
import ddtrace.auto
93+
import ddtrace
94+
import re
95+
import os
96+
import sys
97+
import time
98+
99+
with ddtrace.tracer.trace("test") as parent:
100+
parent.service = "parent_service"
101+
with ddtrace.tracer.trace("child") as child:
102+
child.service = "child_service"
103+
extra_services = ddtrace.config._get_extra_services()
104+
# collecting extra services in all spans, including the parent and child
105+
assert "parent_service" in extra_services
106+
assert "child_service" in extra_services
107+
"""
108+
109+
env = os.environ.copy()
110+
env["DD_REMOTE_CONFIGURATION_ENABLED"] = "true"
111+
stdout, stderr, status, _ = run_python_code_in_subprocess(code, env=env)
112+
assert status == 0, (stdout, stderr, status)

0 commit comments

Comments
 (0)