Skip to content

feat(telemetry): decouple module/operation identifiers from enums#240

Draft
jeanscherf wants to merge 2 commits into
mainfrom
feat/decouple-telemetry-identifiers
Draft

feat(telemetry): decouple module/operation identifiers from enums#240
jeanscherf wants to merge 2 commits into
mainfrom
feat/decouple-telemetry-identifiers

Conversation

@jeanscherf

@jeanscherf jeanscherf commented Jul 21, 2026

Copy link
Copy Markdown
Member

Description

The record_metrics decorator and the underlying record_request_metric, record_error_metric, and default_attributes functions previously required Module and Operation enum values defined inside this package. This made it impossible for external packages to use the OSS telemetry infrastructure without adding entries to those enums via a PR to this repo.

This change relaxes the type constraints from Module / Operation enums to plain str throughout. Since Module and Operation already extend str, all existing callsites are unaffected — enum values continue to work exactly as before. External packages can now pass plain strings (e.g. @record_metrics("my_module", "my_operation")) and plug into the same OTel infrastructure without any changes here.

The isinstance(source_kwarg, Module) guard in the decorator is also relaxed to isinstance(source_kwarg, str) for the same reason.

Type of Change

  • 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. Use the decorator with plain strings from outside the package:
    from sap_cloud_sdk.core.telemetry import record_metrics
    
    class MyClient:
        @record_metrics("my_module", "my_operation")
        def my_method(self):
            ...
  2. Verify no type errors are raised and metrics are emitted normally when OTEL_EXPORTER_OTLP_ENDPOINT is set.
  3. Verify existing enum usage (Module.DESTINATION, Operation.GET_DESTINATION) continues to work unchanged.
  4. Run uv run pytest tests/core/unit/telemetry/test_metrics_decorator.py — all tests including the new TestRecordMetricsDecoratorPlainStrings class should pass.

Checklist

  • 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

Additional Notes

The Module and Operation enums remain the canonical, recommended way to call the API for OSS consumers — they are still exported and fully supported. This change only opens the contract so external packages are not forced to contribute to this repo to use the telemetry layer.

…fiers

Module and Operation enums are still fully supported, but record_metrics,
record_request_metric, record_error_metric, and default_attributes now
accept any str so external packages can plug into the telemetry layer
without needing entries in the OSS enums.
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.

1 participant