Skip to content

log4j spring boot 4 autoinstrumentation#5403

Open
lbloder wants to merge 10 commits into
mainfrom
feat/log4j-autoinstrumentation
Open

log4j spring boot 4 autoinstrumentation#5403
lbloder wants to merge 10 commits into
mainfrom
feat/log4j-autoinstrumentation

Conversation

@lbloder

@lbloder lbloder commented May 11, 2026

Copy link
Copy Markdown
Collaborator

📜 Description

💡 Motivation and Context

resolves: #5035

💚 How did you test it?

📝 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.

🔮 Next steps

@sentry

sentry Bot commented May 11, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 319.10 ms 377.16 ms 58.06 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
eb95ded 317.51 ms 369.08 ms 51.57 ms
2124a46 319.19 ms 415.04 ms 95.85 ms
c3ee041 310.64 ms 361.90 ms 51.26 ms
dcc6bbf 382.58 ms 462.13 ms 79.54 ms
7a19fee 315.46 ms 368.62 ms 53.16 ms
9054d65 330.94 ms 403.24 ms 72.30 ms
d500866 326.13 ms 378.70 ms 52.58 ms
ad8da22 365.86 ms 427.00 ms 61.14 ms
ed33deb 337.52 ms 484.06 ms 146.54 ms
d15471f 310.26 ms 377.04 ms 66.78 ms

App size

Revision Plain With Sentry Diff
eb95ded 0 B 0 B 0 B
2124a46 1.58 MiB 2.12 MiB 551.51 KiB
c3ee041 0 B 0 B 0 B
dcc6bbf 1.58 MiB 2.12 MiB 553.10 KiB
7a19fee 0 B 0 B 0 B
9054d65 1.58 MiB 2.29 MiB 723.38 KiB
d500866 0 B 0 B 0 B
ad8da22 1.58 MiB 2.29 MiB 719.83 KiB
ed33deb 1.58 MiB 2.13 MiB 559.52 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB

Previous results on branch: feat/log4j-autoinstrumentation

Startup times

Revision Plain With Sentry Diff
c488aa4 392.38 ms 468.44 ms 76.06 ms
e13dc15 377.54 ms 433.90 ms 56.36 ms
6f3172f 504.00 ms 585.84 ms 81.84 ms

App size

Revision Plain With Sentry Diff
c488aa4 0 B 0 B 0 B
e13dc15 0 B 0 B 0 B
6f3172f 0 B 0 B 0 B

@lbloder

lbloder commented May 12, 2026

Copy link
Copy Markdown
Collaborator Author

@sentry review

@lbloder

lbloder commented May 12, 2026

Copy link
Copy Markdown
Collaborator Author

cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7d76aa5. Configure here.

@lbloder
lbloder marked this pull request as ready for review May 26, 2026 06:35
Comment thread sentry-samples/sentry-samples-spring-boot-4/build.gradle.kts Outdated
@lbloder

lbloder commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

@adinauer should we add a separate spring-boot-log4j sample for e2e tets?

@adinauer adinauer 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.

Mostly LGTM, just needs to be opt-in for now, to not break manual setups on upgrade. Separate sample + E2E tests sounds good

Comment thread CHANGELOG.md Outdated
Co-authored-by: Alexander Dinauer <adinauer@users.noreply.github.com>
private boolean isSentryAppenderRegistered(final @NotNull LoggerConfig loggerConfig) {
return loggerConfig.getAppenders().values().stream()
.anyMatch(appender -> appender.getClass().equals(SentryAppender.class));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Incomplete existing appender check

Medium Severity

isSentryAppenderRegistered only looks at the target logger and requires an exact SentryAppender class match. A manually configured appender on another logger, or a subclass, does not block auto-registration, so a second appender can still be added. That conflicts with the changelog claim that existing manual SentryAppender setup takes precedence.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 53f53f6. Configure here.

…move log4j dependencies in spring-boot-4 sample
Comment on lines +27 to +29
ISpan currentSpan = Sentry.getSpan();
ISpan sentrySpan = currentSpan.startChild("spanCreatedThroughSentryApi");
try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The result of Sentry.getSpan() is used without a null check. This can cause a NullPointerException as the method is annotated with @Nullable.
Severity: MEDIUM

Suggested Fix

Add a null check after calling Sentry.getSpan() and before calling .startChild() on the result. Only proceed to create a child span if the currentSpan is not null. For example: if (currentSpan != null) { ISpan sentrySpan = currentSpan.startChild("..."); }.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
sentry-samples/sentry-samples-spring-boot-4-log4j2/src/main/java/io/sentry/samples/spring/boot4/PersonController.java#L27-L29

Potential issue: The `Sentry.getSpan()` method is annotated with `@Nullable`, indicating
it can return `null`. However, the code in `PersonController.java` directly calls
`.startChild()` on the returned `ISpan` object without a null check. This will cause a
`NullPointerException` if no active Sentry transaction is present. This can occur under
realistic conditions, such as when tracing is disabled (e.g.,
`sentry.traces-sample-rate=0`), the Sentry DSN is missing, or if the
`SentryTracingFilter` fails to initialize.

Also affects:

  • sentry-samples/sentry-samples-spring-boot-4-log4j2/src/main/java/io/sentry/samples/spring/boot4/PersonController.java:47~48

Did we get this right? 👍 / 👎 to inform future reviews.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4362c07. Configure here.


final LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, null, true);
newLoggerConfig.setParent(loggerConfig);
configuration.addLogger(loggerName, newLoggerConfig);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate events with nested loggers

Medium Severity

Newly created logger configs always use additive=true. When both ROOT and a child logger are listed—as in the changelog example—and the child config does not already exist, the same log event is delivered to SentryAppender on the child and again on ROOT via additivity, producing duplicate events, breadcrumbs, and structured logs.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4362c07. Configure here.

@lbloder

lbloder commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

@adinauer added the sample and e2e tests

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.

Spring Boot support for Log4j2

2 participants