Skip to content
Open
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
17 changes: 13 additions & 4 deletions opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
__version__ as _OPENTELEMETRY_SDK_VERSION,
)
from opentelemetry.semconv.resource import ResourceAttributes
from opentelemetry.semconv.schemas import Schemas
from opentelemetry.util.types import AnyValue

psutil: ModuleType | None = None
Expand Down Expand Up @@ -205,6 +206,13 @@ def create(
if sys.executable:
default_service_name += f":{os.path.basename(sys.executable)}"
resource = resource.merge(Resource({SERVICE_NAME: default_service_name}, schema_url))

# If user explicitly provided a schema_url, it should take precedence
# over detector schema URLs. This follows the specification guidance
# that user-provided resource information has higher priority.
if schema_url:
resource = Resource(resource.attributes, schema_url)

return resource

@staticmethod
Expand Down Expand Up @@ -418,7 +426,7 @@ def detect(self) -> "Resource":
username = process.username()
resource_info[PROCESS_OWNER] = username

return Resource(resource_info) # type: ignore
return Resource(resource_info, Schemas.V1_44_0.value) # type: ignore


class OsResourceDetector(ResourceDetector):
Expand Down Expand Up @@ -501,7 +509,8 @@ def detect(self) -> "Resource":
{
OS_TYPE: os_type,
OS_VERSION: os_version,
}
},
Schemas.V1_44_0.value,
)


Expand Down Expand Up @@ -629,7 +638,7 @@ def detect(self) -> "Resource":
if self.raise_on_error:
raise

return Resource(resource_info)
return Resource(resource_info, Schemas.V1_44_0.value)


class ServiceInstanceIdResourceDetector(ResourceDetector):
Expand Down Expand Up @@ -661,7 +670,7 @@ def detect(self) -> "Resource":
_service_instance_id = str(uuid.uuid4())
_service_instance_id_pid = current_pid
instance_id = _service_instance_id
return Resource({SERVICE_INSTANCE_ID: instance_id})
return Resource({SERVICE_INSTANCE_ID: instance_id}, Schemas.V1_44_0.value)


def _build_resource_detectors() -> list["ResourceDetector"]:
Expand Down
Loading