Skip to content

Commit 4114a84

Browse files
fix: use unique unnamed service name value [backport 2.0] (#7441)
Backport f86ac69 from #7414 to 2.0. In some places, a literal string was being used when a service name is not provided via the configuration interface. This value however differed from the DEFAULT_SERVICE_NAME constant, resulting in multiple service names being used in different parts of the library. This change ensures that only one default service name is used across the library. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent d68fdad commit 4114a84

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

ddtrace/internal/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
W3C_TRACESTATE_SAMPLING_PRIORITY_KEY = "s"
2424
DEFAULT_SAMPLING_RATE_LIMIT = 100
2525
SAMPLING_DECISION_TRACE_TAG_KEY = "_dd.p.dm"
26-
DEFAULT_SERVICE_NAME = "unnamed_python_service"
26+
DEFAULT_SERVICE_NAME = "unnamed-python-service"
2727
# Used to set the name of an integration on a span
2828
COMPONENT = "component"
2929
HIGHER_ORDER_TRACE_ID_BITS = "_dd.p.tid"

ddtrace/internal/datastreams/processor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import ddtrace
2323
from ddtrace import config
2424
from ddtrace.internal.atexit import register_on_exit_signal
25+
from ddtrace.internal.constants import DEFAULT_SERVICE_NAME
2526
from ddtrace.internal.utils.retry import fibonacci_backoff_with_jitter
2627

2728
from .._encoding import packb
@@ -128,7 +129,7 @@ def __init__(self, agent_url, interval=None, timeout=1.0, retry_attempts=3):
128129
"Content-Encoding": "gzip",
129130
} # type: Dict[str, str]
130131
self._hostname = six.ensure_text(get_hostname())
131-
self._service = six.ensure_text(config._get_service("unnamed-python-service"))
132+
self._service = six.ensure_text(config._get_service(DEFAULT_SERVICE_NAME))
132133
self._lock = Lock()
133134
self._current_context = threading.local()
134135
self._enabled = True
@@ -361,7 +362,7 @@ def __init__(self, processor, hash_value, pathway_start_sec, current_edge_start_
361362
self.pathway_start_sec = pathway_start_sec
362363
self.current_edge_start_sec = current_edge_start_sec
363364
self.hash = hash_value
364-
self.service = six.ensure_text(config._get_service("unnamed-python-service"))
365+
self.service = six.ensure_text(config._get_service(DEFAULT_SERVICE_NAME))
365366
self.env = six.ensure_text(config.env or "none")
366367
# loop detection logic
367368
self.previous_direction = ""

ddtrace/internal/schema/span_attribute_schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from enum import Enum
22

3+
from ddtrace.internal.constants import DEFAULT_SERVICE_NAME
4+
35

46
class SpanDirection(Enum):
57
INBOUND = "inbound"
@@ -110,4 +112,4 @@ def url_operation_v1(v0_operation, protocol=None, direction=None):
110112
}
111113

112114

113-
_DEFAULT_SPAN_SERVICE_NAMES = {"v0": None, "v1": "unnamed-python-service"}
115+
_DEFAULT_SPAN_SERVICE_NAMES = {"v0": None, "v1": DEFAULT_SERVICE_NAME}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Use a unique default service name across all the products provided by the
5+
library when one is not given via the configuration interface.

tests/internal/service_name/test_imports.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def test_service_names_import_and_v0():
5050
parametrize={"DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED": ["False", "True"]},
5151
)
5252
def test_service_name_imports_v1():
53+
from ddtrace.internal.constants import DEFAULT_SERVICE_NAME
5354
from ddtrace.internal.schema import DEFAULT_SPAN_SERVICE_NAME
5455
from ddtrace.internal.schema import schematize_cache_operation
5556
from ddtrace.internal.schema import schematize_cloud_api_operation
@@ -62,7 +63,7 @@ def test_service_name_imports_v1():
6263
from ddtrace.internal.schema.span_attribute_schema import service_name_v1
6364
from ddtrace.internal.schema.span_attribute_schema import url_operation_v1
6465

65-
assert DEFAULT_SPAN_SERVICE_NAME == "unnamed-python-service"
66+
assert DEFAULT_SPAN_SERVICE_NAME == DEFAULT_SERVICE_NAME
6667
assert schematize_service_name == service_name_v1
6768
assert schematize_database_operation == database_operation_v1
6869
assert schematize_cache_operation == cache_operation_v1
@@ -77,6 +78,7 @@ def test_service_name_import_with_client_service_names_enabled_v0():
7778
"""
7879
Service name parameters are flipped when DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED is True for v0
7980
"""
81+
from ddtrace.internal.constants import DEFAULT_SERVICE_NAME
8082
from ddtrace.internal.schema import DEFAULT_SPAN_SERVICE_NAME
8183
from ddtrace.internal.schema import schematize_cache_operation
8284
from ddtrace.internal.schema import schematize_cloud_api_operation
@@ -89,7 +91,7 @@ def test_service_name_import_with_client_service_names_enabled_v0():
8991
from ddtrace.internal.schema.span_attribute_schema import service_name_v1
9092
from ddtrace.internal.schema.span_attribute_schema import url_operation_v0
9193

92-
assert DEFAULT_SPAN_SERVICE_NAME == "unnamed-python-service"
94+
assert DEFAULT_SPAN_SERVICE_NAME == DEFAULT_SERVICE_NAME
9395
assert schematize_service_name == service_name_v1
9496
assert schematize_database_operation == database_operation_v0
9597
assert schematize_cache_operation == cache_operation_v0

tests/telemetry/test_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import ddtrace
99
from ddtrace.internal.compat import PY3
10+
from ddtrace.internal.constants import DEFAULT_SERVICE_NAME
1011
from ddtrace.internal.packages import get_distributions
1112
from ddtrace.internal.runtime.container import CGroupInfo
1213
from ddtrace.internal.telemetry.data import _format_version_info
@@ -27,7 +28,7 @@ def test_get_application():
2728
runtime_v = _format_version_info(sys.implementation.version)
2829

2930
expected_application = {
30-
"service_name": "unnamed_python_service",
31+
"service_name": DEFAULT_SERVICE_NAME,
3132
"service_version": "",
3233
"env": "",
3334
"language_name": "python",

0 commit comments

Comments
 (0)