feat(auditlog_ng): auto-inject tenant and user from IAS request context#242
Merged
Conversation
…uest auth context When IAS claims are available in the current async context (set by StarletteIASTelemetryMiddleware), back-fill common.tenant_id from app_tid and common.user_initiator_id from user_uuid before validation and sending, so callers don't need to set these fields manually.
Per review feedback: accessing event.common triggers protobuf lazy creation so callers that never touched common still get it populated. Also sets common.timestamp to utcnow when the caller leaves it at zero.
tiagoek
marked this pull request as ready for review
July 22, 2026 14:18
…for _fill_common_from_auth_context
LucasAlvesSoares
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ias/_context.pywith aContextVar-backedset_auth_context/get_auth_contextto store IAS claims per async requestStarletteIASTelemetryMiddlewareto callset_auth_context(claims)on every request via a unified_parse_request()helperAuditClient.send()to auto-fillcommon.tenant_id(fromapp_tid) andcommon.user_initiator_id(fromuser_uuid) before protovalidate runs — only when not already set by the callerauditlog_ng/user-guide.mdTest plan
_fill_common_from_auth_contextfills empty fields from a mocked IAS contextsend()still raisesValidationErrorwhentenant_idis absent and no context is set