Sentry-java: Add ability to sentry-spring-boot-starter to configurate sentry in application.yml file

Created on 2 Aug 2019  Â·  16Comments  Â·  Source: getsentry/sentry-java

Want to centrilize my application configuration, but can't do this, because I can't set proeprties like sentry.dsn, sentry.stacktrace.app.packages in application.yml file - every time I need to create sentry.properties file. Could you add this ability?

enhancement good first issue help wanted

Most helpful comment

I mean create new SentryProperties class like this:

@Getter
@Setter
@ConfigurationProperties(prefix = "sentry")
public class SentryProperties {

    private boolean enabled;
    private String dsn;
    private List<String> stacktraceAppPackages;

// And all other properties

}

and in application.yml we'll write this:

sentry:
  enabled: true
  dsn: http://
  stacktrace-app-packages:
    - com.pack1
    - com.pack2
# and all other properties

My idea is to be able to replace the sentry.properties file with the Spring Boot application.yml. Of course, I don't know how works your library and perhaps this is not so easy to do.

All 16 comments

Is it possible to load applications.yml with Java Properties? As in Properties.load(inputStream)?

If so, we've just merged ResourceLoader which you can use to override to location to load configuration.

here's an example implementation for Android:

https://github.com/getsentry/sentry-java/blob/2b1d342b1d125f858fd5ec809a69f2c4090fe8dc/sentry-android/src/main/java/io/sentry/android/AndroidAssetsResourceLoader.java#L38-L45

And how it'll be used within the SDK:

https://github.com/getsentry/sentry-java/blob/66aac3cff991baa2675473d4b7d7f4f1b3206113/sentry/src/main/java/io/sentry/config/Lookup.java#L40-L44

I mean create new SentryProperties class like this:

@Getter
@Setter
@ConfigurationProperties(prefix = "sentry")
public class SentryProperties {

    private boolean enabled;
    private String dsn;
    private List<String> stacktraceAppPackages;

// And all other properties

}

and in application.yml we'll write this:

sentry:
  enabled: true
  dsn: http://
  stacktrace-app-packages:
    - com.pack1
    - com.pack2
# and all other properties

My idea is to be able to replace the sentry.properties file with the Spring Boot application.yml. Of course, I don't know how works your library and perhaps this is not so easy to do.

Yeah that's a great feature to have.
Would you like to try to send a PR with the feature?

We have a draft PR open that will address this issue nicely: #750

Yes, the big advantage I see here is to take advantage of the existing features provided by Spring Boot for per-environment configuration.

So, I'd have a single artifact I'd deploy to test and production environments, and just switching the spring.profiles.active system property as part of the runtime will load the right configuration.

@pioto #750 got merged so now configuration can be nicely extended.
I'm still unfamiliar with springboot config system but If you'd be willing to open a PR, even if a draft of what a support we could iterate through it.

I think, basically, from skimming the code, you'd want to have your
Lookup stuff have another system to look up info in, which would
basically be looking for fields in a @ConfigurationProperties annotated
class, managed via Spring.

See this documentation for details on how that works:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties

So, you'd want to expose the dsn, environment, etc as properties that way.

That'd also possibly make it easier to access that same configuration
elsewhere. Noticeably, to only have to configure the DSN once, but be able
to access it in a Thymeleaf template to configure the browser integration.
Something like:

<script th:inline="javascript">
Sentry.init({
  'dsn': /*[[${@sentryProperties.dsn}]]*/ null,
  'environment': /*[[${@sentryProperties.environment}]]*/ null
});
</script>

On Fri, Oct 4, 2019 at 12:38 PM Bruno Garcia notifications@github.com
wrote:

@pioto https://github.com/pioto #750
https://github.com/getsentry/sentry-java/pull/750 got merged so now
configuration can be nicely extended.
I'm still unfamiliar with springboot config system but If you'd be willing
to open a PR, even if a draft of what a support we could iterate through it.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/getsentry/sentry-java/issues/748?email_source=notifications&email_token=AAAEBYQ6N5PBO6PQT2CT6L3QM5WQ7A5CNFSM4II2HXX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAMG7EA#issuecomment-538472336,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAEBYUJ4RDRNXEJQ3FGCXTQM5WQ7ANCNFSM4II2HXXQ
.

--
Mike Kelly

@altro3 please check this PR: https://github.com/getsentry/sentry-java/pull/779, I hope it's what you are looking for.

Yes, grate! That's what I talking about :-)

is it possible to use the sentry logback appender with this starter?

@jeacott1 yes, this is how I use it.

So the property stacktrace.app.packages sounds like it'd end up as

sentry:
  stacktrace:
    app:
      packages:
        - com.example...

but in the code the property is Set<String> appPackages which means the actual configuration path is

sentry:
  stacktrace:
    app-packages: (# or optionally appPackages:)
      - com.example...

This led me, at least, to some confusion only resolved by digging into the library code. (I would have raised it as a separate issue but seeing as this one was still open I figured it made more sense to add it here)

Sentry Java SDK 3.0 uses application.properties, would that be enough?

@maciejwalkowiak ^

In v3 Sentry comes with a dedicated Spring Boot starter that is fully configurable via application.properties or application.yml and seamlessly integrates with Sentry Logback integration.

thanks.
https://github.com/getsentry/sentry-java/releases/tag/3.0.0-beta.1
later I post the docs here once is live

Was this page helpful?
0 / 5 - 0 ratings