Skip to content

Commit

Permalink
Merge pull request #23 from agorapulse/fix/sc-70828-support-legacy-se…
Browse files Browse the repository at this point in the history
…ntry-sdn

[sc70828] support Sentry DSN in env var format
  • Loading branch information
musketyr committed Apr 6, 2022
2 parents 3e8912c + 11a953d commit 9662e49
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Value;
import io.micronaut.core.util.StringUtils;
import io.sentry.EventProcessor;
import io.sentry.IHub;
import io.sentry.Sentry;
Expand Down Expand Up @@ -51,15 +52,19 @@ public class Log4AwsFactory {
*/
@Bean
@Context
public SentryAppender sentryAppender(IHub hub, @Value("${sentry.dsn:}") String sentryDsn) {
public SentryAppender sentryAppender(
IHub hub,
@Value("${sentry.dsn:}") String sentryDsn,
@Value("${SENTRY_DSN:}") String sentryDsnLegacy
) {
return initializeAppenderIfMissing(
SentryAppender.class,
Level.WARN,
APPENDER_NAME,
() -> new SentryAppender(
APPENDER_NAME,
null,
sentryDsn,
StringUtils.isNotEmpty(sentryDsn) ? sentryDsn : sentryDsnLegacy,
null,
null,
null,
Expand All @@ -78,9 +83,15 @@ public SentryAppender sentryAppender(IHub hub, @Value("${sentry.dsn:}") String s
*/
@Bean
@Context
public IHub sentryClient(List<Sentry.OptionsConfiguration<SentryOptions>> configurations, @Value("${sentry.dsn:}") String sentryDsn) {
public IHub sentryClient(
List<Sentry.OptionsConfiguration<SentryOptions>> configurations,
@Value("${sentry.dsn:}") String sentryDsn,
@Value("${SENTRY_DSN:}") String sentryDsnLegacy
) {
Sentry.init(options -> {
options.setDsn(sentryDsn);
options.setDsn(
StringUtils.isNotEmpty(sentryDsn) ? sentryDsn : sentryDsnLegacy
);
configurations.forEach(c -> c.configure(options));
});
return Sentry.getCurrentHub();
Expand Down

0 comments on commit 9662e49

Please sign in to comment.