Sentry-java: Sentry external config not loading sentry.properties from disk automatically

Created on 16 Nov 2020  路  6Comments  路  Source: getsentry/sentry-java

_Platform:_

  • [ ] Android -> If yes, which Device API (and compileSdkVersion/targetSdkVersion/Build tools) version?
  • [x] Java -> If yes, which Java (and sourceCompatibility/targetCompatibility) version?
    openjdk version "11.0.2" 2019-01-15
  • [ ] Kotlin -> If yes, which Kotlin (and jvmTarget) version?
  • [ ] NDK -> If yes, which NDK/CMake version?
  • [ ] React-Native -> If yes, which version?
  • [ ] Timber -> If yes, which version?
  • [ ] Log4j2 -> If yes, which version?
  • [ ] Logback -> If yes, which version?
  • [ ] Spring -> If yes, which version?

_IDE:_

  • [ ] Android Studio -> If yes, which version?
  • [x] IntelliJ -> If yes, which version?
    IntelliJ IDEA 2020.2.3 (Ultimate Edition)
  • [ ] Other -> If yes, which one?

_Build system:_

  • [x] Gradle -> If yes, which version?
    6.7
  • [ ] Buck -> If yes, which version?
  • [ ] Bazel -> If yes, which version?
  • [ ] Maven -> If yes, which version?
  • [ ] Other -> If yes, which one?

_Android Gradle Plugin:_

  • [ ] Yes -> If yes, which version?
  • [x] No

_Sentry Android Gradle Plugin:_

  • [ ] Yes -> If yes, which version?
  • [x] No

_Proguard/R8:_

  • [ ] Enabled
  • [x] Disabled

_Platform installed with:_

  • [x] JCenter
  • [ ] Bintray
  • [ ] Maven Central
  • [ ] Manually

The version of the SDK:
3.1.3


I have the following issue:

Sentry does not load sentry.properties from disk by default if the file is in the root directory with the application.
Adding the system property to tell sentry where the file is located is required to load the properties file.

        System.setProperty("sentry.properties.file", "sentry.properties");
        Sentry.init(options -> {
            options.setEnableExternalConfiguration(true);
        });

Steps to reproduce:
Place properties file in working directory with application when using external configuration.

Actual result:

  • Actual
    File is not loaded and no dsn is available.
Exception in thread "main" java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
    at io.sentry.Sentry.initConfigurations(Sentry.java:183)
    at io.sentry.Sentry.init(Sentry.java:153)
    at io.sentry.Sentry.init(Sentry.java:124)
    at io.sentry.Sentry.init(Sentry.java:110)

Expected result:
Works as before with version 1 and auto detects the file.

documentation enhancement

All 6 comments

thanks for raising this.

I think it tries to read by default from the ClassLoader, cc @maciejwalkowiak to confirm.

As @marandaneto said, by default it tries to load a file from the root of the classpath. Now I see that in 1.7.x in addition to that it did look into the root directory. I'll prepare a fix for that.

not sure if it's documented already, but it'd be nice to document which configuration has precedence over others eg file from classpath, then file in the root, system envs, etc... otherwise, they will overwrite each other and it'll be hard to find out.

It is in Javadocs: https://getsentry.github.io/sentry-java/io/sentry/config/PropertiesProviderFactory.html#create-- but not in the reference docs. I'll add there too.

yeah worth adding it, this question also came thru different channels, thanks.

Gonna be released on the next version :)

Was this page helpful?
0 / 5 - 0 ratings