Skip to content
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

SentryLogbackInitializer is initialized too late #3650

Open
ghoonch4 opened this issue Aug 21, 2024 · 1 comment
Open

SentryLogbackInitializer is initialized too late #3650

ghoonch4 opened this issue Aug 21, 2024 · 1 comment

Comments

@ghoonch4
Copy link

Problem Statement

I am trying to use the sentry-spring-boot-starter-jakarta library. However, I have discovered that warning logs during the application startup are not being sent to Sentry. In SentryLogbackAppenderAutoConfiguration, the autoconfiguration for SentryLogbackInitializer is found, and this configuration seems to be too late.

Spring publishes events in the order described in Spring Application Events and Listeners. When configuring SentryAppender directly via logback-spring.xml without using the sentry-spring-boot-starter-jakarta library, the SentryAppender is initialized at the time of the ApplicationEnvironmentPreparedEvent publication. This is an earlier initialization point. Please refer to LoggingApplicationListener.java#L218.

Solution Brainstorm

  1. Instead of using SentryLogbackAppenderAutoConfiguration, how about registering the listener quickly by configuring it in spring.factories like:
org.springframework.context.ApplicationListener=\
io.sentry.spring.boot.jakarta.SentryLogbackInitializer
  1. Currently, SentryLogbackInitializer supports events of type ContextRefreshedEvent, but even with early listener registration, a lot of tasks may already have been performed by the time ContextRefreshedEvent is published. Can we initialize it at the time of ApplicationEnvironmentPreparedEvent publication?
@adinauer
Copy link
Member

Thanks for opening this issue @ghoonch4! We'll look into this but I'm guessing specifying it in spring.factories would cause problems for users not having the logback dependency. We load some of our config conditionally (depending on classes available), which is what SentryLogbackAppenderAutoConfiguration does via some @ConditionalOn... annotations. Our current suggestion is to configure the logback XML config file if you want startup logs to be captured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: Needs Discussion
Development

No branches or pull requests

2 participants