Configuration

Setting the DSN (Data Source Name)

The DSN is the first and most important thing to configure because it tells the SDK where to send events. You can find your project’s DSN in the “Client Keys” section of your “Project Settings” in Sentry. It can be configured in multiple ways. Explanations of the configuration methods are detailed below.

In a properties file on your filesystem or classpath (defaults to sentry.properties):

sentry.properties
Copied
dsn=https://examplePublicKey@o0.ingest.sentry.io/0

Via the Java System Properties (not available on Android):

Copied
java -Dsentry.dsn=https://examplePublicKey@o0.ingest.sentry.io/0 -jar app.jar

Via a System Environment Variable (not available on Android):

Copied
SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0 java -jar app.jar

In code:

Copied
import io.sentry.Sentry;

Sentry.init(options -> {
  options.setDsn("https://examplePublicKey@o0.ingest.sentry.io/0");
});

When multiple configuration ways are used, options are resolved in the following order:

  • system properties
  • environment variables
  • sentry.properties file which location is resolved from the system property sentry.properties.file
  • sentry.properties file which location is resolved from the environment SENTRY_PROPERTIES_FILE
  • sentry.properties located in the root of the classpath
  • options provided in Java code

Configuration methods

There are multiple ways to configure the Java SDK, but all of them take the same options. See below for how to use each configuration method and how the option names might differ between them.

To enable loading configuration from the properties file, system properties or environment variables, enableExternalConfiguration has to be set to true on SentryOptions:

Copied
import io.sentry.Sentry;

Sentry.init(options -> {
  options.setEnableExternalConfiguration(true);
});

Configuration via properties file

The Java SDK can be configured via a .properties file that is located on the filesystem or in your application’s classpath. By default the SDK will look for a sentry.properties file in the application’s current working directory or in the root of your classpath. In most server side applications the default directory to add resources to your classpath is src/main/resources/, and on Android the default is app/src/main/resources/. You can override the location of the properties file by using either the sentry.properties.file Java System Property or the SENTRY_PROPERTIES_FILE System Environment Variable.

Because this file is often bundled with your application, the values cannot be changed easily once your application has been packaged. For this reason, the properties file is useful for setting defaults or options that you don’t expect to change often. The properties file is the last place checked for each option value, so runtime configuration (described below) will override it if available.

Option names in the property file exactly match the examples given below. For example, to configure the environment, in your properties file:

Copied
environment=production

Configuration via the runtime environment

This is the most flexible method for configuring the Sentry client because it can be easily changed based on the environment you run your application in. Neither Java System Properties or System Environment Variables are available for Android applications. Please configure Sentry for Android via code or the properties file.

Two methods are available for runtime configuration, checked in this order: Java System Properties and System Environment Variables.

Java System Property option names are exactly like the examples given below except that they are prefixed with sentry.. For example, to enable sampling:

Copied
java -Dsentry.environment=production -jar app.jar

System Environment Variable option names require that you replace the . with _, capitalize them, and add a SENTRY_ prefix. For example, to enable sampling:

Copied
SENTRY_ENVIRONMENT=production

Options

The following options can all be configured as described above: via a sentry.properties file, via Java System Properties, via System Environment variables.

Release

To set the application version that will be sent with each event, use the release option:

Copied
release=my-project-name@2.3.12

Distribution

To set the application distribution that will be sent with each event, use the dist option:

Copied
release=my-project-name@2.3.12
dist=x86

The distribution is only useful (and used) if the release is also set.

Environment

To set the application environment that will be sent with each event, use the environment option:

Copied
environment=staging

Server Name

To set the server name that will be sent with each event, use the servername option:

Copied
servername=host1

Tags

To set the common tags that will be sent with each event, use the tags options:

Copied
tags.first_tag=first-tag-value
tags.second_tag=second-tag-value

In App Includes

To set the in-app-includes that will be sent with each event, use the in-app-includes option:

Copied
in-app-includes=com.mycompany,com.other.name

In App Excludes

To set the in-app-excludes that will be sent with each event, use the in-app-excludes option:

Copied
in-app-excludes=host1

Ignored Exceptions For Type

To set exceptions that will be filtered out before sending to Sentry, use the ignored-exceptions-for-type option:

Copied
ignored-exceptions-for-type=java.lang.RuntimeException,java.lang.IllegalStateException

Traces Sample Rate

To set the traces sample rate, use the traces-sample-rate option:

Copied
traces-sample-rate=0.2

Debug

To set Sentry in the debug mode, use the debug option:

Copied
debug=true

Configuring Timeouts

It’s possible to manually set the connection timeouts length with connectionTimeoutMillis and readTimeoutMillis:

Copied
import io.sentry.Sentry;

Sentry.init(options -> {
  options.setConnectionTimeoutMillis(10000);
  options.setReadTimeoutMillis(10000);
});

Using a Proxy

If your application needs to send outbound requests through an HTTP proxy, you can configure the proxy information via JVM networking properties or as a Sentry option.

For example, using JVM networking properties (affects the entire JVM process),

Copied
java \
  # if you are using the HTTP protocol \
  -Dhttp.proxyHost=proxy.example.com \
  -Dhttp.proxyPort=8080 \
  \
  # if you are using the HTTPS protocol \
  -Dhttps.proxyHost=proxy.example.com \
  -Dhttps.proxyPort=8080 \
  \
  # relevant to both HTTP and HTTPS
  -Dhttp.nonProxyHosts=”localhost|host.example.com” \
  \
  MyApp

See Java Networking and Proxies for more information about the proxy properties.

Alternatively, using Sentry options (only affects the Sentry HTTP client, useful inside shared application containers),

Copied
proxy.host=proxy.example.com
# optional
proxy.port=8080 # default 80
proxy.user=proxy-user
proxy.pass=proxy-password

Configuring Offline Caching

The SDK can store events on the disk in case of network errors, and send them to Sentry on another SDK init if the Sentry server is reachable.

To turn on offline caching, set cacheDirPath and add SendCachedEnvelopeFireAndForgetIntegration to Sentry options:

Copied
import io.sentry.SendCachedEnvelopeFireAndForgetIntegration;
import io.sentry.SendFireAndForgetEnvelopeSender;
import io.sentry.Sentry;

Sentry.init(options -> {
  ...
  options.setCacheDirPath("/disk/path");
  options.addIntegration(
    new SendCachedEnvelopeFireAndForgetIntegration(
      new SendFireAndForgetEnvelopeSender(options::getCacheDirPath)
    )
  );
})