|
11 | 11 | from sap_cloud_sdk.core.telemetry.constants import ( |
12 | 12 | ATTR_MLFLOW_EXPERIMENT_ID, |
13 | 13 | ATTR_SAP_SOLUTION_AREA, |
| 14 | + ATTR_SAP_ORD_ID, |
14 | 15 | ) |
15 | 16 |
|
16 | 17 |
|
@@ -233,3 +234,35 @@ def test_solution_area_key_always_present(self): |
233 | 234 | attrs = create_resource_attributes_from_env() |
234 | 235 |
|
235 | 236 | assert "sap.solution_area" in attrs |
| 237 | + |
| 238 | + def test_ord_id_omitted_when_unset(self): |
| 239 | + """sap.ord.id is omitted entirely when ORD_DOCUMENT_ID is unset.""" |
| 240 | + with patch.dict('os.environ', {}, clear=True): |
| 241 | + attrs = create_resource_attributes_from_env() |
| 242 | + |
| 243 | + assert ATTR_SAP_ORD_ID not in attrs |
| 244 | + |
| 245 | + def test_ord_id_omitted_when_empty(self): |
| 246 | + """sap.ord.id is omitted when ORD_DOCUMENT_ID is an empty string.""" |
| 247 | + with patch.dict('os.environ', {'ORD_DOCUMENT_ID': ''}, clear=True): |
| 248 | + attrs = create_resource_attributes_from_env() |
| 249 | + |
| 250 | + assert ATTR_SAP_ORD_ID not in attrs |
| 251 | + |
| 252 | + def test_ord_id_read_from_env(self): |
| 253 | + """sap.ord.id resource attribute is read from ORD_DOCUMENT_ID.""" |
| 254 | + with patch.dict('os.environ', {'ORD_DOCUMENT_ID': 'sap.foo:ord-doc:v1'}, clear=True): |
| 255 | + attrs = create_resource_attributes_from_env() |
| 256 | + |
| 257 | + assert attrs[ATTR_SAP_ORD_ID] == "sap.foo:ord-doc:v1" |
| 258 | + |
| 259 | + def test_ord_id_independent_of_other_attributes(self): |
| 260 | + """sap.ord.id is populated independently from other optional attributes.""" |
| 261 | + with patch.dict('os.environ', { |
| 262 | + 'ORD_DOCUMENT_ID': 'my-ord-id', |
| 263 | + 'MLFLOW_EXPERIMENT_ID': 'exp-99', |
| 264 | + }, clear=True): |
| 265 | + attrs = create_resource_attributes_from_env() |
| 266 | + |
| 267 | + assert attrs[ATTR_SAP_ORD_ID] == "my-ord-id" |
| 268 | + assert attrs[ATTR_MLFLOW_EXPERIMENT_ID] == "exp-99" |
0 commit comments