Skip to content

Send Logback logs to Sentry as logs #4502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Send Logback logs to Sentry as logs #4502

wants to merge 9 commits into from

Conversation

adinauer
Copy link
Member

📜 Description

Allow setting a minimumLevel to our Logback integration which causes logs >= that level to be sent to Sentry as logs.

You also have to enable the logs feature:

Either in logback.xml:

<appender name="sentry" class="io.sentry.logback.SentryAppender">
  <options>
    <!-- NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard -->
    <dsn>https://[email protected]/5428563</dsn>
    <logs>
      <enabled>true</enabled>
    </logs>
  </options>
  <!-- Demonstrates how to modify the minimum values -->
  <!-- Default for Events is ERROR -->
  <minimumEventLevel>WARN</minimumEventLevel>
  <!-- Default for Breadcrumbs is INFO -->
  <minimumBreadcrumbLevel>DEBUG</minimumBreadcrumbLevel>
  <!-- Default for Breadcrumbs is INFO -->
  <minimumLevel>INFO</minimumLevel>
</appender>

Or in sentry.properties:

logs.enabled=true

Or when calling Sentry.init:

    Sentry.init(options -> {
      ...
      options.getLogs().setEnabled(true);
    });

Note: This is different from breadcrumbs (minimumBreadcrumbLevel) and error events (minimumEventLevel) we already had since Sentry Logs is a separate product feature. Breadcrumbs and error events still work.

💡 Motivation and Context

Closes #4404

💚 How did you test it?

📝 Checklist

  • 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

@adinauer
Copy link
Member Author

There's currently a problem, where we don't flush logs before the application shuts down. Will open a separate PR to fix.

Copy link
Contributor

github-actions bot commented Jun 20, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Send Logback logs to Sentry as logs ([#4502](https://github.com/getsentry/sentry-java/pull/4502))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 7792597

Copy link
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 412.67 ms 443.19 ms 30.52 ms
Size 1.58 MiB 2.09 MiB 518.66 KiB

Comment on lines 84 to 85
final Hint hint = new Hint();
hint.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final Hint hint = new Hint();
hint.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject);

I think the hint is not needed here, right?

// for the Android compatibility we must use old Java Date class
@SuppressWarnings("JdkObsolete")
protected void captureLog(@NotNull ILoggingEvent loggingEvent) {
final @NotNull SentryLogLevel sentryLevel = toSentryLogLevel(loggingEvent.getLevel());
Copy link
Member

Choose a reason for hiding this comment

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

let's also check if logs is enabled here, so we don't format the string if not necessary?

Copy link
Member

@stefanosiano stefanosiano left a comment

Choose a reason for hiding this comment

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

I think it's ok
In mobile we want to wait for priority queue for logs integrations to avoid log envelopes throwing away errors, especially when the app is offline, but also in case an app logs really a lot.
Not sure how much of it is applicable to backend, though

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.

Integration for Sentry Logs through Logback
2 participants