Skip to content

fix(tracer): add extra service names for all spans [backport 3.10] #13943

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 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ddtrace/_trace/processor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ def on_span_finish(self, span: Span) -> None:
log.error("error applying processor %r", tp, exc_info=True)

self._queue_span_count_metrics("spans_finished", "integration_name")
if spans is not None:
for span in spans:
if span.service:
# report extra service name as it may have been set after the span creation by the customer
config._add_extra_service(span.service)
self.writer.write(spans)
return

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Tracer: This fix resolves an issue where programmatically set span services names would not get reported to Remote Configuration.
25 changes: 25 additions & 0 deletions tests/internal/service_name/test_extra_services_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,28 @@ def test_config_extra_service_names_rc_disabled(run_python_code_in_subprocess):
env["DD_REMOTE_CONFIGURATION_ENABLED"] = "false"
stdout, stderr, status, _ = run_python_code_in_subprocess(code, env=env)
assert status == 0, (stdout, stderr, status)


def test_config_extra_service_names_customer_changes(run_python_code_in_subprocess):
code = """
import ddtrace.auto
import ddtrace
import re
import os
import sys
import time

with ddtrace.tracer.trace("test") as parent:
parent.service = "parent_service"
with ddtrace.tracer.trace("child") as child:
child.service = "child_service"
extra_services = ddtrace.config._get_extra_services()
# collecting extra services in all spans, including the parent and child
assert "parent_service" in extra_services
assert "child_service" in extra_services
"""

env = os.environ.copy()
env["DD_REMOTE_CONFIGURATION_ENABLED"] = "true"
stdout, stderr, status, _ = run_python_code_in_subprocess(code, env=env)
assert status == 0, (stdout, stderr, status)
Loading