Skip to content

feat: add identity attributes to OTLP logs - #308

Merged
LucasAlvesSoares merged 10 commits into
mainfrom
logging-attributes
Sep 4, 2026
Merged

feat: add identity attributes to OTLP logs#308
LucasAlvesSoares merged 10 commits into
mainfrom
logging-attributes

Conversation

@LucasAlvesSoares

Copy link
Copy Markdown
Contributor

Description

Enriches OTel log records with sap.tenancy.tenant_id and user.id

A new IdentityLogFilter (in core/telemetry/log_filters/identity.py) is installed on the LoggingHandler created by setup_log_provider().

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 the new and updated test suites:
    pytest tests/core/unit/telemetry/log_filters/test_identity.py
    pytest tests/core/unit/telemetry/test_provider.py
    
  2. In a Starlette/FastAPI app wired with auto_instrument() and StarletteIASTelemetryMiddleware, send a request with a valid IAS Bearer token and confirm that exported OTel log records carry sap.tenancy.tenant_id and user.id matching the JWT claims.
  3. Confirm that log records emitted outside a request context (e.g. at startup) do not carry these attributes.

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

Additional Notes

The filter is intentionally kept out of _provider.py and placed in log_filters/identity.py, mirroring the span_processors/ layout. Adding a new log filter in future requires only a new file in that folder and one import.

@LucasAlvesSoares
LucasAlvesSoares marked this pull request as ready for review September 4, 2026 17:39
@LucasAlvesSoares
LucasAlvesSoares requested a review from a team as a code owner September 4, 2026 17:39
Comment thread src/sap_cloud_sdk/core/telemetry/_provider.py
# Conflicts:
#	pyproject.toml
#	uv.lock
jeanscherf
jeanscherf previously approved these changes Sep 4, 2026

@jeanscherf jeanscherf left a comment

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.

LGTM.
Added one comment.

Also maybe it's worth updating the telemetry user-guide in the logging part. That we now inject these attribs as well.

@LucasAlvesSoares
LucasAlvesSoares merged commit ad3f911 into main Sep 4, 2026
11 checks passed
@LucasAlvesSoares
LucasAlvesSoares deleted the logging-attributes branch September 4, 2026 20:16
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