Skip to content

Commit

Permalink
Java docs update (#2708)
Browse files Browse the repository at this point in the history
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
  • Loading branch information
maciejwalkowiak and marandaneto authored Nov 24, 2020
1 parent 39279be commit a4f5ffe
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 38 deletions.
11 changes: 11 additions & 0 deletions src/includes/getting-started-config/java.spring-boot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ sentry:
dsn: ___PUBLIC_DSN___
```
By default, every unhandled exception is sent to Sentry, even those captured with `@ExceptionHandler` annotated methods. This behavior can be tuned through configuring `sentry.exception-resolver-order` property. For example, setting it to `2147483647` (the value of `org.springframework.core.Ordered#LOWEST_PRECEDENCE`) makes sure only exceptions that have not been handled by exception resolvers with higher order are sent to Sentry.

```properties {filename:application.properties}
sentry.exception-resolver-order=2147483647
```

```yaml {filename:application.yml}
sentry:
exception-resolver-order: 2147483647
```

We recommend using Sentry's Spring Boot integration with one of the [logging framework integrations](logging-frameworks/) as they work together seamlessly. To use Sentry **without** Spring Boot, we recommend using the [Sentry Spring integration](/platforms/java/guides/spring/).

Once this integration is configured you can _also_ use Sentry’s static API, [as shown on the usage page](usage/), to record breadcrumbs, set the current user, or manually send events, for example.
24 changes: 24 additions & 0 deletions src/includes/getting-started-config/java.spring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,27 @@ class SentryConfiguration
The DSN can be also provided through the system property `sentry.dsn`, environment variable `SENTRY_DSN` or the `dsn` property in `sentry.properties` file. [See the configuration page](/platforms/java/configuration/) for more details on external configuration.

Once this integration is configured you can _also_ use Sentry’s static API, [as shown on the usage page](usage/), to record breadcrumbs, set the current user, or manually send events, for example.

By default, every unhandled exception is sent to Sentry, even those captured with `@ExceptionHandler` annotated methods. This behavior can be tuned through configuring `exceptionResolverOrder` property on `@EnableSentry` annotation. For example, setting it to `Ordered.LOWEST_PRECEDENCE` makes sure only exceptions that have not been handled by exception resolvers with higher order are sent to Sentry.

```java {tabTitle:Java}
import io.sentry.spring.EnableSentry;
import org.springframework.core.Ordered;
// NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry
// project/dashboard
@EnableSentry(
dsn = "___PUBLIC_DSN___",
exceptionResolverOrder = Ordered.LOWEST_PRECEDENCE
)
```

```kotlin {tabTitle:Kotlin}
import io.sentry.spring.EnableSentry
import org.springframework.core.Ordered;
// NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry
// project/dashboard
@EnableSentry(
dsn = "___PUBLIC_DSN___",
exceptionResolverOrder = Ordered.LOWEST_PRECEDENCE
)
```
6 changes: 3 additions & 3 deletions src/includes/getting-started-install/java.log4j2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j2</artifactId>
<version>{{ packages.version('sentry.java', '3.1.1') }}</version>
<version>{{ packages.version('sentry.java', '3.2.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-log4j2:{{ packages.version('sentry.java', '3.1.1') }}'
implementation 'io.sentry:sentry-log4j2:{{ packages.version('sentry.java', '3.2.0') }}'
```

```scala {tabTitle: SBT}
libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{ packages.version('sentry.java', '3.1.1') }}"
libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{ packages.version('sentry.java', '3.2.0') }}"
```

For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-log4j2).
4 changes: 2 additions & 2 deletions src/includes/getting-started-install/java.spring-boot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring-boot-starter</artifactId>
<version>{{ packages.version('sentry.java', '3.1.1') }}</version>
<version>{{ packages.version('sentry.java', '3.2.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-spring-boot-starter:{{ packages.version('sentry.java', '3.1.1') }}'
implementation 'io.sentry:sentry-spring-boot-starter:{{ packages.version('sentry.java', '3.2.0') }}'
```
6 changes: 3 additions & 3 deletions src/includes/getting-started-install/java.spring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring</artifactId>
<version>{{ packages.version('sentry.java', '3.1.1') }}</version>
<version>{{ packages.version('sentry.java', '3.2.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-spring:{{ packages.version('sentry.java', '3.1.1') }}'
implementation 'io.sentry:sentry-spring:{{ packages.version('sentry.java', '3.2.0') }}'
```

```scala {tabTitle: SBT}
libraryDependencies += "io.sentry" % "sentry-spring" % "{{ packages.version('sentry.java', '3.1.1') }}"
libraryDependencies += "io.sentry" % "sentry-spring" % "{{ packages.version('sentry.java', '3.2.0') }}"
```

For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-spring).
32 changes: 15 additions & 17 deletions src/platforms/java/common/configuration/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Sentry.init(options -> {
});
```

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 {#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.
Expand Down Expand Up @@ -80,20 +89,6 @@ System Environment Variable option names require that you replace the `.` with `
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.
Expand Down Expand Up @@ -170,7 +165,10 @@ See [Java Networking and Proxies](http://docs.oracle.com/javase/8/docs/technotes

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
```properties
http.host=proxy.example.com
# optional
http.port=8080 # default 80
http.user=proxy-user
http.pass=proxy-password
```
4 changes: 2 additions & 2 deletions src/platforms/java/guides/logback/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ The source can be found [on GitHub](https://github.com/getsentry/sentry-java/tre
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>{{ packages.version('sentry.java', '3.1.1') }}</version>
<version>{{ packages.version('sentry.java', '3.2.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-logback:{{ packages.version('sentry.java', '3.1.1') }}'
implementation 'io.sentry:sentry-logback:{{ packages.version('sentry.java', '3.2.0') }}'
```

```scala {tabTitle: SBT}
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/java/guides/spring-boot/logging-frameworks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ To use Sentry Logback integration in Spring Boot application you must include a
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>{{ packages.version('sentry.java', '3.1.1') }}</version>
<version>{{ packages.version('sentry.java', '3.2.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-logback:{{ packages.version('sentry.java', '3.1.1') }}'
implementation 'io.sentry:sentry-logback:{{ packages.version('sentry.java', '3.2.0') }}'
```

Minimum logging levels for `SentryAppender` can be configured in `application.properties` or `application.yml` file.
Expand Down
10 changes: 5 additions & 5 deletions src/platforms/java/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ description: "Learn more about passing configuration options to a static Sentry#
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry:3.1.1'
implementation 'io.sentry:sentry:3.2.0'
```

```scala {tabTitle:SBT}
libraryDependencies += "io.sentry" % "sentry" % "3.1.1"
libraryDependencies += "io.sentry" % "sentry" % "3.2.0"
```

For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-spring).
Expand All @@ -47,7 +47,7 @@ public class MyClass {

// All events get assigned to the release. See more at
// https://docs.sentry.io/workflow/releases/
options.setRelease("io.sentry.samples.console@3.1.1+1");
options.setRelease("io.sentry.samples.console@3.2.0+1");

// Modifications to event before it goes out. Could replace the event altogether
options.setBeforeSend(
Expand Down Expand Up @@ -103,7 +103,7 @@ fun main() {

// All events get assigned to the release. See more at
// https://docs.sentry.io/workflow/releases/
it.release = "io.sentry.samples.console@3.1.1+1"
it.release = "io.sentry.samples.console@3.2.0+1"

// Modifications to event before it goes out. Could replace the event altogether
it.beforeSend = BeforeSendCallback { event: SentryEvent, hint: Any? ->
Expand Down
8 changes: 4 additions & 4 deletions src/wizard/java/spring-boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Install the SDK via Maven or Gradle:
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring-boot-starter</artifactId>
<version>{{ packages.version('sentry.java', '3.1.1') }}</version>
<version>{{ packages.version('sentry.java', '3.2.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-spring-boot-starter:{{ packages.version('sentry.java', '3.1.1') }}'
implementation 'io.sentry:sentry-spring-boot-starter:{{ packages.version('sentry.java', '3.2.0') }}'
```

### Configure
Expand All @@ -46,12 +46,12 @@ Add a dependency to `sentry-logback` module and Sentry Spring Boot Starter will
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>{{ packages.version('sentry.java', '3.1.1') }}</version>
<version>{{ packages.version('sentry.java', '3.2.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-logback:{{ packages.version('sentry.java', '3.1.1') }}'
implementation 'io.sentry:sentry-logback:{{ packages.version('sentry.java', '3.2.0') }}'
```

### Send First Event
Expand Down

1 comment on commit a4f5ffe

@vercel
Copy link

@vercel vercel bot commented on a4f5ffe Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.