From 1b838e5085fada4a949d04ef77c324f16bd96cf9 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 15 Jan 2026 14:37:10 +0100 Subject: [PATCH 1/5] Document Java Metrics --- docs/platforms/android/metrics/index.mdx | 30 +++++ docs/platforms/java/common/crons/index.mdx | 2 +- .../java/common/feature-flags/index.mdx | 2 +- docs/platforms/java/common/gradle/index.mdx | 2 +- docs/platforms/java/common/maven/index.mdx | 2 +- docs/platforms/java/common/metrics/index.mdx | 30 +++++ .../java/common/opentelemetry/index.mdx | 2 +- .../platforms/java/common/profiling/index.mdx | 2 +- .../java/common/user-feedback/index.mdx | 2 +- .../metrics/default-attributes/android.mdx | 20 +++ .../metrics/default-attributes/java.mdx | 20 +++ platform-includes/metrics/options/android.mdx | 69 +++++++++++ platform-includes/metrics/options/java.mdx | 66 ++++++++++ .../metrics/options/java.spring-boot.mdx | 70 +++++++++++ .../metrics/requirements/android.mdx | 1 + .../metrics/requirements/java.mdx | 1 + platform-includes/metrics/usage/android.mdx | 114 ++++++++++++++++++ platform-includes/metrics/usage/java.mdx | 114 ++++++++++++++++++ src/middleware.ts | 8 -- 19 files changed, 542 insertions(+), 15 deletions(-) create mode 100644 docs/platforms/android/metrics/index.mdx create mode 100644 docs/platforms/java/common/metrics/index.mdx create mode 100644 platform-includes/metrics/default-attributes/android.mdx create mode 100644 platform-includes/metrics/default-attributes/java.mdx create mode 100644 platform-includes/metrics/options/android.mdx create mode 100644 platform-includes/metrics/options/java.mdx create mode 100644 platform-includes/metrics/options/java.spring-boot.mdx create mode 100644 platform-includes/metrics/requirements/android.mdx create mode 100644 platform-includes/metrics/requirements/java.mdx create mode 100644 platform-includes/metrics/usage/android.mdx create mode 100644 platform-includes/metrics/usage/java.mdx diff --git a/docs/platforms/android/metrics/index.mdx b/docs/platforms/android/metrics/index.mdx new file mode 100644 index 0000000000000..054b46a924a62 --- /dev/null +++ b/docs/platforms/android/metrics/index.mdx @@ -0,0 +1,30 @@ +--- +title: Set Up Metrics +sidebar_title: Metrics +description: "Metrics allow you to send, view and query counters, gauges and measurements from your Sentry-configured apps to track application health and drill down into related traces, logs, and errors." +sidebar_order: 4500 +sidebar_section: features +beta: true +--- + +With Sentry Metrics, you can send counters, gauges, distributions, and sets from your applications to Sentry. Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes. + + +This feature is currently in open beta. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/discussions/18055) if you have feedback or questions. Features in beta are still in-progress and may have bugs. We recognize the irony. + + +## Requirements + + + +## Usage + + + +## Options + + + +## Default Attributes + + diff --git a/docs/platforms/java/common/crons/index.mdx b/docs/platforms/java/common/crons/index.mdx index c7b132a62216b..8c118fb34b57d 100644 --- a/docs/platforms/java/common/crons/index.mdx +++ b/docs/platforms/java/common/crons/index.mdx @@ -2,7 +2,7 @@ title: Set Up Crons sidebar_title: Crons description: "Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job in your application." -sidebar_order: 5 +sidebar_order: 6 sidebar_section: features --- diff --git a/docs/platforms/java/common/feature-flags/index.mdx b/docs/platforms/java/common/feature-flags/index.mdx index 4a96afc3dc7b9..7b4a1416cea4b 100644 --- a/docs/platforms/java/common/feature-flags/index.mdx +++ b/docs/platforms/java/common/feature-flags/index.mdx @@ -1,7 +1,7 @@ --- title: Set Up Feature Flags sidebar_title: Feature Flags -sidebar_order: 7 +sidebar_order: 8 sidebar_section: features description: With Feature Flags, Sentry tracks feature flag evaluations in your application, keeps an audit log of feature flag changes, and reports any suspicious updates that may have caused an error. --- diff --git a/docs/platforms/java/common/gradle/index.mdx b/docs/platforms/java/common/gradle/index.mdx index 0d3c7f151686a..7fec927f43a40 100644 --- a/docs/platforms/java/common/gradle/index.mdx +++ b/docs/platforms/java/common/gradle/index.mdx @@ -1,7 +1,7 @@ --- title: Gradle description: Learn about using the Sentry Gradle Plugin. -sidebar_order: 8 +sidebar_order: 9 sidebar_section: features og_image: /og-images/platforms-java-common-gradle.png --- diff --git a/docs/platforms/java/common/maven/index.mdx b/docs/platforms/java/common/maven/index.mdx index 7209d70c95dcb..4fd36049aec92 100644 --- a/docs/platforms/java/common/maven/index.mdx +++ b/docs/platforms/java/common/maven/index.mdx @@ -1,7 +1,7 @@ --- title: Maven description: "Learn about using the Sentry Maven Plugin." -sidebar_order: 9 +sidebar_order: 10 sidebar_section: features --- diff --git a/docs/platforms/java/common/metrics/index.mdx b/docs/platforms/java/common/metrics/index.mdx new file mode 100644 index 0000000000000..a1076483c5cc4 --- /dev/null +++ b/docs/platforms/java/common/metrics/index.mdx @@ -0,0 +1,30 @@ +--- +title: Set Up Metrics +sidebar_title: Metrics +description: "Metrics allow you to send, view and query counters, gauges and measurements from your Sentry-configured apps to track application health and drill down into related traces, logs, and errors." +sidebar_order: 4 +sidebar_section: features +beta: true +--- + +With Sentry Metrics, you can send counters, gauges, distributions, and sets from your applications to Sentry. Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes. + + +This feature is currently in open beta. Please reach out on [GitHub](https://github.com/getsentry/sentry/discussions/102275) if you have feedback or questions. Features in beta are still in-progress and may have bugs. We recognize the irony. + + +## Requirements + + + +## Usage + + + +## Options + + + +## Default Attributes + + diff --git a/docs/platforms/java/common/opentelemetry/index.mdx b/docs/platforms/java/common/opentelemetry/index.mdx index 70fc429782681..71f652e813e52 100644 --- a/docs/platforms/java/common/opentelemetry/index.mdx +++ b/docs/platforms/java/common/opentelemetry/index.mdx @@ -2,7 +2,7 @@ title: OpenTelemetry Support sdk: sentry.java.opentelemetry-agent description: "Using OpenTelemetry with Sentry." -sidebar_order: 10 +sidebar_order: 11 sidebar_section: features --- diff --git a/docs/platforms/java/common/profiling/index.mdx b/docs/platforms/java/common/profiling/index.mdx index 108620e3350fe..427290675ea4b 100644 --- a/docs/platforms/java/common/profiling/index.mdx +++ b/docs/platforms/java/common/profiling/index.mdx @@ -2,7 +2,7 @@ title: Set Up Java Profiling sidebar_title: Profiling description: "Learn how to enable profiling in your app if it is not already set up." -sidebar_order: 4 +sidebar_order: 5 sidebar_section: features supported: - java diff --git a/docs/platforms/java/common/user-feedback/index.mdx b/docs/platforms/java/common/user-feedback/index.mdx index 44685ebad1de4..64b4325cac20e 100644 --- a/docs/platforms/java/common/user-feedback/index.mdx +++ b/docs/platforms/java/common/user-feedback/index.mdx @@ -2,7 +2,7 @@ title: Set Up User Feedback sidebar_title: User Feedback description: "Learn more about collecting user feedback when an event occurs. Sentry pairs the feedback with the original event, giving you additional insight into issues." -sidebar_order: 6 +sidebar_order: 7 sidebar_section: features --- diff --git a/platform-includes/metrics/default-attributes/android.mdx b/platform-includes/metrics/default-attributes/android.mdx new file mode 100644 index 0000000000000..be18c1b0ad4a9 --- /dev/null +++ b/platform-includes/metrics/default-attributes/android.mdx @@ -0,0 +1,20 @@ +By default the SDK will attach the following attributes to a metric: + +- `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`. +- `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`. +- `sdk.name`: The name of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.name`. +- `sdk.version`: The version of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.version`. + +### User Attributes + +If user information is available in the current scope, the following attributes are added to the log: + +- `user.id`: The user ID. +- `user.name`: The username. +- `user.email`: The email address. + +### Replay Attributes + +If replay information is available in the current scope, the following attributes are added to the log: + +- `sentry.replay_id`: The ID of the replay. diff --git a/platform-includes/metrics/default-attributes/java.mdx b/platform-includes/metrics/default-attributes/java.mdx new file mode 100644 index 0000000000000..9eae8daf8a4b5 --- /dev/null +++ b/platform-includes/metrics/default-attributes/java.mdx @@ -0,0 +1,20 @@ +By default the SDK will attach the following attributes to a metric: + +- `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`. +- `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`. +- `sdk.name`: The name of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.name`. +- `sdk.version`: The version of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.version`. + +### User Attributes + +If user information is available in the current scope, the following attributes are added to the log: + +- `user.id`: The user ID. +- `user.name`: The username. +- `user.email`: The email address. + +### Server Attributes + +The SDK will attach the following: + +- `server.address`: The address of the server that sent the metric. Equivalent to `server_name` that gets attached to Sentry errors. diff --git a/platform-includes/metrics/options/android.mdx b/platform-includes/metrics/options/android.mdx new file mode 100644 index 0000000000000..dd1f9c27f5c5b --- /dev/null +++ b/platform-includes/metrics/options/android.mdx @@ -0,0 +1,69 @@ +The Sentry Android SDK provides several options to configure how metrics are captured and sent to Sentry. + +### Filtering and Modifying Metrics + +Use the `getMetrics().beforeSend` callback to filter or modify metrics before they're sent to Sentry. This is useful for: + +- Removing sensitive data from metric attributes +- Dropping metrics you don't want to send +- Adding or modifying attributes + +The callback receives a metric object and must return either a modified metric or `null` to drop it. + +```java {tabTitle: Java} +Sentry.init( + options -> { + // ... + options.getMetrics().setBeforeSend((metric, hint) -> { + // Drop metrics with specific attributes + if (metric.getAttributes().containsKey("dropmetric")) { + return null; + } + + // Modify metric attributes + metric.setAttribute("processed", new SentryLogEventAttributeValue(SentryAttributeType.BOOLEAN, true)); + return metric; + }); + } +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.init { options -> + // ... + options.metrics.setBeforeSend { metric, hint -> + // Drop metrics with specific attributes + if (metric.attributes.containsKey("dropmetric")) { + return@setBeforeSend null + } + + // Modify metric attributes + metric.setAttribute( + "processed", + SentryLogEventAttributeValue(SentryAttributeType.BOOLEAN, true) + ) + metric + } +} +``` + +### Disabling Metrics + +If you want to disable metrics collection entirely, you can do so by disabling the `metrics.enabled` flag: + +```xml {tabTitle: XML} + +``` +```java {tabTitle: Java} +Sentry.init( + options -> { + // ... + options.getMetrics().setEnabled(false); + } +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.init { options -> + // ... + options.metrics.setEnabled(false) +} +``` diff --git a/platform-includes/metrics/options/java.mdx b/platform-includes/metrics/options/java.mdx new file mode 100644 index 0000000000000..14327ff3478af --- /dev/null +++ b/platform-includes/metrics/options/java.mdx @@ -0,0 +1,66 @@ +The Sentry Java SDK provides several options to configure how metrics are captured and sent to Sentry. + +### Filtering and Modifying Metrics + +Use the `getMetrics().beforeSend` callback to filter or modify metrics before they're sent to Sentry. This is useful for: + +- Removing sensitive data from metric attributes +- Dropping metrics you don't want to send +- Adding or modifying attributes + +The callback receives a metric object and must return either a modified metric or `null` to drop it. + +```java {tabTitle: Java} +Sentry.init( + options -> { + // ... + options.getMetrics().setBeforeSend((metric, hint) -> { + // Drop metrics with specific attributes + if (metric.getAttributes().containsKey("dropmetric")) { + return null; + } + + // Modify metric attributes + metric.setAttribute("processed", new SentryLogEventAttributeValue(SentryAttributeType.BOOLEAN, true)); + return metric; + }); + } +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.init { options -> + // ... + options.metrics.setBeforeSend { metric, hint -> + // Drop metrics with specific attributes + if (metric.attributes.containsKey("dropmetric")) { + return@setBeforeSend null + } + + // Modify metric attributes + metric.setAttribute( + "processed", + SentryLogEventAttributeValue(SentryAttributeType.BOOLEAN, true) + ) + metric + } +} +``` + +### Disabling Metrics + +If you want to disable metrics collection entirely, you can do so by disabling the `metrics.enabled` flag: + +```java {tabTitle: Java} +Sentry.init( + options -> { + // ... + options.getMetrics().setEnabled(false); + } +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.init { options -> + // ... + options.metrics.setEnabled(false) +} +``` \ No newline at end of file diff --git a/platform-includes/metrics/options/java.spring-boot.mdx b/platform-includes/metrics/options/java.spring-boot.mdx new file mode 100644 index 0000000000000..15d49210ddfde --- /dev/null +++ b/platform-includes/metrics/options/java.spring-boot.mdx @@ -0,0 +1,70 @@ +#### beforeSendMetric + +To filter metrics, or update them before they are sent to Sentry, you can expose a bean implementing the metrics `beforeSend` callback: + +```java {tabTitle: Java} +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.sentry.SentryLogEventAttributeValue; +import io.sentry.SentryOptions; +import io.sentry.SentryAttributeType; + +@Configuration +public class SentryMetricsConfiguration { + @Bean + public SentryOptions.Metrics.BeforeSendMetricCallback beforeSendMetric() { + return (metric, hint) -> { + // Drop metrics with specific attributes + if (metric.getAttributes().containsKey("dropmetric")) { + return null; + } + + // Modify metric attributes + metric.setAttribute("processed", new SentryLogEventAttributeValue(SentryAttributeType.BOOLEAN, true)); + return metric; + }; + } +} +``` +```kotlin {tabTitle: Kotlin} +import io.sentry.SentryAttributeType +import io.sentry.SentryLogEventAttributeValue +import io.sentry.SentryOptions +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class SentryMetricsConfiguration { + @Bean + fun beforeSendMetric(): SentryOptions.Metrics.BeforeSendMetricCallback = + SentryOptions.Metrics.BeforeSendMetricCallback { metric, hint -> + // Drop metrics with specific attributes + if (metric.attributes.containsKey("dropmetric")) { + return@BeforeSendMetricCallback null + } + + // Modify metric attributes + metric.setAttribute( + "processed", + SentryLogEventAttributeValue(SentryAttributeType.BOOLEAN, true) + ) + metric + } +} +``` + +The `beforeSend` function receives a metric object, and should return the metric object if you want it to be sent to Sentry, or `null` if you want to discard it. + +### Disabling Metrics + +If you want to disable metrics collection entirely, you can do so by disabling the `metrics.enabled` flag: + +```properties {tabTitle:application.properties} +sentry.metrics.enabled=false +``` +```yaml {tabTitle:application.yml} +sentry: + metrics: + enabled: false +``` diff --git a/platform-includes/metrics/requirements/android.mdx b/platform-includes/metrics/requirements/android.mdx new file mode 100644 index 0000000000000..5c566e3854d02 --- /dev/null +++ b/platform-includes/metrics/requirements/android.mdx @@ -0,0 +1 @@ +Metrics are supported in Sentry Android SDK version `8.30.0` and above. diff --git a/platform-includes/metrics/requirements/java.mdx b/platform-includes/metrics/requirements/java.mdx new file mode 100644 index 0000000000000..7a16ffd457180 --- /dev/null +++ b/platform-includes/metrics/requirements/java.mdx @@ -0,0 +1 @@ +Metrics are supported in Sentry Java SDK version `8.30.0` and above. diff --git a/platform-includes/metrics/usage/android.mdx b/platform-includes/metrics/usage/android.mdx new file mode 100644 index 0000000000000..73039645d1d05 --- /dev/null +++ b/platform-includes/metrics/usage/android.mdx @@ -0,0 +1,114 @@ +Once the SDK is initialized, you can send metrics using the `Sentry.metrics()` APIs. + +The `metrics` namespace exposes methods that you can use to capture different types of metric information: `count`, `gauge` and `distribution`. + +### Counter + +Use `count` to track an incrementing value, such as the number of times a button was clicked or a function was called. + +```java {tabTitle: Java} +Sentry.metrics().count("button_click", 1.0); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().count("button_click", 1.0) +``` + +### Gauge + +Use `gauge` to track a value that can go up and down, such as the current memory usage or the number of items in a queue. + +```java {tabTitle: Java} +Sentry.metrics().gauge("queue_depth", 42.0); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().gauge("queue_depth", 42.0) +``` + +### Distribution + +Use `distribution` to track the distribution of a value, such as the response time of a request. + +```java {tabTitle: Java} +Sentry.metrics().distribution("response_time", 187.5); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().distribution("response_time", 187.5) +``` + +### Adding Attributes + +You can also pass additional attributes to any of the metric methods via `SentryMetricsParameters`. Attributes allow you to filter and group metrics. + +```java {tabTitle: Java} +Sentry.metrics().distribution( + "page_load", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + Map.of("browser", "Firefox") + ) +); + +Sentry.metrics().distribution( + "response_time", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + SentryAttributes.of( + SentryAttribute.stringAttribute("browser", "Firefox") + ) + ) +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().distribution( + "page_load", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + mapOf("browser" to "Firefox") + ) +) + +Sentry.metrics().distribution( + "response_time", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + SentryAttributes.of( + SentryAttribute.stringAttribute("browser", "Firefox") + ) + ) +) +``` + +### Specifying Units + +For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. + +```java {tabTitle: Java} +Sentry.metrics().distribution( + "response_time", + 187.5, + MetricsUnit.Duration.MILLISECOND +); + +Sentry.metrics().gauge( + "memory_usage", + 1024.0, + MetricsUnit.Information.BYTE +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().distribution( + "response_time", + 187.5, + MetricsUnit.Duration.MILLISECOND +) + +Sentry.metrics().gauge( + "memory_usage", + 1024.0, + MetricsUnit.Information.BYTE +) +``` diff --git a/platform-includes/metrics/usage/java.mdx b/platform-includes/metrics/usage/java.mdx new file mode 100644 index 0000000000000..73039645d1d05 --- /dev/null +++ b/platform-includes/metrics/usage/java.mdx @@ -0,0 +1,114 @@ +Once the SDK is initialized, you can send metrics using the `Sentry.metrics()` APIs. + +The `metrics` namespace exposes methods that you can use to capture different types of metric information: `count`, `gauge` and `distribution`. + +### Counter + +Use `count` to track an incrementing value, such as the number of times a button was clicked or a function was called. + +```java {tabTitle: Java} +Sentry.metrics().count("button_click", 1.0); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().count("button_click", 1.0) +``` + +### Gauge + +Use `gauge` to track a value that can go up and down, such as the current memory usage or the number of items in a queue. + +```java {tabTitle: Java} +Sentry.metrics().gauge("queue_depth", 42.0); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().gauge("queue_depth", 42.0) +``` + +### Distribution + +Use `distribution` to track the distribution of a value, such as the response time of a request. + +```java {tabTitle: Java} +Sentry.metrics().distribution("response_time", 187.5); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().distribution("response_time", 187.5) +``` + +### Adding Attributes + +You can also pass additional attributes to any of the metric methods via `SentryMetricsParameters`. Attributes allow you to filter and group metrics. + +```java {tabTitle: Java} +Sentry.metrics().distribution( + "page_load", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + Map.of("browser", "Firefox") + ) +); + +Sentry.metrics().distribution( + "response_time", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + SentryAttributes.of( + SentryAttribute.stringAttribute("browser", "Firefox") + ) + ) +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().distribution( + "page_load", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + mapOf("browser" to "Firefox") + ) +) + +Sentry.metrics().distribution( + "response_time", + 1.0, + MetricsUnit.Duration.MILLISECOND, + SentryMetricsParameters.create( + SentryAttributes.of( + SentryAttribute.stringAttribute("browser", "Firefox") + ) + ) +) +``` + +### Specifying Units + +For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. + +```java {tabTitle: Java} +Sentry.metrics().distribution( + "response_time", + 187.5, + MetricsUnit.Duration.MILLISECOND +); + +Sentry.metrics().gauge( + "memory_usage", + 1024.0, + MetricsUnit.Information.BYTE +); +``` +```kotlin {tabTitle: Kotlin} +Sentry.metrics().distribution( + "response_time", + 187.5, + MetricsUnit.Duration.MILLISECOND +) + +Sentry.metrics().gauge( + "memory_usage", + 1024.0, + MetricsUnit.Information.BYTE +) +``` diff --git a/src/middleware.ts b/src/middleware.ts index e662838f639ac..aa7743f749837 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1774,14 +1774,6 @@ const USER_DOCS_REDIRECTS: Redirect[] = [ from: '/platforms/ruby/metrics/', to: '/concepts/key-terms/tracing/span-metrics/', }, - { - from: '/platforms/java/metrics/', - to: '/concepts/key-terms/tracing/span-metrics/', - }, - { - from: '/platforms/android/metrics/', - to: '/concepts/key-terms/tracing/span-metrics/', - }, { from: '/platforms/apple/metrics/', to: '/concepts/key-terms/tracing/span-metrics/', From c7ad00160640c23100119771b65e439f7eafc9e2 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 15 Jan 2026 14:48:49 +0100 Subject: [PATCH 2/5] add imports --- platform-includes/metrics/options/android.mdx | 12 +++++++ platform-includes/metrics/options/java.mdx | 12 +++++++ .../metrics/options/java.spring-boot.mdx | 8 +++-- platform-includes/metrics/usage/android.mdx | 32 +++++++++++++++++++ platform-includes/metrics/usage/java.mdx | 32 +++++++++++++++++++ 5 files changed, 93 insertions(+), 3 deletions(-) diff --git a/platform-includes/metrics/options/android.mdx b/platform-includes/metrics/options/android.mdx index dd1f9c27f5c5b..46eb1c9ed0497 100644 --- a/platform-includes/metrics/options/android.mdx +++ b/platform-includes/metrics/options/android.mdx @@ -11,6 +11,10 @@ Use the `getMetrics().beforeSend` callback to filter or modify metrics before th The callback receives a metric object and must return either a modified metric or `null` to drop it. ```java {tabTitle: Java} +import io.sentry.Sentry; +import io.sentry.SentryAttributeType; +import io.sentry.SentryLogEventAttributeValue; + Sentry.init( options -> { // ... @@ -28,6 +32,10 @@ Sentry.init( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry +import io.sentry.SentryAttributeType +import io.sentry.SentryLogEventAttributeValue + Sentry.init { options -> // ... options.metrics.setBeforeSend { metric, hint -> @@ -54,6 +62,8 @@ If you want to disable metrics collection entirely, you can do so by disabling t ``` ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.init( options -> { // ... @@ -62,6 +72,8 @@ Sentry.init( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.init { options -> // ... options.metrics.setEnabled(false) diff --git a/platform-includes/metrics/options/java.mdx b/platform-includes/metrics/options/java.mdx index 14327ff3478af..13f862f66a17e 100644 --- a/platform-includes/metrics/options/java.mdx +++ b/platform-includes/metrics/options/java.mdx @@ -11,6 +11,10 @@ Use the `getMetrics().beforeSend` callback to filter or modify metrics before th The callback receives a metric object and must return either a modified metric or `null` to drop it. ```java {tabTitle: Java} +import io.sentry.Sentry; +import io.sentry.SentryAttributeType; +import io.sentry.SentryLogEventAttributeValue; + Sentry.init( options -> { // ... @@ -28,6 +32,10 @@ Sentry.init( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry +import io.sentry.SentryAttributeType +import io.sentry.SentryLogEventAttributeValue + Sentry.init { options -> // ... options.metrics.setBeforeSend { metric, hint -> @@ -51,6 +59,8 @@ Sentry.init { options -> If you want to disable metrics collection entirely, you can do so by disabling the `metrics.enabled` flag: ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.init( options -> { // ... @@ -59,6 +69,8 @@ Sentry.init( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.init { options -> // ... options.metrics.setEnabled(false) diff --git a/platform-includes/metrics/options/java.spring-boot.mdx b/platform-includes/metrics/options/java.spring-boot.mdx index 15d49210ddfde..e37da6e1e94bc 100644 --- a/platform-includes/metrics/options/java.spring-boot.mdx +++ b/platform-includes/metrics/options/java.spring-boot.mdx @@ -9,11 +9,12 @@ import org.springframework.context.annotation.Configuration; import io.sentry.SentryLogEventAttributeValue; import io.sentry.SentryOptions; import io.sentry.SentryAttributeType; +import io.sentry.SentryOptions.Metrics.BeforeSendMetricCallback; @Configuration public class SentryMetricsConfiguration { @Bean - public SentryOptions.Metrics.BeforeSendMetricCallback beforeSendMetric() { + public BeforeSendMetricCallback beforeSendMetric() { return (metric, hint) -> { // Drop metrics with specific attributes if (metric.getAttributes().containsKey("dropmetric")) { @@ -31,14 +32,15 @@ public class SentryMetricsConfiguration { import io.sentry.SentryAttributeType import io.sentry.SentryLogEventAttributeValue import io.sentry.SentryOptions +import io.sentry.SentryOptions.Metrics.BeforeSendMetricCallback import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @Configuration class SentryMetricsConfiguration { @Bean - fun beforeSendMetric(): SentryOptions.Metrics.BeforeSendMetricCallback = - SentryOptions.Metrics.BeforeSendMetricCallback { metric, hint -> + fun beforeSendMetric(): BeforeSendMetricCallback = + BeforeSendMetricCallback { metric, hint -> // Drop metrics with specific attributes if (metric.attributes.containsKey("dropmetric")) { return@BeforeSendMetricCallback null diff --git a/platform-includes/metrics/usage/android.mdx b/platform-includes/metrics/usage/android.mdx index 73039645d1d05..45977e40f8622 100644 --- a/platform-includes/metrics/usage/android.mdx +++ b/platform-includes/metrics/usage/android.mdx @@ -7,9 +7,13 @@ The `metrics` namespace exposes methods that you can use to capture different ty Use `count` to track an incrementing value, such as the number of times a button was clicked or a function was called. ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.metrics().count("button_click", 1.0); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.metrics().count("button_click", 1.0) ``` @@ -18,9 +22,13 @@ Sentry.metrics().count("button_click", 1.0) Use `gauge` to track a value that can go up and down, such as the current memory usage or the number of items in a queue. ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.metrics().gauge("queue_depth", 42.0); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.metrics().gauge("queue_depth", 42.0) ``` @@ -29,9 +37,13 @@ Sentry.metrics().gauge("queue_depth", 42.0) Use `distribution` to track the distribution of a value, such as the response time of a request. ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.metrics().distribution("response_time", 187.5); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.metrics().distribution("response_time", 187.5) ``` @@ -40,6 +52,14 @@ Sentry.metrics().distribution("response_time", 187.5) You can also pass additional attributes to any of the metric methods via `SentryMetricsParameters`. Attributes allow you to filter and group metrics. ```java {tabTitle: Java} +import java.util.Map; + +import io.sentry.Sentry; +import io.sentry.SentryAttribute; +import io.sentry.SentryAttributes; +import io.sentry.metrics.MetricsUnit; +import io.sentry.metrics.SentryMetricsParameters; + Sentry.metrics().distribution( "page_load", 1.0, @@ -61,6 +81,12 @@ Sentry.metrics().distribution( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry +import io.sentry.SentryAttribute +import io.sentry.SentryAttributes +import io.sentry.metrics.MetricsUnit +import io.sentry.metrics.SentryMetricsParameters + Sentry.metrics().distribution( "page_load", 1.0, @@ -87,6 +113,9 @@ Sentry.metrics().distribution( For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. ```java {tabTitle: Java} +import io.sentry.Sentry; +import io.sentry.metrics.MetricsUnit; + Sentry.metrics().distribution( "response_time", 187.5, @@ -100,6 +129,9 @@ Sentry.metrics().gauge( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry +import io.sentry.metrics.MetricsUnit + Sentry.metrics().distribution( "response_time", 187.5, diff --git a/platform-includes/metrics/usage/java.mdx b/platform-includes/metrics/usage/java.mdx index 73039645d1d05..10c162d0c0425 100644 --- a/platform-includes/metrics/usage/java.mdx +++ b/platform-includes/metrics/usage/java.mdx @@ -7,9 +7,13 @@ The `metrics` namespace exposes methods that you can use to capture different ty Use `count` to track an incrementing value, such as the number of times a button was clicked or a function was called. ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.metrics().count("button_click", 1.0); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.metrics().count("button_click", 1.0) ``` @@ -18,9 +22,13 @@ Sentry.metrics().count("button_click", 1.0) Use `gauge` to track a value that can go up and down, such as the current memory usage or the number of items in a queue. ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.metrics().gauge("queue_depth", 42.0); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.metrics().gauge("queue_depth", 42.0) ``` @@ -29,9 +37,13 @@ Sentry.metrics().gauge("queue_depth", 42.0) Use `distribution` to track the distribution of a value, such as the response time of a request. ```java {tabTitle: Java} +import io.sentry.Sentry; + Sentry.metrics().distribution("response_time", 187.5); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry + Sentry.metrics().distribution("response_time", 187.5) ``` @@ -40,6 +52,14 @@ Sentry.metrics().distribution("response_time", 187.5) You can also pass additional attributes to any of the metric methods via `SentryMetricsParameters`. Attributes allow you to filter and group metrics. ```java {tabTitle: Java} +import java.util.Map; + +import io.sentry.Sentry; +import io.sentry.SentryAttribute; +import io.sentry.SentryAttributes; +import io.sentry.SentryMetricsParameters; +import io.sentry.metrics.MetricsUnit; + Sentry.metrics().distribution( "page_load", 1.0, @@ -61,6 +81,12 @@ Sentry.metrics().distribution( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry +import io.sentry.SentryAttribute +import io.sentry.SentryAttributes +import io.sentry.SentryMetricsParameters +import io.sentry.metrics.MetricsUnit + Sentry.metrics().distribution( "page_load", 1.0, @@ -87,6 +113,9 @@ Sentry.metrics().distribution( For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. ```java {tabTitle: Java} +import io.sentry.Sentry; +import io.sentry.metrics.MetricsUnit; + Sentry.metrics().distribution( "response_time", 187.5, @@ -100,6 +129,9 @@ Sentry.metrics().gauge( ); ``` ```kotlin {tabTitle: Kotlin} +import io.sentry.Sentry +import io.sentry.metrics.MetricsUnit + Sentry.metrics().distribution( "response_time", 187.5, From 3f046b97c82f167970351aef6dc1c36fbd4ade64 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 15 Jan 2026 14:56:17 +0100 Subject: [PATCH 3/5] mention custom units are not supported --- platform-includes/metrics/usage/android.mdx | 2 +- platform-includes/metrics/usage/java.mdx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform-includes/metrics/usage/android.mdx b/platform-includes/metrics/usage/android.mdx index 45977e40f8622..21a2fd7525ae0 100644 --- a/platform-includes/metrics/usage/android.mdx +++ b/platform-includes/metrics/usage/android.mdx @@ -110,7 +110,7 @@ Sentry.metrics().distribution( ### Specifying Units -For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. +For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. Sending in custom units is not supported. ```java {tabTitle: Java} import io.sentry.Sentry; diff --git a/platform-includes/metrics/usage/java.mdx b/platform-includes/metrics/usage/java.mdx index 10c162d0c0425..21a2fd7525ae0 100644 --- a/platform-includes/metrics/usage/java.mdx +++ b/platform-includes/metrics/usage/java.mdx @@ -57,8 +57,8 @@ import java.util.Map; import io.sentry.Sentry; import io.sentry.SentryAttribute; import io.sentry.SentryAttributes; -import io.sentry.SentryMetricsParameters; import io.sentry.metrics.MetricsUnit; +import io.sentry.metrics.SentryMetricsParameters; Sentry.metrics().distribution( "page_load", @@ -84,8 +84,8 @@ Sentry.metrics().distribution( import io.sentry.Sentry import io.sentry.SentryAttribute import io.sentry.SentryAttributes -import io.sentry.SentryMetricsParameters import io.sentry.metrics.MetricsUnit +import io.sentry.metrics.SentryMetricsParameters Sentry.metrics().distribution( "page_load", @@ -110,7 +110,7 @@ Sentry.metrics().distribution( ### Specifying Units -For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. +For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. `MetricsUnit` offers constants for units supported by Sentry. Sending in custom units is not supported. ```java {tabTitle: Java} import io.sentry.Sentry; From 41a746e607d31e8dd869979cc8a2eb82edb5c174 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 16 Jan 2026 09:27:14 +0100 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Markus Hintersteiner --- platform-includes/metrics/options/android.mdx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/platform-includes/metrics/options/android.mdx b/platform-includes/metrics/options/android.mdx index 46eb1c9ed0497..ced1f1f17168a 100644 --- a/platform-includes/metrics/options/android.mdx +++ b/platform-includes/metrics/options/android.mdx @@ -11,11 +11,12 @@ Use the `getMetrics().beforeSend` callback to filter or modify metrics before th The callback receives a metric object and must return either a modified metric or `null` to drop it. ```java {tabTitle: Java} -import io.sentry.Sentry; +import io.sentry.android.core.SentryAndroid; +import io.sentry.android.core.SentryAndroidOptions; import io.sentry.SentryAttributeType; import io.sentry.SentryLogEventAttributeValue; -Sentry.init( +SentryAndroid.init(context, options -> { // ... options.getMetrics().setBeforeSend((metric, hint) -> { @@ -32,11 +33,12 @@ Sentry.init( ); ``` ```kotlin {tabTitle: Kotlin} -import io.sentry.Sentry +import io.sentry.android.core.SentryAndroid +import io.sentry.android.core.SentryAndroidOptions import io.sentry.SentryAttributeType import io.sentry.SentryLogEventAttributeValue -Sentry.init { options -> +SentryAndroid.init(context) { options -> // ... options.metrics.setBeforeSend { metric, hint -> // Drop metrics with specific attributes @@ -62,9 +64,10 @@ If you want to disable metrics collection entirely, you can do so by disabling t ``` ```java {tabTitle: Java} -import io.sentry.Sentry; +import io.sentry.android.core.SentryAndroid; +import io.sentry.android.core.SentryAndroidOptions; -Sentry.init( +SentryAndroid.init(context, options -> { // ... options.getMetrics().setEnabled(false); @@ -72,9 +75,10 @@ Sentry.init( ); ``` ```kotlin {tabTitle: Kotlin} -import io.sentry.Sentry +import io.sentry.android.core.SentryAndroid +import io.sentry.android.core.SentryAndroidOptions -Sentry.init { options -> +SentryAndroid.init { options -> // ... options.metrics.setEnabled(false) } From 601466af7d0396d45528443638c8e10a0311521b Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 16 Jan 2026 09:33:39 +0100 Subject: [PATCH 5/5] link Java and Android in supported SDKs for metrics --- .../explore/metrics/getting-started/index.mdx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/product/explore/metrics/getting-started/index.mdx b/docs/product/explore/metrics/getting-started/index.mdx index 86e1349c92cc8..ec818cdb890e5 100644 --- a/docs/product/explore/metrics/getting-started/index.mdx +++ b/docs/product/explore/metrics/getting-started/index.mdx @@ -174,6 +174,32 @@ To set up Sentry Metrics, use the links below for supported SDKs. After it's bee url="/platforms/javascript/guides/wasm/metrics/" /> +### Java + +- +- +- + +### Mobile + +- + ### Python -