getsentry / getsentry/sentry-java

`SentryLogbackInitializer` is initialized too late

Aberta
#3,650 1 comentário 0 reações 0 responsáveis Ver no GitHub
Improvement Java Logs
Linguagem predominante
Kotlin
Estrelas
1.4k
Forks
478
Merge médio
3d 4h
PRs com merge (30d)
72

Descrição

### 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](https://docs.spring.io/spring-boot/reference/features/spring-application.html#features.spring-application.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](https://github.com/spring-projects/spring-boot/blob/7936de70d897fcc8cc929b9afe2dfc8ac7ad0adf/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/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
```

2. 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?

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

Comece com SentryLogbackAppenderAutoConfiguration e SentryLogbackInitializer e, em seguida, rastreie como o inicializador trata ContextRefreshedEvent. Compare esse caminho com o ApplicationEnvironmentPreparedEvent do Spring Boot e a referência a LoggingApplicationListener na issue. Considera-se concluído quando os logs de aviso emitidos na inicialização são capturados ao usar sentry-spring-boot-starter-jakarta, com testes cobrindo o momento de inicialização mais cedo.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
java, spring-boot
Domínio
backend, observability
Tipo de issue
Bug
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
32/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.