Configuration
Learn more about how to configure the SDK. These options are set when the SDK is first initialized, passed to the init method as an object.
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
dsn=___PUBLIC_DSN___
Via the Java System Properties (not available on Android):
java -Dsentry.dsn=https://examplePublicKey@o0.ingest.sentry.io/0 -jar app.jar
Via a System Environment Variable (not available on Android):
SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0 java -jar app.jar
In code:
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 propertysentry.properties.file
sentry.properties
file which location is resolved from the environmentSENTRY_PROPERTIES_FILE
sentry.properties
located in the root of the classpath- options provided in Java code
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);
});
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=production
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
The following options can all be configured as described above: via a sentry.properties
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:
release=my-project-name@2.3.12
To set the application distribution that will be sent with each event, use the dist
option:
release=my-project-name@2.3.12
dist=x86
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:
environment=staging
To set the server name that will be sent with each event, use the servername
option:
servername=host1
To set the common tags that will be sent with each event, use the tags
options:
tags.first_tag=first-tag-value
tags.second_tag=second-tag-value
To set the in-app-includes that will be sent with each event, use the in-app-includes
option:
in-app-includes=com.mycompany,com.other.name
To set the in-app-excludes that will be sent with each event, use the in-app-excludes
option:
in-app-excludes=host1
To set exceptions that will be filtered out before sending to Sentry, use the ignored-exceptions-for-type
option:
ignored-exceptions-for-type=java.lang.RuntimeException,java.lang.IllegalStateException
To set the traces sample rate, use the traces-sample-rate
option:
traces-sample-rate=0.2
To set tracing origins, use the tracing-origins
option:
tracing-origins=localhost,^(http|https)://api\\..*$
To set Sentry in the debug mode, use the debug
option:
debug=true
To disable Sentry, use the enabled
option:
enabled=false
It’s possible to manually set the connection timeouts length with connectionTimeoutMillis
and readTimeoutMillis
:
import io.sentry.Sentry;
Sentry.init(options -> {
options.setConnectionTimeoutMillis(10000);
options.setReadTimeoutMillis(10000);
});
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” \
\
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),
proxy.host=proxy.example.com
# optional
proxy.port=8080 # default 80
proxy.user=proxy-user
proxy.pass=proxy-password
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:
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)
)
);
})
To turn off sending of client reports, use the sendClientReports
option:
send-client-reports=false
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").