This repository has been archived by the owner on May 22, 2021. It is now read-only.
generated from E-Edu/microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from E-Edu/issue/40
Issue/40
- Loading branch information
Showing
9 changed files
with
190 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,3 +289,5 @@ nbdist/ | |
/gateway.iml | ||
|
||
*.iml | ||
|
||
.sentryEnabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ services: | |
JWT_SECRET: SECRET | ||
SERVICE_SECRET: SECRET | ||
PRODUCTIVE: "false" | ||
SENTRY_ENABLED: "${SENTRY_ENABLED}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
package de.themorpheus.edu.gateway; | ||
|
||
import de.themorpheus.edu.gateway.util.GitInfo; | ||
import com.jcabi.manifests.Manifests; | ||
import io.sentry.Sentry; | ||
import io.sentry.SentryClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import java.io.IOException; | ||
|
||
@SpringBootApplication | ||
public class GatewayApplication { | ||
|
||
public static final boolean PRODUCTIVE = Boolean.parseBoolean(System.getenv("PRODUCTIVE")); | ||
public static final boolean SENTRY_ENABLED = Boolean.parseBoolean(System.getenv("SENTRY_ENABLED")); | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(GatewayApplication.class.getSimpleName()); | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(GatewayApplication.class, args); | ||
initSentry(); | ||
} | ||
|
||
@Bean | ||
|
@@ -28,4 +41,36 @@ public void addCorsMappings(CorsRegistry registry) { | |
}; | ||
} | ||
|
||
private static void initSentry() { | ||
if (!PRODUCTIVE && !SENTRY_ENABLED) { | ||
Sentry.init(""); | ||
LOGGER.info("Sentry error reporting is disabled."); | ||
return; | ||
} | ||
|
||
Sentry.init("https://[email protected]/9"); | ||
SentryClient sentry = Sentry.getStoredClient(); | ||
sentry.addTag("OS", System.getProperty("OS")); | ||
sentry.addTag("version", GatewayApplication.class.getPackage().getImplementationVersion()); | ||
sentry.addTag("title", GatewayApplication.class.getPackage().getImplementationTitle()); | ||
sentry.addTag("environment", PRODUCTIVE ? "production" : "dev"); | ||
|
||
try { | ||
GitInfo gitInfo = GitInfo.load(); | ||
sentry.addTag("build-host", gitInfo.getBuildHost()); | ||
sentry.addTag("build-time", Manifests.read("Build-Time")); | ||
sentry.addTag("build-user-email", gitInfo.getBuildUserEmail()); | ||
sentry.addTag("build-version", gitInfo.getBuildVersion()); | ||
sentry.addTag("git-branch", gitInfo.getBranch()); | ||
sentry.addTag("git-commit-id", gitInfo.getCommitId()); | ||
sentry.addTag("git-commit-message", gitInfo.getCommitMessageShort()); | ||
sentry.addTag("git-commit-user-email", gitInfo.getCommitUserEmail()); | ||
sentry.addTag("git-dirty", gitInfo.getGitDirty()); | ||
} catch (IOException ex) { | ||
LOGGER.error("Error while loading git information", ex); | ||
} | ||
|
||
LOGGER.info("Sentry error reporting is enabled."); | ||
} | ||
|
||
} |
33 changes: 27 additions & 6 deletions
33
src/main/java/de/themorpheus/edu/gateway/graphql/resolver/query/ServiceInfoResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/de/themorpheus/edu/gateway/util/GitInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.themorpheus.edu.gateway.util; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.core.io.Resource; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class GitInfo { | ||
|
||
private String branch; | ||
private String buildHost; | ||
private String buildUserEmail; | ||
private String buildVersion; | ||
private String commitId; | ||
private String commitMessageShort; | ||
private String commitUserEmail; | ||
private String gitDirty; | ||
|
||
public static GitInfo load() throws IOException { | ||
Resource resource = new ClassPathResource("git.properties"); | ||
Properties properties = new Properties(); | ||
properties.load(resource.getInputStream()); | ||
|
||
return new GitInfo( | ||
properties.getProperty("git.branch"), | ||
properties.getProperty("git.build.host"), | ||
properties.getProperty("git.build.user.email"), | ||
properties.getProperty("git.build.version"), | ||
properties.getProperty("git.commit.id"), | ||
properties.getProperty("git.commit.message.short"), | ||
properties.getProperty("git.commit.user.email"), | ||
properties.getProperty("git.dirty") | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="warn" packages="org.apache.logging.log4j.core,io.sentry.log4j2"> | ||
<Appenders> | ||
|
||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout> | ||
<pattern>%style{[}{dim,white}%d{HH:mm:ss}%style{][}{dim,white}%highlight{%-5.5level{INFO=INFO, | ||
WARN=WARN, ERROR=ERROR, DEBUG=DEBUG}}{ERROR=red, DEBUG=blue, | ||
INFO=green}%style{][}{dim,white}%style{%logger}{dark,cyan}%style{]}{dim,white}: | ||
%highlight{%msg%n%throwable}{ERROR=red, DEBUG=blue, INFO=default} | ||
</pattern> | ||
</PatternLayout> | ||
</Console> | ||
|
||
<RollingRandomAccessFile name="Logfile" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log"> | ||
<PatternLayout pattern="[%d{dd MMM HH:mm:ss}][%level][%logger]: %msg%n"/> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy/> | ||
<OnStartupTriggeringPolicy/> | ||
</Policies> | ||
</RollingRandomAccessFile> | ||
|
||
<Sentry name="Sentry" /> | ||
</Appenders> | ||
|
||
<Loggers> | ||
<Root level="debug"> | ||
<AppenderRef ref="Logfile"/> | ||
<AppenderRef ref="Console" level="debug"/> | ||
<AppenderRef ref="Sentry" level="WARN" /> | ||
</Root> | ||
<Logger name="org.reflections" level="off"/> | ||
<Logger name="org.hibernate" level="warn"/> | ||
<Logger name="org.springframework" level="warn"/> | ||
<Logger name="com.oembedler.moon.graphql" level="warn"/> | ||
<Logger name="io.micrometer.core" level="warn"/> | ||
<Logger name="graphql.kickstart" level="warn"/> | ||
<Logger name="com.jcabi.manifests" level="warn"/> | ||
<Logger name="io.sentry" level="warn"/> | ||
<Logger name="graphql.execution" level="warn"/> | ||
<Logger name="notprivacysafe.graphql" level="warn"/> | ||
</Loggers> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
stacktrace.app.packages= # Disables the console warning |