Skip to content

fix(logging): Avoid formatting preformatted log messages - #6737

Draft
adinauer wants to merge 2 commits into
mainfrom
fix/skip-preformatted-log-messages
Draft

adinauer wants to merge 2 commits into
mainfrom
fix/skip-preformatted-log-messages

Conversation

@adinauer

Copy link
Copy Markdown
Member

📜 Description

Add a messageAlreadyFormatted option to SentryLogParameters. Logback, Log4j2, and JUL set it when forwarding messages they have already formatted, so the Sentry logger preserves the message body instead of applying String.format again.

Original message arguments are still passed through and recorded as structured sentry.message.parameter.* attributes.

💡 Motivation and Context

Logging integrations currently pass both the framework-formatted message and its original arguments to the Sentry Logs API. The API interprets the formatted message as a new Java format string, allowing percent sequences introduced by argument values to be processed during a second formatting pass. Large field widths can corrupt the message or exhaust the heap.

Resolves #6715
Refs JAVA-849

💚 How did you test it?

Added regression coverage for the core logger and the Logback, Log4j2, and JUL integrations using an argument containing %2010B.

Ran:

  • make format api
  • ./gradlew ':sentry:test' --tests='*ScopesTest*' ':sentry-logback:test' --tests='*SentryAppenderTest*' ':sentry-log4j2:test' ':sentry-jul:test' --tests='*SentryHandlerTest*'

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

None.

Let logging integrations mark message bodies as already formatted while preserving their original arguments as structured log attributes. This prevents percent sequences from user input from being interpreted during a second formatting pass.

Fixes #6715
@linear-code

linear-code Bot commented Nov 23, 2026

Copy link
Copy Markdown

JAVA-849

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 529294c.

Main concerns: public contract, reach, data sent to Sentry.

Rules that block low also fired:

  • R4: a public API record changed: sentry/api/sentry.api

This label is a hint for reviewers, not an approval.

@sentry

sentry Bot commented Nov 23, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.65.0 (1) release

⚙️ sentry-android Build Distribution Settings

This branch has not been deployed

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logback integrations run already-formatted log messages through String.format again: a % in a log argument can cause OutOfMemoryError

1 participant