diff --git a/docs/platforms/java/guides/spring-boot/logging-frameworks/index.mdx b/docs/platforms/java/guides/spring-boot/logging-frameworks/index.mdx new file mode 100644 index 0000000000000..88d692b7c962b --- /dev/null +++ b/docs/platforms/java/guides/spring-boot/logging-frameworks/index.mdx @@ -0,0 +1,11 @@ +--- +title: Logging Framework Integrations +sidebar_order: 6 +description: "Learn more about using one of our logging integrations with Sentry Spring Boot." +--- + +## Supported Logging Frameworks + +Sentry provides integrations for the following logging frameworks with Spring Boot: + + diff --git a/docs/platforms/java/guides/spring-boot/logging-frameworks/log4j2.mdx b/docs/platforms/java/guides/spring-boot/logging-frameworks/log4j2.mdx new file mode 100644 index 0000000000000..746293f572de8 --- /dev/null +++ b/docs/platforms/java/guides/spring-boot/logging-frameworks/log4j2.mdx @@ -0,0 +1,81 @@ +--- +title: Log4j 2 Integration +description: "Learn how to use Sentry's Log4j 2 integration with Spring Boot." +--- + +For the best experience, we recommend using Sentry's Spring Boot integration with the Log4j 2 logging framework integration as they work together seamlessly. + + + +By default this integration captures logs as breadcrumbs and error events (great for error context!). But if you need to search and query your logs across your entire application, we recommend enabling the new logs feature. Logs at or above the `minimumLevel` are automatically sent as Sentry Logs when enabled. + + + +## Installation + +To use Sentry's Log4j 2 integration in Spring Boot application, you must include a dependency to the `sentry-log4j2` module: + +```xml {tabTitle:Maven} + + io.sentry + sentry-log4j2 + {{@inject packages.version('sentry.java.log4j2', '5.1.1') }} + +``` + +```groovy {tabTitle:Gradle} +implementation 'io.sentry:sentry-log4j2:{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}' +``` + +```scala {tabTitle: SBT} +libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}" +``` + +For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-log4j2). + +## Configuration + +### Spring Boot Configuration + +To send logs to Sentry and have them show up in the Logs section, you need to enable the feature: + +```properties +sentry.logs.enabled=true +``` + +### XML Configuration + +[Follow the guide on configuring Log4j 2 with Spring Boot](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-configure-log4j-for-logging) and configure `SentryAppender` in the `log4j2.xml` file: + +```xml + + + + + + + + + + + + + + + + + + +``` + + + +You do not need to configure your DSN in the Log4j 2 configuration file since Sentry is configured from the Spring Boot integration. + +However, if errors that may appear during startup should to be sent to Sentry, the DSN must be provided to both the Log4j 2 and Spring Boot configurations. + + + +## Mapped Diagnostic Context (MDC) + +Starting with Sentry Java SDK version 8.24.0, you can use the `contextTags` option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry. diff --git a/docs/platforms/java/guides/spring-boot/logging-frameworks.mdx b/docs/platforms/java/guides/spring-boot/logging-frameworks/logback.mdx similarity index 53% rename from docs/platforms/java/guides/spring-boot/logging-frameworks.mdx rename to docs/platforms/java/guides/spring-boot/logging-frameworks/logback.mdx index 5fc7aaee7f499..7268412a89fed 100644 --- a/docs/platforms/java/guides/spring-boot/logging-frameworks.mdx +++ b/docs/platforms/java/guides/spring-boot/logging-frameworks/logback.mdx @@ -1,12 +1,17 @@ --- -title: Logging Framework Integrations -sidebar_order: 6 -description: "Learn more about using one of our logging integrations with Sentry Spring Boot." +title: Logback Integration +description: "Learn how to use Sentry's Logback integration with Spring Boot." --- -For the best experience, we recommend using Sentry's Spring Boot integration with one of the logging framework integrations as they work together seamlessly. +For the best experience, we recommend using Sentry's Spring Boot integration with the Logback logging framework integration as they work together seamlessly. -### Logback + + +By default this integration captures logs as breadcrumbs and error events (great for error context!). But if you need to search and query your logs across your entire application, we recommend enabling the new logs feature. Logs at or above the `sentry.logging.minimum-level` are automatically sent as Sentry Logs when enabled. + + + +## Installation To use Sentry Logback integration in Spring Boot application you must include a dependency to the `sentry-logback` module, then Sentry's Spring Boot Starter will auto-configure `SentryAppender`: @@ -22,6 +27,16 @@ To use Sentry Logback integration in Spring Boot application you must include a implementation 'io.sentry:sentry-logback:{{@inject packages.version('sentry.java.logback', '4.2.0') }}' ``` +## Configuration + +### Spring Boot Configuration + +To send logs to Sentry and have them show up in the Logs section, you need to enable the feature: + +```properties +sentry.logs.enabled=true +``` + Minimum logging levels for `SentryAppender` can be configured in `application.properties` or `application.yml` file. ```properties @@ -36,18 +51,14 @@ The default values are: - `info` or higher will send a log message to Sentry and will show up in the Logs section. - `error` or higher will send an event to Sentry and will show up in the Issues section. -To send logs to Sentry and have them show up in the Logs section, you need to enable the feature: - -```properties -sentry.logs.enabled=true -``` - When `SentryAppender` auto-configuration does not suit your needs, it can be turned off by setting: ```properties sentry.logging.enabled=false ``` +### XML Configuration + If you decide to opt-out from the `application.properties` based Spring Boot logging configuration, and instead configure logging in the `logback-spring.xml` file, the `SentryAppender` can be configured as follows: ```xml @@ -56,7 +67,9 @@ If you decide to opt-out from the `application.properties` based Spring Boot log - + + INFO + @@ -73,63 +86,6 @@ However, if errors that may appear during startup should to be sent to Sentry, t -#### Mapped Diagnostic Context (MDC) - -Starting with Sentry Java SDK version 8.24.0, you can use the `contextTags` option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry. - -### Log4j 2 - -To use Sentry's Log4j 2 integration in Spring Boot application, you must include a dependency to the `sentry-log4j2` module: - -```xml {tabTitle:Maven} - - io.sentry - sentry-log4j2 - {{@inject packages.version('sentry.java.log4j2', '5.1.1') }} - -``` - -```groovy {tabTitle:Gradle} -implementation 'io.sentry:sentry-log4j2:{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}' -``` - -```scala {tabTitle: SBT} -libraryDependencies += "io.sentry" % "sentry-log4j2" % "{{@inject packages.version('sentry.java.log4j2', '5.1.1') }}" -``` - -For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-log4j2). - -Then [follow the guide on configuring Log4j 2 with Spring Boot](https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-configure-log4j-for-logging) and configure `SentryAppender` in the `log4j2.xml` file: - -```xml - - - - - - - - - - - - - - - - - - -``` - - - -You do not need to configure your DSN in the Log4j 2 configuration file since Sentry is configured from the Spring Boot integration. - -However, if errors that may appear during startup should to be sent to Sentry, the DSN must be provided to both the Log4j 2 and Spring Boot configurations. - - - -#### Mapped Diagnostic Context (MDC) +## Mapped Diagnostic Context (MDC) Starting with Sentry Java SDK version 8.24.0, you can use the `contextTags` option to include specific properties from the Mapped Diagnostic Context (MDC) as attributes on log entries sent to Sentry. diff --git a/platform-includes/getting-started-config/java.jul.mdx b/platform-includes/getting-started-config/java.jul.mdx index 0a523ab7b22d2..40bdc1d56e638 100644 --- a/platform-includes/getting-started-config/java.jul.mdx +++ b/platform-includes/getting-started-config/java.jul.mdx @@ -38,6 +38,10 @@ dsn=___PUBLIC_DSN___ # Add data like request headers and IP for users, # see https://docs.sentry.io/platforms/java/guides/jul/data-management/data-collected/ for more info send-default-pii=true + +# Enable logs +logs.enabled=true + ``` @@ -47,6 +51,9 @@ Two log levels are used to configure this integration: 1. Configure the lowest level required for a log message to become an event (`minimumEventLevel`) sent to Sentry. 2. Configure the lowest level a message has to be to become a breadcrumb (`minimumBreadcrumbLevel`). + +3. Configure the lowest level a message has to be to be sent as Sentry Log (`minimumLevel`). + diff --git a/platform-includes/getting-started-config/java.log4j2.mdx b/platform-includes/getting-started-config/java.log4j2.mdx index 73bbfc870b513..ad63de687fce7 100644 --- a/platform-includes/getting-started-config/java.log4j2.mdx +++ b/platform-includes/getting-started-config/java.log4j2.mdx @@ -71,6 +71,9 @@ If the DSN is not present in the `log4j2.xml` configuration, Sentry will attempt # Add data like request headers and IP for users, # see https://docs.sentry.io/platforms/java/guides/log4j2/data-management/data-collected/ for more info send-default-pii=true +// ___PRODUCT_OPTION_START___ logs +logs.enabled=true +// ___PRODUCT_OPTION_END___ logs ``` @@ -80,6 +83,9 @@ Two log levels are used to configure this integration, as illustrated below in t 1. Configure the lowest level required for a log message to become an event (`minimumEventLevel`) sent to Sentry. 2. Configure the lowest level a message has to be to become a breadcrumb (`minimumBreadcrumbLevel`) + +3. Configure the lowest level a message has to be to be sent as Sentry Log (`minimumLevel`). + @@ -96,7 +102,11 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi + minimumEventLevel="WARN" + + minimumLevel="DEBUG" + + /> ``` @@ -105,6 +115,10 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi + minimumEventLevel="WARN" + + minimumLevel="DEBUG" + + /> ``` diff --git a/platform-includes/getting-started-config/java.logback.mdx b/platform-includes/getting-started-config/java.logback.mdx index 4f3b567740500..1fdfe1b3dc621 100644 --- a/platform-includes/getting-started-config/java.logback.mdx +++ b/platform-includes/getting-started-config/java.logback.mdx @@ -25,6 +25,11 @@ The `ConsoleAppender` is provided only as an example of a non-Sentry appender se ___PUBLIC_DSN___ true + // ___PRODUCT_OPTION_START___ logs + + true + + // ___PRODUCT_OPTION_END___ logs @@ -87,6 +92,9 @@ Two log levels are used to configure this integration: 1. Configure the lowest level required for a log message to become an event (`minimumEventLevel`) sent to Sentry. 2. Configure the lowest level a message has to be to become a breadcrumb (`minimumBreadcrumbLevel`). + +3. Configure the lowest level a message has to be to be sent as Sentry Log (`minimumLevel`). + @@ -110,6 +118,10 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi WARN DEBUG + // ___PRODUCT_OPTION_START___ logs + + DEBUG + // ___PRODUCT_OPTION_END___ logs ``` @@ -121,6 +133,10 @@ Breadcrumbs are kept in memory (by default the last 100 records) and are sent wi WARN DEBUG + // ___PRODUCT_OPTION_START___ logs + + DEBUG + // ___PRODUCT_OPTION_END___ logs ``` diff --git a/platform-includes/getting-started-config/java.mdx b/platform-includes/getting-started-config/java.mdx index c725f2f74a013..3ab8bbd95cbed 100644 --- a/platform-includes/getting-started-config/java.mdx +++ b/platform-includes/getting-started-config/java.mdx @@ -60,4 +60,11 @@ Sentry.init { options -> // ___PRODUCT_OPTION_END___ logs } ``` + + + +Learn more about setting up logging in our Logs documentation. + + + diff --git a/platform-includes/getting-started-config/java.servlet.mdx b/platform-includes/getting-started-config/java.servlet.mdx index bb32e8df3701e..d881ae1dcc8e2 100644 --- a/platform-includes/getting-started-config/java.servlet.mdx +++ b/platform-includes/getting-started-config/java.servlet.mdx @@ -22,6 +22,24 @@ public final class SentryInitializer implements ServletContainerInitializer { // Add data like request headers and IP for users, // see https://docs.sentry.io/platforms/java/guides/servlet/data-management/data-collected/ for more info options.setSendDefaultPii(true); + // ___PRODUCT_OPTION_START___ performance + + // Set traces_sample_rate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production. + options.setTracesSampleRate(1.0); + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ profiling + + // Enable profiling + options.setProfileSessionSampleRate(1.0); + options.setProfileLifecycle(ProfileLifecycle.TRACE); + // ___PRODUCT_OPTION_END___ profiling + // ___PRODUCT_OPTION_START___ logs + + // Enable logs to be sent to Sentry + options.getLogs().setEnabled(true); + // ___PRODUCT_OPTION_END___ logs }); } } @@ -43,10 +61,35 @@ class SentryInitializer : ServletContainerInitializer { // Add data like request headers and IP for users, // see https://docs.sentry.io/platforms/java/guides/servlet/data-management/data-collected/ for more info options.isSendDefaultPii = true + // ___PRODUCT_OPTION_START___ performance + + // Set traces_sample_rate to 1.0 to capture 100% + // of transactions for tracing. + // We recommend adjusting this value in production. + options.tracesSampleRate = 1.0 + // ___PRODUCT_OPTION_END___ performance + // ___PRODUCT_OPTION_START___ profiling + + // Enable profiling + options.profileSessionSampleRate = 1.0 + options.profileLifecycle = ProfileLifecycle.TRACE + // ___PRODUCT_OPTION_END___ profiling + // ___PRODUCT_OPTION_START___ logs + + // Enable logs to be sent to Sentry + options.logs.enabled = true + // ___PRODUCT_OPTION_END___ logs } } } ``` + + + +Learn more about setting up logging in our Logs documentation. + + + Create a file in `src/main/resources/META-INF/services` named `javax.servlet.ServletContainerInitializer`, with a full name of your custom `SentryInitializer` class as a content: diff --git a/platform-includes/getting-started-config/java.spring-boot.mdx b/platform-includes/getting-started-config/java.spring-boot.mdx index 8dfcda7535ed2..bacb025bc1908 100644 --- a/platform-includes/getting-started-config/java.spring-boot.mdx +++ b/platform-includes/getting-started-config/java.spring-boot.mdx @@ -22,6 +22,11 @@ sentry.traces-sample-rate=1.0 sentry.profile-session-sample-rate=1.0 sentry.profile-lifecycle=TRACE // ___PRODUCT_OPTION_END___ profiling +// ___PRODUCT_OPTION_START___ logs + +# Enable logs +sentry.logs.enabled=true +// ___PRODUCT_OPTION_END___ logs ``` ```yaml {filename:application.yml} @@ -44,6 +49,12 @@ sentry: profileSessionSampleRate: 1.0 profileLifecycle: TRACE // ___PRODUCT_OPTION_END___ profiling + // ___PRODUCT_OPTION_START___ logs + + # Enable logs + logs: + enabled: true + // ___PRODUCT_OPTION_END___ logs ``` By default, only unhandled exceptions are sent to Sentry. This behavior can be tuned through configuring the `sentry.exception-resolver-order` property. For example, setting it to `-2147483647` (the value of `org.springframework.core.Ordered#HIGHEST_PRECEDENCE`) ensures exceptions that have been handled by exception resolvers with higher order are sent to Sentry - including ones handled by `@ExceptionHandler` annotated methods. diff --git a/platform-includes/getting-started-config/java.spring.mdx b/platform-includes/getting-started-config/java.spring.mdx index 12cef2c90b579..fc437a87c88d2 100644 --- a/platform-includes/getting-started-config/java.spring.mdx +++ b/platform-includes/getting-started-config/java.spring.mdx @@ -190,16 +190,21 @@ import org.springframework.core.Ordered class SentryConfiguration ``` - The SDK can be configured using a `sentry.properties` file: ```properties {filename:sentry.properties} +// ___PRODUCT_OPTION_START___ performance +# Enable tracing traces-sample-rate=1.0 +// ___PRODUCT_OPTION_END___ performance // ___PRODUCT_OPTION_START___ profiling # Enable profiling profile-session-sample-rate=1.0 profile-lifecycle=TRACE // ___PRODUCT_OPTION_END___ profiling +// ___PRODUCT_OPTION_START___ logs +# Enable logs +logs.enabled=true +// ___PRODUCT_OPTION_END___ logs ``` - diff --git a/platform-includes/getting-started-config/opentelemetry/java.mdx b/platform-includes/getting-started-config/opentelemetry/java.mdx index de03b54463cc0..a3d2c434bc21a 100644 --- a/platform-includes/getting-started-config/opentelemetry/java.mdx +++ b/platform-includes/getting-started-config/opentelemetry/java.mdx @@ -10,6 +10,9 @@ send-default-pii=true # ___PRODUCT_OPTION_START___ performance traces-sample-rate=1.0 # ___PRODUCT_OPTION_END___ performance +// ___PRODUCT_OPTION_START___ logs +logs.enabled=true +// ___PRODUCT_OPTION_END___ logs // ___PRODUCT_OPTION_START___ profiling # Enable profiling @@ -17,4 +20,12 @@ profile-session-sample-rate=1.0 profile-lifecycle=TRACE // ___PRODUCT_OPTION_END___ profiling ``` + + + + +Learn more about setting up logging in our Logs documentation. + + + diff --git a/platform-includes/getting-started-install/java.jul.mdx b/platform-includes/getting-started-install/java.jul.mdx index 86761ceec1eb6..e91230044175e 100644 --- a/platform-includes/getting-started-install/java.jul.mdx +++ b/platform-includes/getting-started-install/java.jul.mdx @@ -1,5 +1,5 @@ ```xml {tabTitle:Maven} diff --git a/platform-includes/getting-started-install/java.log4j2.mdx b/platform-includes/getting-started-install/java.log4j2.mdx index 38b873980673e..53532e6e46d15 100644 --- a/platform-includes/getting-started-install/java.log4j2.mdx +++ b/platform-includes/getting-started-install/java.log4j2.mdx @@ -1,5 +1,5 @@ ```xml {tabTitle:Maven Plugin}{filename:pom.xml} diff --git a/platform-includes/getting-started-install/java.logback.mdx b/platform-includes/getting-started-install/java.logback.mdx index 1f9d275a3cc91..fb588c9f355ea 100644 --- a/platform-includes/getting-started-install/java.logback.mdx +++ b/platform-includes/getting-started-install/java.logback.mdx @@ -1,5 +1,5 @@ ```xml {tabTitle:Maven Plugin}{filename:pom.xml} diff --git a/platform-includes/getting-started-install/java.servlet.mdx b/platform-includes/getting-started-install/java.servlet.mdx index 3e33f8234d034..e214803352595 100644 --- a/platform-includes/getting-started-install/java.servlet.mdx +++ b/platform-includes/getting-started-install/java.servlet.mdx @@ -1,5 +1,5 @@ ```xml {tabTitle:Maven} diff --git a/platform-includes/getting-started-install/java.spring-boot.mdx b/platform-includes/getting-started-install/java.spring-boot.mdx index edb95bc06580c..cb8a54531752c 100644 --- a/platform-includes/getting-started-install/java.spring-boot.mdx +++ b/platform-includes/getting-started-install/java.spring-boot.mdx @@ -1,5 +1,5 @@ ```groovy {tabTitle:Gradle Plugin} diff --git a/platform-includes/getting-started-install/java.spring.mdx b/platform-includes/getting-started-install/java.spring.mdx index 7f33d0f534e4c..a5bb24a35b487 100644 --- a/platform-includes/getting-started-install/java.spring.mdx +++ b/platform-includes/getting-started-install/java.spring.mdx @@ -1,5 +1,5 @@ ```groovy {tabTitle:Gradle Plugin} diff --git a/platform-includes/getting-started-primer/java.jul.mdx b/platform-includes/getting-started-primer/java.jul.mdx index 6d4c29d67e15f..91a706a0ef571 100644 --- a/platform-includes/getting-started-primer/java.jul.mdx +++ b/platform-includes/getting-started-primer/java.jul.mdx @@ -4,4 +4,10 @@ The `sentry-jul` library provides a [java.util.logging Handler](http://docs.orac + + + Enable the Sentry Logs feature to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place. + + + Once this integration is configured you can _also_ use Sentry’s static API, as shown on the usage page, in order to do things like record breadcrumbs, set the current user, or manually send events. The source can be found [on GitHub](https://github.com/getsentry/sentry-java/tree/master/sentry-jul). diff --git a/platform-includes/getting-started-primer/java.log4j2.mdx b/platform-includes/getting-started-primer/java.log4j2.mdx index 8d6dd2f15f689..fe7c90d61d521 100644 --- a/platform-includes/getting-started-primer/java.log4j2.mdx +++ b/platform-includes/getting-started-primer/java.log4j2.mdx @@ -4,4 +4,10 @@ The `sentry-log4j2` library provides [Log4j 2.x](https://logging.apache.org/log4 + + + Enable the Sentry Logs feature to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place. + + + Once the integration is configured you can _also_ use Sentry’s static API, [as shown on the usage page](usage/), in order to do things like record breadcrumbs, set the current user, or manually send events. The source can be found [on GitHub](https://github.com/getsentry/sentry-java/tree/master/sentry-log4j2). diff --git a/platform-includes/getting-started-primer/java.logback.mdx b/platform-includes/getting-started-primer/java.logback.mdx index 1b6508c1b726c..63d27a958be47 100644 --- a/platform-includes/getting-started-primer/java.logback.mdx +++ b/platform-includes/getting-started-primer/java.logback.mdx @@ -4,4 +4,10 @@ The `sentry-logback` library provides [Logback](https://logback.qos.ch/) support + + + Enable the Sentry Logs feature to unlock Sentry's full logging power. With Sentry Logs, you can search, filter, and analyze logs from across your entire application in one place. + + + Once this integration is configured you can _also_ use Sentry’s static API, [as shown on the usage page](usage/), in order to do things like record breadcrumbs, set the current user, or manually send events. The source can be found [on GitHub](https://github.com/getsentry/sentry-java/tree/master/sentry-logback). diff --git a/platform-includes/logs/integrations/java.mdx b/platform-includes/logs/integrations/java.mdx index 06b2d5741ba88..de308b84eaee9 100644 --- a/platform-includes/logs/integrations/java.mdx +++ b/platform-includes/logs/integrations/java.mdx @@ -1,5 +1,6 @@ Available integrations: -- [Spring Boot using Logback](/platforms/java/guides/spring-boot/logging-frameworks/) +- [Spring Boot using Logback](/platforms/java/guides/spring-boot/logging-frameworks/logback) +- [Spring Boot using Log4j2](/platforms/java/guides/spring-boot/logging-frameworks/log4j2) - [Logback](/platforms/java/guides/logback/logs/) - [Log4j2](/platforms/java/guides/log4j2/logs/) - [JUL](/platforms/java/guides/jul/logs/)