Skip to content

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

Merged
adinauer merged 3 commits into
mainfrom
fix/skip-preformatted-log-messages
Nov 23, 2026
Merged

adinauer merged 3 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

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit b972da0.

Main concerns: reach, public contract, 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

@adinauer
adinauer marked this pull request as ready for review November 23, 2026 10:26
@adinauer
adinauer requested a review from a team as a code owner November 23, 2026 10:26
@adinauer
adinauer requested review from 0xadam-brown and romtsn and removed request for a team November 23, 2026 10:26
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026

@runningcode runningcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@adinauer
adinauer merged commit 346fffa into main Nov 23, 2026
51 checks passed
@adinauer
adinauer deleted the fix/skip-preformatted-log-messages branch November 23, 2026 10:49
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

2 participants