Skip to content

Commit 1783bb5

Browse files
committed
test: cover auditlog ng factory error telemetry
1 parent 99c9198 commit 1783bb5

3 files changed

Lines changed: 53 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
## [0.20.2] - 2026-05-26
4+
5+
### Fixed
6+
7+
- Record ALS v3 (`auditlog_ng`) capability telemetry when `AuditClient` is
8+
initialized, including direct `AuditClient(config)` construction. The
9+
`send()` and `send_json()` APIs remain uninstrumented so the metric continues
10+
to represent client initialization rather than audit event volume.

src/sap_cloud_sdk/core/auditlog_ng/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ def create_client(
104104
compression=compression,
105105
schema_url=schema_url,
106106
)
107-
except (ValueError, ValidationError):
108-
record_error_metric(
109-
Module.AUDITLOG_NG,
110-
_telemetry_source,
111-
Operation.AUDITLOG_CREATE_CLIENT,
112-
)
113-
raise
114107
except Exception:
115108
record_error_metric(
116109
Module.AUDITLOG_NG,

tests/core/unit/auditlog_ng/unit/test_create_client.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,34 @@ def test_create_client_missing_endpoint_raises(self):
4949
with pytest.raises(ValueError, match="endpoint, deployment_id, and namespace are required"):
5050
create_client(deployment_id="dep-1", namespace="ns-1")
5151

52-
def test_create_client_missing_endpoint_records_error_metric(self):
52+
@pytest.mark.parametrize(
53+
("kwargs", "match"),
54+
[
55+
(
56+
{"deployment_id": "dep-1", "namespace": "ns-1"},
57+
"endpoint, deployment_id, and namespace are required",
58+
),
59+
(
60+
{
61+
"endpoint": "localhost:4317",
62+
"deployment_id": "bad value",
63+
"namespace": "ns-1",
64+
},
65+
"deployment_id",
66+
),
67+
],
68+
)
69+
def test_create_client_config_errors_record_error_metric(self, kwargs, match):
5370
with patch(
5471
"sap_cloud_sdk.core.auditlog_ng.record_error_metric"
5572
) as mock_error_metric:
5673
with pytest.raises(
5774
ValueError,
58-
match="endpoint, deployment_id, and namespace are required",
75+
match=match,
5976
):
6077
create_client(
61-
deployment_id="dep-1",
62-
namespace="ns-1",
6378
_telemetry_source=Module.DMS,
79+
**kwargs,
6480
)
6581

6682
mock_error_metric.assert_called_once_with(
@@ -96,13 +112,30 @@ def test_create_client_unexpected_exception_wraps_in_client_creation_error(
96112
):
97113
mock_provider_cls.side_effect = RuntimeError("Unexpected failure")
98114

99-
with pytest.raises(ClientCreationError, match="Failed to create audit log NG client"):
100-
create_client(
101-
endpoint="localhost:4317",
102-
deployment_id="dep-1",
103-
namespace="ns-1",
104-
insecure=True,
115+
with patch(
116+
"sap_cloud_sdk.core.telemetry.metrics_decorator.record_error_metric"
117+
) as mock_error_metric:
118+
with patch(
119+
"sap_cloud_sdk.core.telemetry.metrics_decorator.record_request_metric"
120+
) as mock_request_metric:
121+
with pytest.raises(
122+
ClientCreationError, match="Failed to create audit log NG client"
123+
):
124+
create_client(
125+
endpoint="localhost:4317",
126+
deployment_id="dep-1",
127+
namespace="ns-1",
128+
insecure=True,
129+
_telemetry_source=Module.DMS,
130+
)
131+
132+
mock_error_metric.assert_called_once_with(
133+
Module.AUDITLOG_NG,
134+
Module.DMS,
135+
Operation.AUDITLOG_CREATE_CLIENT,
136+
False,
105137
)
138+
mock_request_metric.assert_not_called()
106139

107140
@patch("sap_cloud_sdk.core.auditlog_ng.client._create_log_exporter")
108141
@patch("sap_cloud_sdk.core.auditlog_ng.client.LoggerProvider")

0 commit comments

Comments
 (0)