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
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ String count() {
}

@GetMapping("gauge/{count}")
String gauge(@PathVariable Long count) {
String gauge(@PathVariable("count") Long count) {
Sentry.metrics().gauge("memory.free", count.doubleValue(), "byte");
return "gauge metric tracked";
}

@GetMapping("distribution/{count}")
String distribution(@PathVariable Long count) {
String distribution(@PathVariable("count") Long count) {
Sentry.metrics().distribution("distributionMetric", count.doubleValue(), "child");
return "distribution metric tracked";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MetricsSystemTest {

@Before
fun setup() {
testHelper = TestHelper("http://localhost:8080")
testHelper = TestHelper("http://localhost:8080/sentry-samples-spring-7-0.0.1-SNAPSHOT")
testHelper.reset()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ String count() {
}

@GetMapping("gauge/{count}")
String gauge(@PathVariable Long count) {
String gauge(@PathVariable("count") Long count) {
Sentry.metrics().gauge("memory.free", count.doubleValue(), "byte");
return "gauge metric tracked";
}

@GetMapping("distribution/{count}")
String distribution(@PathVariable Long count) {
String distribution(@PathVariable("count") Long count) {
Sentry.metrics().distribution("distributionMetric", count.doubleValue(), "child");
return "distribution metric tracked";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MetricsSystemTest {

@Before
fun setup() {
testHelper = TestHelper("http://localhost:8080")
testHelper = TestHelper("http://localhost:8080/sentry-samples-spring-jakarta-0.0.1-SNAPSHOT")
testHelper.reset()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ String count() {
}

@GetMapping("gauge/{count}")
String gauge(@PathVariable Long count) {
String gauge(@PathVariable("count") Long count) {
Sentry.metrics().gauge("memory.free", count.doubleValue(), "byte");
return "gauge metric tracked";
}

@GetMapping("distribution/{count}")
String distribution(@PathVariable Long count) {
String distribution(@PathVariable("count") Long count) {
Sentry.metrics().distribution("distributionMetric", count.doubleValue(), "child");
return "distribution metric tracked";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MetricsSystemTest {

@Before
fun setup() {
testHelper = TestHelper("http://localhost:8080")
testHelper = TestHelper("http://localhost:8080/sentry-samples-spring-0.0.1-SNAPSHOT")
testHelper.reset()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ static class HubConfiguration {
beforeSendTransactionCallback,
final @NotNull ObjectProvider<SentryOptions.Logs.BeforeSendLogCallback>
beforeSendLogsCallback,
final @NotNull ObjectProvider<SentryOptions.Metrics.BeforeSendMetricCallback>
beforeSendMetricCallback,
final @NotNull ObjectProvider<SentryOptions.BeforeBreadcrumbCallback>
beforeBreadcrumbCallback,
final @NotNull ObjectProvider<SentryOptions.TracesSamplerCallback> tracesSamplerCallback,
Expand All @@ -117,6 +119,8 @@ static class HubConfiguration {
beforeSendCallback.ifAvailable(options::setBeforeSend);
beforeSendTransactionCallback.ifAvailable(options::setBeforeSendTransaction);
beforeSendLogsCallback.ifAvailable(callback -> options.getLogs().setBeforeSend(callback));
beforeSendMetricCallback.ifAvailable(
callback -> options.getMetrics().setBeforeSend(callback));
beforeBreadcrumbCallback.ifAvailable(options::setBeforeBreadcrumb);
tracesSamplerCallback.ifAvailable(options::setTracesSampler);
eventProcessors.forEach(options::addEventProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.sentry.SentryEvent
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel
import io.sentry.SentryLogEvent
import io.sentry.SentryMetricsEvent
import io.sentry.SentryOptions
import io.sentry.asyncprofiler.profiling.JavaContinuousProfiler
import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider
Expand Down Expand Up @@ -370,6 +371,17 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `registers metrics beforeSendCallback on SentryOptions`() {
contextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(CustomBeforeSendMetricCallbackConfiguration::class.java)
.run {
assertThat(it.getBean(SentryOptions::class.java).metrics.beforeSend)
.isInstanceOf(CustomBeforeSendMetricCallback::class.java)
}
}

@Test
fun `registers beforeBreadcrumbCallback on SentryOptions`() {
contextRunner
Expand Down Expand Up @@ -1240,6 +1252,16 @@ class SentryAutoConfigurationTest {
override fun execute(event: SentryLogEvent): SentryLogEvent? = null
}

@Configuration(proxyBeanMethods = false)
open class CustomBeforeSendMetricCallbackConfiguration {

@Bean open fun beforeSendCallback() = CustomBeforeSendMetricCallback()
}

class CustomBeforeSendMetricCallback : SentryOptions.Metrics.BeforeSendMetricCallback {
override fun execute(metric: SentryMetricsEvent, hint: Hint): SentryMetricsEvent? = null
}

@Configuration(proxyBeanMethods = false)
open class CustomBeforeSendTransactionCallbackConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ static class HubConfiguration {
beforeSendTransactionCallback,
final @NotNull ObjectProvider<SentryOptions.Logs.BeforeSendLogCallback>
beforeSendLogsCallback,
final @NotNull ObjectProvider<SentryOptions.Metrics.BeforeSendMetricCallback>
beforeSendMetricCallback,
final @NotNull ObjectProvider<SentryOptions.BeforeBreadcrumbCallback>
beforeBreadcrumbCallback,
final @NotNull ObjectProvider<SentryOptions.OnDiscardCallback> onDiscardCallback,
Expand All @@ -118,6 +120,8 @@ static class HubConfiguration {
beforeSendCallback.ifAvailable(options::setBeforeSend);
beforeSendTransactionCallback.ifAvailable(options::setBeforeSendTransaction);
beforeSendLogsCallback.ifAvailable(callback -> options.getLogs().setBeforeSend(callback));
beforeSendMetricCallback.ifAvailable(
callback -> options.getMetrics().setBeforeSend(callback));
beforeBreadcrumbCallback.ifAvailable(options::setBeforeBreadcrumb);
onDiscardCallback.ifAvailable(options::setOnDiscard);
tracesSamplerCallback.ifAvailable(options::setTracesSampler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.sentry.SentryEvent
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel
import io.sentry.SentryLogEvent
import io.sentry.SentryMetricsEvent
import io.sentry.SentryOptions
import io.sentry.asyncprofiler.profiling.JavaContinuousProfiler
import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider
Expand Down Expand Up @@ -381,6 +382,17 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `registers metrics beforeSendCallback on SentryOptions`() {
contextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(CustomBeforeSendMetricCallbackConfiguration::class.java)
.run {
assertThat(it.getBean(SentryOptions::class.java).metrics.beforeSend)
.isInstanceOf(CustomBeforeSendMetricCallback::class.java)
}
}

@Test
fun `registers beforeBreadcrumbCallback on SentryOptions`() {
contextRunner
Expand Down Expand Up @@ -1262,6 +1274,16 @@ class SentryAutoConfigurationTest {
override fun execute(event: SentryLogEvent): SentryLogEvent? = null
}

@Configuration(proxyBeanMethods = false)
open class CustomBeforeSendMetricCallbackConfiguration {

@Bean open fun beforeSendCallback() = CustomBeforeSendMetricCallback()
}

class CustomBeforeSendMetricCallback : SentryOptions.Metrics.BeforeSendMetricCallback {
override fun execute(metric: SentryMetricsEvent, hint: Hint): SentryMetricsEvent? = null
}

@Configuration(proxyBeanMethods = false)
open class CustomBeforeSendTransactionCallbackConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ static class HubConfiguration {
beforeSendTransactionCallback,
final @NotNull ObjectProvider<SentryOptions.Logs.BeforeSendLogCallback>
beforeSendLogsCallback,
final @NotNull ObjectProvider<SentryOptions.Metrics.BeforeSendMetricCallback>
beforeSendMetricCallback,
final @NotNull ObjectProvider<SentryOptions.BeforeBreadcrumbCallback>
beforeBreadcrumbCallback,
final @NotNull ObjectProvider<SentryOptions.OnDiscardCallback> onDiscardCallback,
Expand All @@ -116,6 +118,8 @@ static class HubConfiguration {
beforeSendCallback.ifAvailable(options::setBeforeSend);
beforeSendTransactionCallback.ifAvailable(options::setBeforeSendTransaction);
beforeSendLogsCallback.ifAvailable(callback -> options.getLogs().setBeforeSend(callback));
beforeSendMetricCallback.ifAvailable(
callback -> options.getMetrics().setBeforeSend(callback));
beforeBreadcrumbCallback.ifAvailable(options::setBeforeBreadcrumb);
onDiscardCallback.ifAvailable(options::setOnDiscard);
tracesSamplerCallback.ifAvailable(options::setTracesSampler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.sentry.SentryEvent
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel
import io.sentry.SentryLogEvent
import io.sentry.SentryMetricsEvent
import io.sentry.SentryOptions
import io.sentry.asyncprofiler.profiling.JavaContinuousProfiler
import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider
Expand Down Expand Up @@ -369,6 +370,17 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `registers metrics beforeSendCallback on SentryOptions`() {
contextRunner
.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(CustomBeforeSendMetricCallbackConfiguration::class.java)
.run {
assertThat(it.getBean(SentryOptions::class.java).metrics.beforeSend)
.isInstanceOf(CustomBeforeSendMetricCallback::class.java)
}
}

@Test
fun `registers beforeSendTransactionCallback on SentryOptions`() {
contextRunner
Expand Down Expand Up @@ -1188,6 +1200,16 @@ class SentryAutoConfigurationTest {
override fun execute(event: SentryLogEvent): SentryLogEvent? = null
}

@Configuration(proxyBeanMethods = false)
open class CustomBeforeSendMetricCallbackConfiguration {

@Bean open fun beforeSendCallback() = CustomBeforeSendMetricCallback()
}

class CustomBeforeSendMetricCallback : SentryOptions.Metrics.BeforeSendMetricCallback {
override fun execute(metric: SentryMetricsEvent, hint: Hint): SentryMetricsEvent? = null
}

@Configuration(proxyBeanMethods = false)
open class CustomBeforeSendTransactionCallbackConfiguration {

Expand Down
Loading