Skip to content

fix: record auditlog ng telemetry on client initialization#139

Open
tiagoek wants to merge 3 commits into
mainfrom
fix-auditlog-ng-telemetry
Open

fix: record auditlog ng telemetry on client initialization#139
tiagoek wants to merge 3 commits into
mainfrom
fix-auditlog-ng-telemetry

Conversation

@tiagoek
Copy link
Copy Markdown
Contributor

@tiagoek tiagoek commented May 26, 2026

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

Description

Moves the ALS v3 (auditlog_ng) AUDITLOG_CREATE_CLIENT capability metric from the public factory wrapper to the shared AuditClient initialization path. This keeps the signal as client/capability initialization rather than audit-event volume, while ensuring direct AuditClient(config) construction emits the same SDK usage telemetry as create_client(config=...).

The factory still records error metrics for validation/configuration failures that happen before AuditClient can be initialized, preserving the previous error telemetry behavior. The package version is bumped to 0.20.2.

Related Issue

Internal tracking: AFSDK-3392

Type of Change

Please check the relevant option:

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

  1. Run focused telemetry and auditlog NG tests:
    uv run pytest tests/core/unit/test_version.py tests/core/unit/auditlog_ng/unit/test_create_client.py tests/core/unit/auditlog_ng/unit/test_client.py tests/core/unit/telemetry/test_metrics_decorator.py -q
  2. Run non-integration unit tests:
    uv run pytest tests -m 'not integration' -q
  3. Run lint/type/build checks:
    uv run ruff check pyproject.toml src/sap_cloud_sdk/core/auditlog_ng/__init__.py src/sap_cloud_sdk/core/auditlog_ng/client.py src/sap_cloud_sdk/core/telemetry/metrics_decorator.py tests/core/unit/auditlog_ng/unit/test_create_client.py tests/core/unit/auditlog_ng/unit/test_client.py tests/core/unit/telemetry/test_metrics_decorator.py
    uv run ty check
    uv build
  4. Run integration checks with configured service bindings:
    uv run pytest tests/core/integration/auditlog -q
    uv run pytest tests -m integration --ignore=tests/destination/integration -q

Expected result: direct AuditClient(config) and factory-created clients both record exactly one auditlog_ng/create_client capability metric on successful initialization, without instrumenting send() or send_json().

Checklist

Before submitting your PR, please review and check the following:

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Breaking Changes

None.

Additional Notes

send() and send_json() remain uninstrumented intentionally. The dashboard signal should represent ALS v3 capability/client initialization, not audit event volume.

Local verification performed:

  • 53 passed for focused version/auditlog NG/telemetry tests.
  • 2098 passed, 125 deselected for non-integration tests.
  • 21 passed for AuditLog integration tests with configured bindings.
  • 65 passed, 31 skipped for integration tests excluding Destination.
  • uv run ty check completed with only pre-existing DMS integration warnings.
  • uv build produced sap_cloud_sdk-0.20.2 sdist and wheel.

Full integration was also executed; remaining failures were limited to known Destination integration scenarios and are unrelated to ALS v3 telemetry.

@tiagoek tiagoek marked this pull request as ready for review May 26, 2026 19:28
@tiagoek tiagoek requested a review from a team as a code owner May 26, 2026 19:28
Comment thread CHANGELOG.md Outdated
Comment on lines +1 to +10
# Changelog

## [0.20.2] - 2026-05-26

### Fixed

- Record ALS v3 (`auditlog_ng`) capability telemetry when `AuditClient` is
initialized, including direct `AuditClient(config)` construction. The
`send()` and `send_json()` APIs remain uninstrumented so the metric continues
to represent client initialization rather than audit event volume.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we're not doing this file anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed CHANGELOG.md from this PR.

)

from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics
from sap_cloud_sdk.core.telemetry import Module, Operation, record_error_metric
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice fix overall.

One small thing: record_error_metric is an internal telemetry helper, and importing it without an underscore alias means it ends up in this module's public namespace, reachable as sap_cloud_sdk.core.auditlog_ng.record_error_metric even if it is not in __all__. A private alias would keep that intent clear:

from sap_cloud_sdk.core.telemetry import Module, Operation, record_error_metric as _record_error_metric
Then update the call site below to match:

_record_error_metric(
    Module.AUDITLOG_NG,
    _telemetry_source,
    Operation.AUDITLOG_CREATE_CLIENT,
)

wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed by importing record_error_metric as _record_error_metric and updating the test patch target accordingly.

Copy link
Copy Markdown
Member

@jeanscherf jeanscherf left a comment

Choose a reason for hiding this comment

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

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants