Skip to content

Commit c002817

Browse files
Auto register custom ITransportFactory in Spring integration. (#1194)
1 parent 7c2dbdb commit c002817

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Enhancement: Polish Performance API (#1165)
1313
* Enhancement: Set "debug" through external properties (#1186)
1414
* Enhancement: Simplify Spring integration (#1188)
15+
* Enhancement: Auto register custom ITransportFactory in Spring integration (#1194)
1516
* Enhancement: Improve Kotlin property access in Performance API (#1193)
1617

1718
# 4.0.0-alpha.3

sentry-spring/src/main/java/io/sentry/spring/SentryInitBeanPostProcessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.spring;
22

33
import com.jakewharton.nopen.annotation.Open;
4+
import io.sentry.ITransportFactory;
45
import io.sentry.Sentry;
56
import io.sentry.SentryOptions;
67
import io.sentry.SentryOptions.TracesSamplerCallback;
@@ -33,6 +34,9 @@ public Object postProcessAfterInitialization(
3334
applicationContext
3435
.getBeanProvider(TracesSamplerCallback.class)
3536
.ifAvailable(options::setTracesSampler);
37+
applicationContext
38+
.getBeanProvider(ITransportFactory.class)
39+
.ifAvailable(options::setTransportFactory);
3640
}
3741
Sentry.init(options);
3842
}

sentry-spring/src/test/kotlin/io/sentry/spring/EnableSentryTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.sentry.spring
22

3+
import com.nhaarman.mockitokotlin2.mock
34
import io.sentry.IHub
5+
import io.sentry.ITransportFactory
46
import io.sentry.SentryOptions
57
import kotlin.test.Test
68
import org.assertj.core.api.Assertions.assertThat
@@ -92,6 +94,16 @@ class EnableSentryTest {
9294
}
9395
}
9496

97+
@Test
98+
fun `configures custom TransportFactory`() {
99+
ApplicationContextRunner().withConfiguration(UserConfigurations.of(AppConfigWithCustomTransportFactory::class.java))
100+
.run {
101+
val options = it.getBean(SentryOptions::class.java)
102+
val transportFactory = it.getBean(ITransportFactory::class.java)
103+
assertThat(options.transportFactory).isEqualTo(transportFactory)
104+
}
105+
}
106+
95107
@EnableSentry(dsn = "http://key@localhost/proj")
96108
class AppConfig
97109

@@ -114,4 +126,11 @@ class EnableSentryTest {
114126
}
115127
}
116128
}
129+
130+
@EnableSentry(dsn = "http://key@localhost/proj")
131+
class AppConfigWithCustomTransportFactory {
132+
133+
@Bean
134+
fun tracesSampler() = mock<ITransportFactory>()
135+
}
117136
}

0 commit comments

Comments
 (0)