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

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

java -Dsentry.dsn= -jar app.jar

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

SENTRY_DSN= java -jar app.jar

In code:

import io.sentry.Sentry;

Sentry.init(options -> {

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

  • system properties
  • environment variables
  • file which location is resolved from the system property
  • file which location is resolved from the environment SENTRY_PROPERTIES_FILE
  • 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:

import io.sentry.Sentry;

Sentry.init(options -> {

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


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:

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:

SENTRY_ENVIRONMENT=production java -jar app.jar


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


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



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


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


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


Server Name

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



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


Configuring Timeouts

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

Sentry.init(options -> {

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),

java \
  # if you are using the HTTP protocol \ \
  -Dhttp.proxyPort=8080 \
  # if you are using the HTTPS protocol \ \
  -Dhttps.proxyPort=8080 \
  # relevant to both HTTP and HTTPS
  -Dhttp.nonProxyHosts=”localhost|” \

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),

# optional
proxy.port=8080 # default 80
You can edit this page on GitHub.