getsentry / getsentry/sentry-java

`SentryLogbackInitializer` is initialized too late

未關閉
#3,650 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
Improvement Java Logs
主要語言
Kotlin
星號
1.4k
分支
478
平均合併
3 天 4 小時
30 天內合併 PR
72

描述

### 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?

貢獻指南

開啟貢獻指南

研究方向

從 SentryLogbackAppenderAutoConfiguration 和 SentryLogbackInitializer 開始,然後追蹤 initializer 如何處理 ContextRefreshedEvent。將該路徑與 Spring Boot 的 ApplicationEnvironmentPreparedEvent 以及 issue 中對 LoggingApplicationListener 的參考進行比較。完成的標準是:使用 sentry-spring-boot-starter-jakarta 時能夠擷取啟動警告日誌,並且測試涵蓋更早的初始化時機。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java, spring-boot
領域
backend, observability
Issue 類型
缺陷
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
32/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。