How to add application version information to Sentry information

Premise

The application uses Sentry to detect error information.

Language and framework

Overview

I want to be able to check which version of the application the error information sent to Sentry is for the error.

merit

--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.

Screenshot 2020-10-15 11.33.52.png

Prerequisites

--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.

Definition file

pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<project xmls="~">
     :
	<groupId>com.example</groupId>
	<artifactId>myproject</artifactId>
	<version>100.0.100</version>
     :
</project>

Correction procedure

Make corrections in the following order.

  1. Add dependency
  2. Add endpoint
  3. Add information to display on the endpoint
  4. Addition of transmission process to Sentry

1. Add dependency

pom.xml


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

2. Add endpoint

application.yml


management:
  endpoints:
    web:
      exposure:
        include: "info"
      base-path: "/"

Change the base-path according to your environment.

3. Add information to display on the endpoint

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"}}

4. Addition of transmission process to Sentry

Configuration file: Add the following processing to the class in which @SpringBootApplication annotation is set.


  @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();
  }

After setting

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.

Screenshot 2020-10-15 11.27.03.png

Recommended Posts

How to add application version information to Sentry information
How to create an application
How to lower java version
How to add ActionText function
How to check JSF version
How to add HDD to Ubuntu
How to monitor application information in real time using JConsole
How to add Hyperledger Iroha Peer
How to add columns to a table
[rails] How to display db information
[Rails] How to add new pages
[Xcode] How to add a README.md file
How to add local jar to maven pom.xml
[Java] How to add data to List (add, addAll)
How to publish an application on Heroku
How to add a new hash / array
How to add jar file in ScalaIDE
How to install the legacy version [Java]
How to add / remove Ruby on Rails columns
How to add sound in the app (swift)
How to create a class that inherits class information
How to deploy
How to delete the database when recreating the application
How to add a classpath in Spring Boot
How to conditionally add html.erb class in Rails
How to make Unity Native Plugin (Android version)
How to use nfs protocol version 2 with ubuntu 18.04
How to write React Native bridge ~ Android version ~
How to run NullpoMino 7.5.0 on Ubuntu 20.04.1 64bit version
How to update devise user information without a password
How to get information about associated tables in many-to-many tables
How to add characters to display when using link_to method
How to organize information to make programming learning more efficient
[Ruby] How to use rbenv (version `x.x.x'is not installed)
Install MySQL 5.6 on CentOS6 [How to specify the version]
How to pass image pixel information natively from Unity
How to download the old version of Apache Tomcat
Add files to jar files
How to develop OpenSPIFe
How to call AmazonSQSAsync
How to use Map
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to adapt Bootstrap
How to use Twitter4J
How to use active_hash! !!
How to install Docker
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
How to uninstall Rails
How to install docker-machine
[How to use label]
How to make shaded-jar
How to use identity
How to use hashes