Installation on Heroku

Protect your applications on Heroku with Sqreen


The Sqreen Java agent and Heroku

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

See our Heroku page for more information.

Installation for Heroku apps

After deploying your Java app on Heroku, you can install the Sqreen agent.

You need to:

  • Add the sqreen.jar, either using Maven, Gradle or directly in your repository.
  • Change the Java command line parameters.

Adding sqreen.jar to your project

Using Maven

In pom.xml, add the following plugin definition:

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

Then, commit your changes.

git add ./pom.xml
git commit -m 'Add Sqreen agent'

Each new deploy downloads the latest version of the agent. If you prefer to use a specific version, replace java/sqreen.jar with java/sqreen-{VERSION}.jar, where {VERSION} is the version number.

Using Gradle

In build.gradle add:

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(dowloadSqreen)

Then, commit your changes:

git add ./build.gradle
git commit -m 'Add Sqreen agent'

Each new deploy downloads the latest version of the agent. If you want to use a specific version, replace java/sqreen.jar with java/sqreen-{VERSION}.jar.

Agent in repository

Download the sqreen.jar 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'

Modify Java command line parameters

Set the -javaagent command line parameter in the app's Procfile:

web: java -javaagent:/app/sqreen.jar -jar your-app-1.0.jar

Multiple agents

If there is more than one agent configured (-javaagent parameters), make sure Sqreen is the last in the command line.

Then, commit your changes and deploy your updated application.

git add ./Procfile
git commit -m 'Configure Sqreen agent'

# redeploys your app with the Sqreen agent
git push heroku master

The Sqreen Add-on for Heroku automatically provides the SQREEN_TOKEN environment variable.

More information on Heroku

Learn more about using Sqreen with Heroku on the Heroku Marketplace:
Sqreen Heroku Addon
Sqreen Heroku Documentation

Agent logging & troubleshooting

By default, Sqreen agent writes its log to the filesystem in /tmp/sqreen.log, and this approach does not works well with Heroku because log files are lost on each deployment/restart.

Then, in order to access agent logs, the best option is to configure agent to write them to standard output

To do so, you have to set SQREEN_LOG_LOCATION=/dev/stdout environment variable.

Also, for troubleshooting, it might be relevant to use debug logging with SQREEN_LOG_LEVEL=debug environment variable.

Please note that those settings will require JVM restart to be effective.