diff --git a/src/main/java/com/atomist/SentryConfiguration.java b/src/main/java/com/atomist/SentryConfiguration.java new file mode 100644 index 0000000..498c0ca --- /dev/null +++ b/src/main/java/com/atomist/SentryConfiguration.java @@ -0,0 +1,64 @@ +package com.atomist; + +import io.sentry.Sentry; +import io.sentry.spring.SentryExceptionResolver; +import io.sentry.spring.SentryServletContextInitializer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.info.GitProperties; +import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.HandlerExceptionResolver; + +import javax.annotation.PostConstruct; + +@Configuration +public class SentryConfiguration { + + @Value("${raven.dsn}") + private String dsn; + + @Value("${atomist.environment.domain}") + private String environment; + + @Value("${atomist.environment.pod}") + private String server; + + @Autowired + private GitProperties gitProperties; + + @Bean + public HandlerExceptionResolver sentryExceptionResolver() { + return new SentryExceptionResolver(); + } + + @Bean + public ServletContextInitializer sentryServletContextInitializer() { + return new SentryServletContextInitializer(); + } + + @PostConstruct + public void init() { + + String url = this.gitProperties.get("remote.origin.url"); + String owner = ""; + String repo = ""; + url = url.replace(".git", ""); + if (url.startsWith("git")) { + int ix = url.lastIndexOf(":"); + String slug = url.substring(ix + 1); + owner = slug.split("/")[0]; + repo = slug.split("/")[1]; + } else { + int ix = url.lastIndexOf("/"); + repo = url.substring( ix + 1); + url = url.substring(0, ix); + ix = url.lastIndexOf("/"); + owner = url.substring(ix + 1); + } + + Sentry.init(this.dsn + "?extra=git_sha:" + this.gitProperties.getCommitId()+ ",git_repo:" + repo + ",git_owner:" + owner + + "&release=" + this.gitProperties.getCommitId() + "&environment=" + this.environment + "&servername=" + this.server); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..4741e10 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,3 @@ + +raven: + dsn: 'adad' \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 0000000..4741e10 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,3 @@ + +raven: + dsn: 'adad' \ No newline at end of file