Skip to content

Commit 103ff08

Browse files
committed
move service.name default into base resource
Merges service.name=unknown_service into base before running detectors, so detectors (e.g. service) can override it. Previously it was added to config_attrs and merged last, which would have silently overridden any detector-provided service.name. Assisted-by: Claude Sonnet 4.6
1 parent 9cfdcce commit 103ff08

File tree

1 file changed

+4
-7
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/_configuration

1 file changed

+4
-7
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_resource.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ def create_resource(config: Optional[ResourceConfig]) -> Resource:
101101
A Resource with SDK defaults, optional detector attributes, and any
102102
config-specified attributes merged in priority order.
103103
"""
104-
base = _DEFAULT_RESOURCE
104+
# Spec requires service.name to always be present; detectors and explicit
105+
# config attributes can override this default.
106+
base = _DEFAULT_RESOURCE.merge(Resource({SERVICE_NAME: "unknown_service"}))
105107

106108
if config is None:
107-
service_resource = Resource({SERVICE_NAME: "unknown_service"})
108-
return base.merge(service_resource)
109+
return base
109110

110111
# attributes_list is lower priority; explicit attributes overwrite conflicts.
111112
config_attrs: dict[str, object] = {}
@@ -116,10 +117,6 @@ def create_resource(config: Optional[ResourceConfig]) -> Resource:
116117
for attr in config.attributes:
117118
config_attrs[attr.name] = _coerce_attribute_value(attr)
118119

119-
# Spec requires service.name to always be present.
120-
if SERVICE_NAME not in config_attrs:
121-
config_attrs[SERVICE_NAME] = "unknown_service"
122-
123120
schema_url = config.schema_url
124121

125122
# Run detectors only if detection_development is configured. Collect all

0 commit comments

Comments
 (0)