Skip to content
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "sap-cloud-sdk"
version = "0.34.0"
version = "0.35.0"
description = "SAP Cloud SDK for Python"
readme = "README.md"
license = "Apache-2.0"
Expand Down
17 changes: 17 additions & 0 deletions src/sap_cloud_sdk/core/telemetry/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ATTR_SAP_SOLUTION_AREA,
ATTR_MLFLOW_EXPERIMENT_ID,
ATTR_SAP_ORD_ID,
ATTR_SAP_SERVICE_DISPLAY_NAME,
SDK_NAME,
)

Expand All @@ -35,6 +36,7 @@
ENV_SOLUTION_AREA = "SAP_SOLUTION_AREA"
ENV_MLFLOW_EXPERIMENT_ID = "MLFLOW_EXPERIMENT_ID"
ENV_ORD_DOCUMENT_ID = "ORD_DOCUMENT_ID"
ENV_SERVICE_DISPLAY_NAME = "SAP_SERVICE_DISPLAY_NAME"

# OTEL environment variable keys
ENV_OTLP_ENDPOINT = "OTEL_EXPORTER_OTLP_ENDPOINT"
Expand Down Expand Up @@ -110,6 +112,16 @@ def _get_ord_id() -> Optional[str]:
return value if value else None


def _get_service_display_name() -> Optional[str]:
"""Get service display name from environment.

Returns:
Value of SAP_SERVICE_DISPLAY_NAME, or None if the env var is missing or empty.
"""
value = os.getenv(ENV_SERVICE_DISPLAY_NAME)
return value if value else None


def create_resource_attributes_from_env() -> dict:
"""Create OpenTelemetry Resource with SDK attributes.

Expand All @@ -131,6 +143,7 @@ def create_resource_attributes_from_env() -> dict:
- sap.solution_area (from SAP_SOLUTION_AREA, defaults to "unknown")
- mlflow.experiment_id (from MLFLOW_EXPERIMENT_ID, omitted when unset or empty)
- sap.ord.id (from ORD_DOCUMENT_ID, omitted when unset or empty)
- sap.service.display_name (from SAP_SERVICE_DISPLAY_NAME, omitted when unset or empty)
"""

attributes = {
Expand All @@ -155,6 +168,10 @@ def create_resource_attributes_from_env() -> dict:
if ord_id is not None:
attributes[ATTR_SAP_ORD_ID] = ord_id

service_display_name = _get_service_display_name()
if service_display_name is not None:
attributes[ATTR_SAP_SERVICE_DISPLAY_NAME] = service_display_name

return attributes


Expand Down
3 changes: 3 additions & 0 deletions src/sap_cloud_sdk/core/telemetry/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
# Attribute keys - ORD
ATTR_SAP_ORD_ID = "sap.ord.id"

# Attribute keys - Service display name
ATTR_SAP_SERVICE_DISPLAY_NAME = "sap.service.display_name"

# Attribute keys - SAP App Foundation specific
ATTR_CAPABILITY = "sap.cloud_sdk.capability"
ATTR_FUNCTIONALITY = "sap.cloud_sdk.functionality"
Expand Down
33 changes: 33 additions & 0 deletions tests/core/unit/telemetry/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ATTR_MLFLOW_EXPERIMENT_ID,
ATTR_SAP_SOLUTION_AREA,
ATTR_SAP_ORD_ID,
ATTR_SAP_SERVICE_DISPLAY_NAME,
)


Expand Down Expand Up @@ -266,3 +267,35 @@ def test_ord_id_independent_of_other_attributes(self):

assert attrs[ATTR_SAP_ORD_ID] == "my-ord-id"
assert attrs[ATTR_MLFLOW_EXPERIMENT_ID] == "exp-99"

def test_service_display_name_omitted_when_unset(self):
"""sap.service.display_name is omitted entirely when SAP_SERVICE_DISPLAY_NAME is unset."""
with patch.dict('os.environ', {}, clear=True):
attrs = create_resource_attributes_from_env()

assert ATTR_SAP_SERVICE_DISPLAY_NAME not in attrs

def test_service_display_name_omitted_when_empty(self):
"""sap.service.display_name is omitted when SAP_SERVICE_DISPLAY_NAME is an empty string."""
with patch.dict('os.environ', {'SAP_SERVICE_DISPLAY_NAME': ''}, clear=True):
attrs = create_resource_attributes_from_env()

assert ATTR_SAP_SERVICE_DISPLAY_NAME not in attrs

def test_service_display_name_read_from_env(self):
"""sap.service.display_name resource attribute is read from SAP_SERVICE_DISPLAY_NAME."""
with patch.dict('os.environ', {'SAP_SERVICE_DISPLAY_NAME': 'My Service'}, clear=True):
attrs = create_resource_attributes_from_env()

assert attrs[ATTR_SAP_SERVICE_DISPLAY_NAME] == "My Service"

def test_service_display_name_independent_of_other_attributes(self):
"""sap.service.display_name is populated independently from other optional attributes."""
with patch.dict('os.environ', {
'SAP_SERVICE_DISPLAY_NAME': 'My Service',
'ORD_DOCUMENT_ID': 'my-ord-id',
}, clear=True):
attrs = create_resource_attributes_from_env()

assert attrs[ATTR_SAP_SERVICE_DISPLAY_NAME] == "My Service"
assert attrs[ATTR_SAP_ORD_ID] == "my-ord-id"
8 changes: 6 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading