Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0d3f9a5
Update Logback guide to 3.0.
maciejwalkowiak Sep 10, 2020
5ed87c1
Update Logback guide to 3.0.
maciejwalkowiak Sep 10, 2020
d376f58
Update Logback guide to 3.0.
maciejwalkowiak Sep 10, 2020
aaebbd8
Update Log4j2 guide to 3.0.
maciejwalkowiak Sep 10, 2020
7e778e4
Delete obsolete guides.
maciejwalkowiak Sep 10, 2020
0beeb2a
Merge remote-tracking branch 'origin/master' into sentry-java-3.0
maciejwalkowiak Sep 10, 2020
4720a47
Update Spring guide to 3.0.
maciejwalkowiak Sep 10, 2020
7f12d04
Initial Spring Boot guide.
maciejwalkowiak Sep 10, 2020
6d20926
Manual usage.
maciejwalkowiak Sep 15, 2020
0a15a25
Update Context/Scope section.
maciejwalkowiak Sep 15, 2020
09e2b07
Configuration options.
maciejwalkowiak Sep 15, 2020
0b37452
Merge remote-tracking branch 'origin/master' into sentry-java-3.0
maciejwalkowiak Sep 15, 2020
4a60c53
Update release and environments docs.
maciejwalkowiak Sep 15, 2020
c7f8597
Bring back legacy Java SDK docs.
maciejwalkowiak Sep 16, 2020
5934aa7
Update legacy docs.
maciejwalkowiak Sep 17, 2020
3b4f614
Merge remote-tracking branch 'origin/master' into sentry-java-3.0
maciejwalkowiak Sep 17, 2020
33b8614
Update legacy docs.
maciejwalkowiak Sep 17, 2020
32ca947
Update legacy docs.
maciejwalkowiak Sep 17, 2020
95c0478
Filled common docs gaps.
maciejwalkowiak Sep 17, 2020
1bf5bbc
Update Spring docs.
maciejwalkowiak Sep 17, 2020
28f62ab
Merge remote-tracking branch 'origin/master' into sentry-java-3.0
maciejwalkowiak Sep 22, 2020
ed9d787
Apply suggestions from code review
maciejwalkowiak Sep 29, 2020
51798e1
Merge remote-tracking branch 'origin/master' into sentry-java-3.0
maciejwalkowiak Sep 29, 2020
8c98e5f
Point to Spring Boot guide from the docs home page.
maciejwalkowiak Sep 29, 2020
3cae76a
Update Logback + Spring Boot guide.
maciejwalkowiak Sep 29, 2020
8d9f532
Update broken links.
maciejwalkowiak Sep 29, 2020
d5dc859
Update broken links.
maciejwalkowiak Sep 29, 2020
4f7c2a8
Update docs with external configuration.
maciejwalkowiak Sep 29, 2020
7083d4f
Update Spring + Logback.
maciejwalkowiak Sep 29, 2020
617b7e1
Merge remote-tracking branch 'origin/master' into sentry-java-3.0
maciejwalkowiak Sep 29, 2020
a25b193
Update Spring + Logback.
maciejwalkowiak Sep 30, 2020
4020336
Update Spring guide.
maciejwalkowiak Sep 30, 2020
06cbd0f
Apply suggestions from code review
maciejwalkowiak Sep 30, 2020
bccb071
Merge remote-tracking branch 'origin/master' into sentry-java-3.0
maciejwalkowiak Sep 30, 2020
6ed1044
Move migration docs under legacy.
maciejwalkowiak Sep 30, 2020
60ef121
Apply suggestions from code review
maciejwalkowiak Sep 30, 2020
bb00175
Remove unused import
maciejwalkowiak Sep 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/docs/accounts/quotas/manage-event-stream-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Check out additional configuration options with the [TryCatch](/platforms/javasc

### Other SDKs

**Java** - Sentry SDK provides integrations with common Java loggers through implemented _Handlers_ and _Appenders_. The configuration allows you to set a logging threshold determining the level under which all errors will be filtered. For more information see Java Integrations [java.util.logging](/platforms/java/guides/logging/), [Log4j 1.x](/platforms/java/guides/log4j/), [Log4j 2.x](/platforms/java/guides/log4j2/), and [Logback](/platforms/java/guides/logback/).
**Java** - Sentry SDK provides integrations with common Java loggers through implemented _Handlers_ and _Appenders_. The configuration allows you to set a logging threshold determining the level under which all errors will be filtered. For more information see Java Integrations [java.util.logging](/platforms/java/legacy/logging/), [Log4j 1.x](/platforms/java/legacy/log4j/), [Log4j 2.x](/platforms/java/guides/log4j2/), and [Logback](/platforms/java/guides/logback/).

**PHP** - The `error_types` configuration option allows you to set the error types you want Sentry to monitor. For more information see [PHP: Common Options](/platforms/php/configuration/options/#common-options).

Expand Down
11 changes: 11 additions & 0 deletions src/includes/capture-error/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
In Java you can capture any exception object that you caught:

```java
import io.sentry.Sentry;

try {
aMethodThatMightFail();
} catch(Exception e) {
Sentry.captureException(e);
}
```
5 changes: 5 additions & 0 deletions src/includes/capture-message/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```java
import io.sentry.Sentry;

Sentry.captureMessage("Something went wrong");
```
17 changes: 17 additions & 0 deletions src/includes/configuration/before-send/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
A `BiFunction<SentryEvent, Object, SentryEvent>` can be used to mutate, discard (return null), or return a completely new event.

```java
import io.sentry.Sentry;

Sentry.init(
options -> {
options.setBeforeSend(
(event, hint) -> {
// Modify the event here:
event.setServerName(null); // Don't send server names.
return event;
});
});
```

When using [Spring Boot integration](/platforms/java/guides/spring-boot/), `beforeSend` can be registered simply by creating a Spring `bean` implementing `BeforeSendCallback`. See [Spring Boot integration](/platforms/java/guides/spring-boot/#registering-custom-before-send-callback) for more details.
45 changes: 45 additions & 0 deletions src/includes/configuration/config-intro/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Options can be set by passing a callback to the `init()` method which will
pass the option object along for modifications:

```java {tabTitle:Java}
import io.sentry.Sentry;

public class MyClass {
public static void main(String... args) {
Sentry.init(
options -> {
// your Sentry project/dashboard
options.setDsn("___PUBLIC_DSN___");
options.setRelease("[email protected]+1");
options.setBeforeSend(
(event, hint) -> {
// Drop an event altogether:
if (event.getTag("SomeTag") != null) {
return null;
}
return event;
});
});
}
}
```

```kotlin {tabTitle:Kotlin}
import io.sentry.SentryOptions.BeforeSendCallback

fun main() {
Sentry.init {
// your Sentry project/dashboard
it.dsn = "___PUBLIC_DSN___"
it.release = "[email protected]+1"
it.beforeSend = BeforeSendCallback { event: SentryEvent, hint: Any? ->
// Drop an event altogether:
if (event.getTag("SomeTag") != null) {
null
} else {
event
}
}
}
}
```
3 changes: 3 additions & 0 deletions src/includes/configuration/decluttering/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Decluttering Sentry

When used together with one of the logging framework integrations, the Java SDK captures all error logs as events. If you see a particular kind of error very often that has a `logger` tag, you can ignore that particular logger entirely. For more information see our <Link to="/platforms/java/guides/logback/">Logback</Link> or <Link to="/platforms/java/guides/log4j2/">Log4j 2.x</Link> integration.
1 change: 1 addition & 0 deletions src/includes/configuration/drain-example/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Java SDK automatically shuts down on JVM exit and waits `shutdownTimeout` milliseconds before that happens.
8 changes: 8 additions & 0 deletions src/includes/configuration/sample-rate/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```java
import io.sentry.Sentry;

Sentry.init(
options -> {
options.setSampleRate(0.25);
});
```
5 changes: 5 additions & 0 deletions src/includes/set-environment/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```java
Sentry.init(options -> {
options.setEnvironment("production");
});
```
7 changes: 7 additions & 0 deletions src/includes/set-release/java.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```java
Sentry.init(options -> {
options.setRelease("[email protected]");
});
```

When using Sentry in Spring Boot application, thanks to Spring Boot Starter the release field is set automatically. Read more in [Spring Boot Starter](/platforms/java/guides/spring-boot/#using-git-commit-id-as-the-release) guide.
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const HIGHLIGHTED_PLATFORMS = [
"php.laravel",
"android",
"apple",
"java.spring",
"java.spring-boot",
"ruby.rails",
];

Expand Down
16 changes: 8 additions & 8 deletions src/platforms/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ Grouping in Sentry is different for events with stack traces and without. As a r

</markdown></ConfigKey>

<ConfigKey name="send-default-pii" supported={["python"]}><markdown>
<ConfigKey name="send-default-pii" supported={["python", "java"]}><markdown>

If this flag is enabled, certain personally identifiable information (PII) is added by active integrations. By default, no such data is sent.

If possible, we recommended turning on this feature to send all such data by default, and manually remove what you don't want to send using our features for managing [_Sensitive Data_](../../data-management/sensitive-data/).

</markdown></ConfigKey>

<ConfigKey name="server-name" supported={["python", "node", "ruby", "php"]}><markdown>
<ConfigKey name="server-name" supported={["python", "node", "ruby", "php", "java"]}><markdown>

This option can be used to supply a "server name." When provided, the name of the server is sent along and persisted in the event. For many integrations the server name actually corresponds to the device hostname, even in situations where the machine is not actually a server. Most SDKs
will attempt to auto-discover this value.
Expand All @@ -101,13 +101,13 @@ will be sent. This is a "contains" match to the entire file URL. As a result, if

</markdown></ConfigKey>

<ConfigKey name="in-app-include" supported={["python", "rust", "csharp", "php"]}><markdown>
<ConfigKey name="in-app-include" supported={["python", "rust", "csharp", "php", "java"]}><markdown>

A list of string prefixes of module names that belong to the app. This option takes precedence over `in-app-exclude`.

</markdown></ConfigKey>

<ConfigKey name="in-app-exclude" supported={["python", "rust", "csharp", "php"]}><markdown>
<ConfigKey name="in-app-exclude" supported={["python", "rust", "csharp", "php", "java"]}><markdown>

A list of string prefixes of module names that do not belong to the app, but rather to third-party packages. Modules considered not part of the app will be hidden from stack traces by default.

Expand Down Expand Up @@ -177,19 +177,19 @@ The callback typically gets a second argument (called a "hint") which contains t

</markdown></ConfigKey>

<PlatformSection supported={["javascript", "python", "node", "php"]}><markdown>
<PlatformSection supported={["javascript", "java", "python", "node", "php"]}><markdown>

## Transport Options

Transports are used to send events to Sentry. Transports can be customized to some degree to better support highly specific deployments.

<ConfigKey name="transport" supported={["javascript", "php", "python"]}><markdown>
<ConfigKey name="transport" supported={["javascript", "php", "python", "java"]}><markdown>

Switches out the transport used to send events. How this works depends on the SDK. It can, for instance, be used to capture events for unit-testing or to send it through some more complex setup that requires proxy authentication.

</markdown></ConfigKey>

<ConfigKey name="http-proxy" supported={["node", "php", "python"]}><markdown>
<ConfigKey name="http-proxy" supported={["node", "php", "python", "java"]}><markdown>

When set, a proxy can be configured that should be used for outbound requests. This is also used for HTTPS requests unless a separate `https-proxy` is configured. However, not all SDKs support a separate HTTPS proxy. SDKs will attempt to default to the system-wide configured proxy, if possible. For instance, on Unix systems, the `http_proxy` environment variable will be picked up.

Expand All @@ -201,7 +201,7 @@ Configures a separate proxy for outgoing HTTPS requests. This value might not be

</markdown></ConfigKey>

<ConfigKey name="shutdown-timeout" supported={["python", "node"]}><markdown>
<ConfigKey name="shutdown-timeout" supported={["python", "node", "java"]}><markdown>

Controls how many seconds to wait before shutting down. Sentry SDKs send events from a background queue. This queue is given a certain amount to drain pending events. The default is SDK specific but typically around two seconds. Setting this value too low may cause problems for sending events from command line applications. Setting the value too high will cause the application to block for a long time for users experiencing network connectivity problems.

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/common/configuration/releases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A release is a version of your code that is deployed to an environment. When you
- Resolve issues by including the issue number in your commit message
- Receive email notifications when your code gets deployed

<PlatformSection supported={["javascript", "node"]}><markdown>
<PlatformSection supported={["javascript", "node", "java"]}><markdown>

Additionally, releases are used for applying [source maps](/platforms/javascript/sourcemaps/) to minified JavaScript to view original, untransformed source code.

Expand Down
165 changes: 165 additions & 0 deletions src/platforms/java/common/configuration/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---
title: Configuration
sidebar_order: 10
description: "Learn more about how to configure the SDK. These options are set when the SDK is first initialized, passed to the `init()` as an object."
---

## Setting the DSN (Data Source Name) {#setting-the-dsn}

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](#configuration-methods).

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

```text {tabTitle:Properties File} {filename:sentry.properties}
dsn=___PUBLIC_DSN___
```

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

```bash {tabTitle:Java System Properties}
java -Dsentry.dsn=___PUBLIC_DSN___ -jar app.jar
```

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

```bash {tabTitle:System Environment Variable}
SENTRY_DSN=___PUBLIC_DSN___ java -jar app.jar
```

In code:

```java
import io.sentry.Sentry;

Sentry.init(options -> {
options.setDsn("___PUBLIC_DSN___");
});
```

## Configuration methods {#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`:

```java
import io.sentry.Sentry;

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

### Configuration via properties file

The Java SDK can be configured via a [.properties file](https://en.wikipedia.org/wiki/.properties) 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:

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

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

```bash
SENTRY_ENVIRONMENT=production java -jar app.jar
```

### Configuration via code

The DSN itself can also be configured directly in code:

```java
import io.sentry.Sentry;

Sentry.init(options -> {
options.setDsn("___PUBLIC_DSN___");
});
```

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.0
```

#### Distribution

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

```
release=1.0.0
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:

```
environment=staging
```

### Server Name

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

```
servername=host1
```

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

```bash
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](http://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html) 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
```
Loading