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
26 changes: 19 additions & 7 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 @@ -185,9 +186,18 @@ def create(
if not attributes:
attributes = {}

resource = get_aggregated_resources(_build_resource_detectors(), _DEFAULT_RESOURCE).merge(
Resource(attributes, schema_url)
)
if schema_url:
# When user provides schema_url, use empty schema URL for detectors to avoid conflicts
# The user's schema_url will be set on the final resource
resource = get_aggregated_resources(_build_resource_detectors(), _DEFAULT_RESOURCE).merge(
Resource(attributes, "")
)
resource = Resource(resource.attributes, schema_url)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like the correct behavior to me and it mostly defeats the purpose of a user populating schema_url in the first place.

else:
# When user doesn't provide schema_url, let detectors use their normal schema URLs
resource = get_aggregated_resources(_build_resource_detectors(), _DEFAULT_RESOURCE).merge(
Resource(attributes, "")
)

if not resource.attributes.get(SERVICE_NAME, None):
default_service_name = "unknown_service"
Expand Down Expand Up @@ -411,7 +421,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 @@ -494,7 +504,8 @@ def detect(self) -> "Resource":
{
OS_TYPE: os_type,
OS_VERSION: os_version,
}
},
Schemas.V1_44_0.value,
)


Expand All @@ -508,7 +519,8 @@ def detect(self) -> "Resource":
{
HOST_NAME: socket.gethostname(),
HOST_ARCH: platform.machine(),
}
},
Schemas.V1_44_0.value,
)


Expand Down Expand Up @@ -541,7 +553,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
Loading