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.propertiesdsn=https://examplePublicKey@o0.ingest.sentry.io/0Via the Java System Properties (not available on Android):
java -Dsentry.dsn=https://examplePublicKey@o0.ingest.sentry.io/0 -jar app.jarVia a System Environment Variable (not available on Android):
SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0 java -jar app.jarIn code:
import io.sentry.Sentry;
Sentry.init(options -> {
options.setDsn("https://examplePublicKey@o0.ingest.sentry.io/0");
});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 -> {
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:
environment=productionConfiguration 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.jarSystem 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.jarConfiguration via code
The DSN itself can also be configured directly in code:
import io.sentry.Sentry;
Sentry.init(options -> {
options.setDsn("https://examplePublicKey@o0.ingest.sentry.io/0");
});By passing a hardcoded DSN you are no longer able to override the DSN at runtime via Java System Properties or System Environment Variables.
Options
The following options can all be configured as described above: via a sentry.properties file, via Java System Properties, via System Environment variables, or via the DSN.
Release
To set the application version that will be sent with each event, use the release option:
release=1.0.0Distribution
To set the application distribution that will be sent with each event, use the dist option:
release=1.0.0
dist=x86The 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:
environment=stagingServer Name
To set the server name that will be sent with each event, use the servername option:
servername=host1Using 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.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” \
\
MyAppSee 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),
http.proxy.host=proxy.example.com
http.proxy.port=8080