sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Failed to init Sentry during appender initialization: DSN is required

Open dodgex opened this issue 5 months ago • 5 comments

Integration

sentry-spring-boot-jakarta

Java Version

21

Version

8.16.0

Steps to Reproduce

  • Spring Boot 3.5.3
  • no logback.xml
  • sentry.dsn in applicaiton.yml

Dependencies on classpath:

  • sentry
  • sentry-logback
  • sentry-reactor
  • sentry-spring-boot-jakarta
  • sentry-spring-boot-starter-jakarta
  • sentry-spring-jakarta

Expected Result

No warnings about sentry failing to init

Actual Result

There is a warning logged:

12:17:28,447 |-WARN in io.sentry.logback.SentryAppender[SENTRY_APPENDER] - Failed to init Sentry during appender initialization: DSN is required. Use empty string or set enabled to false in SentryOptions to disable SDK.

Even tho it works.

Adding a breakpoint in Sentry.init() reveals, that is been called twice, once from SentryAutoConfiguration and again from SentryAppender#start via SentryLogbackInitializer. The problem on that second call is, that the SentryAppender creates an empty SentryOptions instance that is used in start(). If the SentryLogbackInitializer would pass its instance of SentryProperties to the Appender on creation, the warning does not appear.

Potential fixes (from my understanding of what happens :D):

  • Add sentryAppender.setOptions(sentryProperties); here and potentially here too
  • or verify if the condition here should possibly be changed to options.getDsn() != null

dodgex avatar Jul 01 '25 10:07 dodgex

Maybe this is to some degree related to https://github.com/getsentry/sentry-java/issues/3249 but I did not want to reopen such an old issue.

dodgex avatar Jul 01 '25 10:07 dodgex

Thanks for reaching out @dodgex . You can safely ignore this warning. We'll take a look at getting rid of it.

adinauer avatar Jul 01 '25 12:07 adinauer

We could simply use the SentryAppender::setOptions here to make the warning go away

jebeaudet avatar Jul 28 '25 21:07 jebeaudet

I'm experiencing similar issue (init method being called twice: once from SentryAutoCinfiguration#sentryHub and once from SentryAppender#start). I have the bean OptionsConfiguration<SentryOptions> created. I used debugger to see that they are filled correctly when called from SentryAutoConfiguration but are not injected in the 2nd call.

~Unfortunately for me, the latter call (without options) empty dsn resulting in Sentry not working at all resulting in Failed to init Sentry during appender initialization: DSN is required. Use empty string or set enabled to false in SentryOptions to disable SDK.~ EDIT: It started working once upgraded to the newest 5.8.0. Last version of Sentry that doesn't print the warning is 4.14.1. The newest, 5.8.0 prints the warning but works. In the meantime I think I had other version (higher than 4.14.1 but lower than 5.8.0 and it wasn't working at all).

Stack:

  • SpringBoot 3.5.3
  • Sentry Plugin 5.8.0
  • no logback

Andromedids avatar Jul 29 '25 08:07 Andromedids

@Andromedids it's quite possible you've hit a buggy version of the Java SDK which the Gradle plugin automatically adds. Glad it's working for you with the latest version.

@jebeaudet that would have some side effects like reporting the wrong SDK (logback vs spring boot) and might have more problems due to the re-init not going through but at the same time using options of a login that already went through. So a bit more than that will likely be required.

adinauer avatar Jul 29 '25 12:07 adinauer