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
5 changes: 5 additions & 0 deletions src/sap_cloud_sdk/core/auditlog_ng/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
from sap_cloud_sdk.core.auditlog_ng.exceptions import ValidationError
from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics
from sap_cloud_sdk.core.telemetry.config import ENV_OTLP_PROTOCOL
from sap_cloud_sdk.core.telemetry.constants import (
ATTR_SAP_QOS_CLASS,
QOS_CLASS_AT_LEAST_ONCE,
)
from sap_cloud_sdk.core.runtime_context import get_context
from sap_cloud_sdk.core.runtime_context.providers import APP_TENANT_ID, USER_ID
from sap_cloud_sdk.ias._context import get_auth_context
Expand Down Expand Up @@ -249,6 +253,7 @@ def send(
"cloudevents.event_id": event_id,
"sap.tenancy.tenant_id": tenant_id,
"sap.auditlogging.mime_type": mime_type,
ATTR_SAP_QOS_CLASS: QOS_CLASS_AT_LEAST_ONCE,
},
)

Expand Down
3 changes: 3 additions & 0 deletions src/sap_cloud_sdk/core/auditlog_ng/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ print(f"Sent event with ID: {event_id}")
event_id = client.send_json(event)
```

> **Note:** Every emitted LogRecord carries a fixed `sap.qos.class` attribute set to
> `at_least_once`. The value is always set by the SDK and is not configurable.

### Close the Client

Always close the client when the agent shuts down to flush pending events:
Expand Down
4 changes: 4 additions & 0 deletions src/sap_cloud_sdk/core/telemetry/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
ATTR_SAP_SDK_VERSION = "sap.cloud_sdk.version"
ATTR_SAP_SOLUTION_AREA = "sap.solution_area"

# Attribute keys - SAP QoS (quality of service)
ATTR_SAP_QOS_CLASS = "sap.qos.class"
QOS_CLASS_AT_LEAST_ONCE = "at_least_once"

# Attribute keys - MLflow
ATTR_MLFLOW_EXPERIMENT_ID = "mlflow.experiment_id"

Expand Down
11 changes: 10 additions & 1 deletion tests/core/unit/auditlog_ng/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

import pytest

from sap_cloud_sdk.core.auditlog_ng.client import AuditClient, _fill_common_from_auth_context
from sap_cloud_sdk.core.auditlog_ng.client import (
AuditClient,
_fill_common_from_auth_context,
)
from sap_cloud_sdk.core.auditlog_ng.config import AuditLogNGConfig, SCHEMA_URL
from sap_cloud_sdk.core.auditlog_ng.exceptions import ValidationError
from sap_cloud_sdk.core.auditlog_ng.gen.sap.auditlog.auditevent.v2 import auditevent_pb2 as pb
from sap_cloud_sdk.core.telemetry import Module, Operation
from sap_cloud_sdk.core.telemetry.constants import (
ATTR_SAP_QOS_CLASS,
QOS_CLASS_AT_LEAST_ONCE,
)
from sap_cloud_sdk.ias._context import set_auth_context


Expand Down Expand Up @@ -177,6 +184,7 @@ def test_send_binary_success(self):
== "application/protobuf"
)
assert kwargs["attributes"]["sap.tenancy.tenant_id"] == "tenant-123"
assert kwargs["attributes"][ATTR_SAP_QOS_CLASS] == QOS_CLASS_AT_LEAST_ONCE
assert "cloudevents.event_id" in kwargs["attributes"]
finally:
patcher.stop()
Expand All @@ -194,6 +202,7 @@ def test_send_json_success(self):
assert (
kwargs["attributes"]["sap.auditlogging.mime_type"] == "application/json"
)
assert kwargs["attributes"][ATTR_SAP_QOS_CLASS] == QOS_CLASS_AT_LEAST_ONCE
assert isinstance(kwargs["body"], str)
finally:
patcher.stop()
Expand Down
Loading