Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify registering traces sample callback #1184

Merged
merged 2 commits into from
Jan 18, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Enhancement: Pass request to CustomSamplingContext in Spring integration (#1172)
* Fix: Free Local Refs manually due to Android local ref. count limits
* Enhancement: Add overload for `transaction/span.finish(SpanStatus)` (#1182)
* Enhancement: Simplify registering traces sample callback in Spring integration (#1184)

# 4.0.0-alpha.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.jakewharton.nopen.annotation.Open;
import io.sentry.Sentry;
import io.sentry.SentryOptions;
import io.sentry.SentryOptions.TracesSamplerCallback;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.BeansException;
Expand All @@ -29,6 +30,9 @@ public Object postProcessAfterInitialization(
sentryUserProvider ->
options.addEventProcessor(
new SentryUserProviderEventProcessor(options, sentryUserProvider)));
applicationContext
.getBeanProvider(TracesSamplerCallback.class)
.ifAvailable(options::setTracesSampler);
}
Sentry.init(options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlin.test.Test
import org.assertj.core.api.Assertions.assertThat
import org.springframework.boot.context.annotation.UserConfigurations
import org.springframework.boot.test.context.runner.ApplicationContextRunner
import org.springframework.context.annotation.Bean

class EnableSentryTest {
private val contextRunner = ApplicationContextRunner()
Expand Down Expand Up @@ -88,6 +89,16 @@ class EnableSentryTest {
}
}

@Test
fun `configures custom TracesSamplerCallback`() {
ApplicationContextRunner().withConfiguration(UserConfigurations.of(AppConfigWithCustomTracesSamplerCallback::class.java))
.run {
val options = it.getBean(SentryOptions::class.java)
val samplerCallback = it.getBean(SentryOptions.TracesSamplerCallback::class.java)
assertThat(options.tracesSampler).isEqualTo(samplerCallback)
}
}

@EnableSentry(dsn = "http://key@localhost/proj")
class AppConfig

Expand All @@ -99,4 +110,15 @@ class EnableSentryTest {

@EnableSentry(dsn = "http://key@localhost/proj", exceptionResolverOrder = Integer.MAX_VALUE)
class AppConfigWithExceptionResolverOrderIntegerMaxValue

@EnableSentry(dsn = "http://key@localhost/proj")
class AppConfigWithCustomTracesSamplerCallback {

@Bean
fun tracesSampler(): SentryOptions.TracesSamplerCallback {
return SentryOptions.TracesSamplerCallback {
return@TracesSamplerCallback 1.0
}
}
}
}