Repository navigation
fix(audit-log): Correct sentry_app key in internal integration events - #125182
Merged
Merged
Conversation
armenzg
reviewed
Sep 22, 2026
armenzg
approved these changes
Sep 22, 2026
scttcper
added a commit
that referenced
this pull request
Nov 16, 2026
…1042) Token created/revoked audit log entries written before #125182 stored the app under `sentry_app_slug` instead of `sentry_app`, so they raise a KeyError and show a blank note whenever an org's audit log is loaded. Those old rows now render with the slug. Also drops a stray `.format()` on the disabled internal integration note that would raise on a name with braces in it. fixes SENTRY-42CT Co-authored-by: Claude Fable 5.2 <[email protected]>
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.
This PR addresses the
KeyError: 'sentry_app'occurring when rendering audit log entries for internal integration token events.Problem:
The audit log template for
INTERNAL_INTEGRATION_ADD_TOKENandINTERNAL_INTEGRATION_REMOVE_TOKENevents expected a{sentry_app}placeholder. However, thecreate_audit_entrycalls insentry_internal_app_tokens.pyandsentry_internal_app_token_details.pywere supplying"sentry_app_slug": sentry_app.slugin theirdatadictionaries, leading to aKeyErrorwhenstr.format()was called.Initial Attempt & Iteration:
An initial attempt included hardening
AuditLogEvent.render()insrc/sentry/audit_log/manager.pyto usestr.format_map(collections.defaultdict(str, ...))to preventKeyErrorfor missing keys. While this provided defense-in-depth, it was found to conflict with an existing test (test_invalid_templateintests/sentry/api/serializers/test_auditlogentry.py) which specifically asserts that aKeyErroris caught by theAuditLogEntrySerializerand results in an empty note. Theformat_mapchange bypassed thisKeyErrorcatch, causing the test to fail.Final Solution:
The
manager.pychange was reverted to its originalstr.format(**audit_log_entry.data)behavior. The core fix, which is sufficient, is to correct the key name at the call sites:src/sentry/sentry_apps/api/endpoints/sentry_internal_app_tokens.py: Changed"sentry_app_slug": sentry_app.slugto"sentry_app": sentry_app.nameforINTERNAL_INTEGRATION_ADD_TOKENevents.src/sentry/sentry_apps/api/endpoints/sentry_internal_app_token_details.py: Changed"sentry_app_slug": sentry_app.slugto"sentry_app": sentry_app.nameforINTERNAL_INTEGRATION_REMOVE_TOKENevents.This aligns the data provided with the template's expectation, resolving the
KeyError. TheAuditLogEntrySerializer's existingKeyErrorhandling remains as a robust fallback for any future template/data mismatches.Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
Fixes SENTRY-42CT
@sentry <feedback>: Autofix iterates on these changes@sentry stop iterating: Autofix stops iterating on this runThis PR was automatically generated by Sentry. You can adjust this setting at any time.