Install the Java microagent on Heroku applications

Heroku is a Platform as a Service (PaaS) that hosts web applications. Sqreen supports Heroku for Java applications.

  1. Review Java microagent compatibility to confirm that the Sqreen Microagent for Java is compatible with your Java application.
  2. Sign up to create your Sqreen account. The Sqreen Add-on for Heroku automatically provides the SQREEN_TOKEN environment variable.
  3. After deploying your Java app on Heroku, add the sqreen.jar file to your project using Maven or Gradle, or add it directly to your repository.
      Maven:
    1. In the pom.xml file, add the following plugin definition for the latest version of the microagent. If you prefer to use a specific version of the microagent, replace java/sqreen.jar with java/sqreen-{VERSION}.jar, where {VERSION} is the version number you wish to use.
      <!-- download latest sqreen agent -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>wagon-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>download-sqreen</id>
            <phase>package</phase>
            <goals>
              <goal>download-single</goal>
            </goals>
            <configuration>
              <url>https://download.sqreen.com</url>
              <fromFile>java/sqreen.jar</fromFile>
              <toFile>${project.build.directory}/../sqreen.jar</toFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
      
    2. Commit your changes.
      git add ./pom.xml
      git commit -m 'Add Sqreen agent'
      
      Gradle:
    1. In the build.gradle file, add the following for the latest version of the microagent. If you prefer to use a specific version of the microagent, replace java/sqreen.jar with java/sqreen-{VERSION}.jar, where {VERSION} is the version number you wish to use.
      plugins {
          id "de.undercouch.download" version "3.4.3"
      }
      
      task downloadSqreen(type: Download) {
          src 'https://download.sqreen.com/java/sqreen.jar'
          dest "$buildDir/../sqreen.jar"
          onlyIfModified false
      }
      
      // download sqreen agent at stage configuration used by heroku
      stage.dependsOn(downloadSqreen)
      
    2. Commit your changes.
      git add ./build.gradle
      git commit -m 'Add Sqreen agent'
      
      Repository:
    1. Download the sqreen.jar file and store it with your code:
      curl https://download.sqreen.com/java/sqreen.jar -o sqreen.jar
      git add ./sqreen.jar
      git commit -m 'Add Sqreen agent'
      
  4. Set the -javaagent command line parameter in the app's Procfile. If your app uses more than one agent, be sure to require the Sqreen Microagent for Java last in the JVM arguments.
    web: java -javaagent:/app/sqreen.jar -jar your-app-1.0.jar
    
  5. By default, the microagent writes its logs to the file system in /tmp/sqreen.log but this does not work well with Heroku apps because log files are lost on each deployment/restart. Set the following environment variable to configure the microagent to write logs to standard output: SQREEN_LOG_LOCATION=/dev/stdout.
  6. Commit your changes and deploy your updated application.
    git add ./Procfile
    git commit -m 'Configure Sqreen agent'
    
    # redeploys your app with the Sqreen microagent
    git push heroku master
    

Learn more about using Sqreen with Heroku: