Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ targets:
maven:io.sentry:sentry-opentelemetry-otlp:
maven:io.sentry:sentry-opentelemetry-otlp-spring:
maven:io.sentry:sentry-kafka:
# TODO: Add after first release of the artifact.
# maven:io.sentry:sentry-micrometer:
maven:io.sentry:sentry-apollo:
maven:io.sentry:sentry-jdbc:
maven:io.sentry:sentry-jcache:
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ body:
- sentry-quartz
- sentry-openfeign
- sentry-openfeature
- sentry-micrometer
- sentry-launchdarkly-server
- sentry-apache-http-client-5
- sentry-okhttp
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Sentry SDK for Java and Android
| sentry-jul | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-jul?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-jul) |
| sentry-jdbc | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-jdbc?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-jdbc) |
| sentry-kafka | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-kafka?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-kafka) |
| sentry-micrometer | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-micrometer?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-micrometer) |
| sentry-apollo | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-apollo?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-apollo) | 21 |
| sentry-apollo-3 | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-apollo-3?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-apollo-3) | 21 |
| sentry-apollo-4 | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-apollo-4?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-apollo-4) | 21 |
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ object Config {
val SENTRY_QUARTZ_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.quartz"
val SENTRY_JDBC_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.jdbc"
val SENTRY_KAFKA_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.kafka"
val SENTRY_MICROMETER_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.micrometer"
val SENTRY_OPENFEATURE_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.openfeature"
val SENTRY_LAUNCHDARKLY_SERVER_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.launchdarkly-server"
val SENTRY_LAUNCHDARKLY_ANDROID_SDK_NAME = "$SENTRY_ANDROID_SDK_NAME.launchdarkly"
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ksp = "2.3.9"
ktorClient = "3.0.0"
logback = "1.2.9"
log4j2 = "2.20.0"
micrometer = "1.9.17"
nopen = "1.0.1"
# see https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compatibility-and-versioning.html#kotlin-compatibility
# see https://developer.android.com/jetpack/androidx/releases/compose-kotlin
Expand Down Expand Up @@ -144,6 +145,7 @@ log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "lo
leakcanary = { module = "com.squareup.leakcanary:leakcanary-android", version = "2.14" }
lottie-compose = { module = "com.airbnb.android:lottie-compose", version = "6.7.1" }
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
micrometer-core = { module = "io.micrometer:micrometer-core", version.ref = "micrometer" }
nopen-annotations = { module = "com.jakewharton.nopen:nopen-annotations", version.ref = "nopen" }
nopen-checker = { module = "com.jakewharton.nopen:nopen-checker", version.ref = "nopen" }
nullaway = { module = "com.uber.nullaway:nullaway", version = "0.9.5" }
Expand Down
21 changes: 21 additions & 0 deletions sentry-micrometer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# sentry-micrometer

This module forwards Micrometer metrics to Sentry.

## Install

Add the Sentry Micrometer module and Micrometer Core:

```kotlin
dependencies {
implementation("io.sentry:sentry-micrometer:<version>")
implementation("io.micrometer:micrometer-core:<version>")
}
```

Create a `SentryMeterRegistry` and add it to Micrometer:

```java
SentryMeterRegistry sentryRegistry = new SentryMeterRegistry();
Metrics.addRegistry(sentryRegistry);
```
9 changes: 9 additions & 0 deletions sentry-micrometer/api/sentry-micrometer.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public final class io/sentry/micrometer/BuildConfig {
public static final field SENTRY_MICROMETER_SDK_NAME Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
}

public final class io/sentry/micrometer/SentryMeterRegistry : io/micrometer/core/instrument/MeterRegistry {
public fun <init> ()V
}

66 changes: 66 additions & 0 deletions sentry-micrometer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import net.ltgt.gradle.errorprone.errorprone
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`java-library`
id("io.sentry.javadoc")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.errorprone)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
id("io.sentry.animalsniffer")
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
}

dependencies {
api(projects.sentry)
compileOnly(libs.micrometer.core)
compileOnly(libs.jetbrains.annotations)
compileOnly(libs.nopen.annotations)

errorprone(libs.errorprone.core)
errorprone(libs.nopen.checker)
errorprone(libs.nullaway)

// tests
testImplementation(projects.sentryTestSupport)
testImplementation(kotlin(Config.kotlinStdLib))
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.google.truth)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.micrometer.core)
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "io.sentry")
}
}

buildConfig {
useJavaOutput()
packageName("io.sentry.micrometer")
buildConfigField(
"String",
"SENTRY_MICROMETER_SDK_NAME",
"\"${Config.Sentry.SENTRY_MICROMETER_SDK_NAME}\"",
)
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}

tasks.jar {
manifest {
attributes(
"Sentry-Version-Name" to project.version,
"Sentry-SDK-Name" to Config.Sentry.SENTRY_MICROMETER_SDK_NAME,
"Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-micrometer",
"Implementation-Vendor" to "Sentry",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.sentry.micrometer;

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.cumulative.CumulativeCounter;
import org.jetbrains.annotations.NotNull;

final class SentryCounter extends CumulativeCounter implements SentryRemovableMeter {
private final @NotNull SentryMeterRegistry registry;
private final @NotNull SentryMetricInfo metricInfo;
private volatile boolean removed;

SentryCounter(
final @NotNull Meter.Id id,
final @NotNull SentryMeterRegistry registry,
final @NotNull SentryMetricInfo metricInfo) {
super(id);
this.registry = registry;
this.metricInfo = metricInfo;
}

@Override
public void increment(final double amount) {
super.increment(amount);
if (amount > 0.0 && Double.isFinite(amount) && !removed) {
registry.captureCounter(metricInfo, amount);
}
}

@Override
public void markRemoved() {
removed = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.sentry.micrometer;

import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.cumulative.CumulativeDistributionSummary;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
import org.jetbrains.annotations.NotNull;

final class SentryDistributionSummary extends CumulativeDistributionSummary
implements SentryRemovableMeter {
private final @NotNull SentryMeterRegistry registry;
private final @NotNull SentryMetricInfo metricInfo;
private volatile boolean removed;

SentryDistributionSummary(
final @NotNull Meter.Id id,
final @NotNull Clock clock,
final @NotNull DistributionStatisticConfig distributionStatisticConfig,
final double scale,
final @NotNull SentryMeterRegistry registry,
final @NotNull SentryMetricInfo metricInfo) {
super(id, clock, distributionStatisticConfig, scale, false);
this.registry = registry;
this.metricInfo = metricInfo;
}

@Override
protected void recordNonNegative(final double amount) {
super.recordNonNegative(amount);
if (Double.isFinite(amount) && !removed) {
registry.captureDistribution(metricInfo, amount);
}
}

@Override
public void markRemoved() {
removed = true;
}
}
Loading
Loading