The application uses Sentry to detect error information.
I want to be able to check which version of the application the error information sent to Sentry is for the error.
--You can identify the application version of the error that occurred at a glance. --On the Sentry screen, you will be able to search the list of errors that occurred in a specific version as follows.
--The application version is defined. --The version is updated with each release.
Send the following definition file in <version>
to Sentry.
This time, we will send the version information to Sentry as a tag.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmls="~">
:
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>100.0.100</version>
:
</project>
Make corrections in the following order.
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
application.yml
management:
endpoints:
web:
exposure:
include: "info"
base-path: "/"
Change the base-path according to your environment.
application.yml
info:
application:
version: @project.version@
With the settings up to this point, you can check the version information set in the steps up to this point by accessing http: // localhost: 8080 / info
as shown below.
{"application":{"version":"100.0.100"}}
Configuration file: Add the following processing to the class in which @SpringBootApplication annotation is set.
version
.
(Addition of arguments and transmission of tag.)
@Bean
public HandlerExceptionResolver sentryExceptionResolver(
@Value("${sentry.url:#{null}}") Optional<String> sentryUrl,
@Value("${info.application.version:#{null}}") Optional<String> appVersion) {
if (sentryUrl.isPresent()) {
try {
SentryClient sentryClient = Sentry.init(sentryUrl.get());
//Here, version information is added as a tag.
appVersion.ifPresent(s -> sentryClient.addTag("version", s));
} catch (InvalidDsnException e) {
LOGGER.warn(e.getMessage(), e);
}
}
return new SentryExceptionResolverImpl();
}
Sentry.url
is also defined in ʻapplication.yml in the same way as ʻinfo.application.version
.After completing the above settings, if an error occurs in the application, the following version
tag will be displayed.
By clicking the numerical part of version, you can check the search results mentioned as the merit at the beginning.
Recommended Posts