@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
1919import org.springframework.web.bind.annotation.GetMapping ;
2020import org.springframework.web.bind.annotation.PathVariable ;
2121
22+
2223@RestController
2324class HelloController {
2425
@@ -51,65 +52,80 @@ Each sampled request executed by this controller method will be turned into a tr
5152Sentry Spring integration provides ` SentrySpanClientHttpRequestInterceptor ` that creates a span for each outgoing HTTP request executed with a ` RestTemplate ` . To use instrumented ` RestTemplate ` make sure to set interceptor on the ` RestTemplate ` bean:
5253
5354``` java {tabTitle:Java (Spring 5)}
54- import io.sentry.IHub ;
55+ import io.sentry.IScopes ;
5556import io.sentry.spring.tracing.SentrySpanClientHttpRequestInterceptor ;
5657import java.util.Collections ;
5758import org.springframework.context.annotation.Bean ;
5859import org.springframework.context.annotation.Configuration ;
5960import org.springframework.web.client.RestTemplate ;
6061import org.springframework.web.util.UriTemplateHandler ;
62+ import org.springframework.beans.factory.annotation.Autowired ;
63+ import org.springframework.context.ApplicationContext ;
6164
6265@Configuration
6366class AppConfig {
6467
68+ @Autowired
69+ private ApplicationContext applicationContext;
70+
6571 @Bean
66- RestTemplate restTemplate (IHub hub ) {
72+ RestTemplate restTemplate () {
6773 RestTemplate restTemplate = new RestTemplate ();
6874 SentrySpanClientHttpRequestInterceptor sentryRestTemplateInterceptor =
69- new SentrySpanClientHttpRequestInterceptor (hub );
75+ new SentrySpanClientHttpRequestInterceptor (applicationContext . getBean( IScopes . class) );
7076 restTemplate. setInterceptors(Collections . singletonList(sentryRestTemplateInterceptor));
7177 return restTemplate;
7278 }
7379}
7480```
7581
7682``` java {tabTitle:Java (Spring 6)}
77- import io.sentry.IHub ;
83+ import io.sentry.IScopes ;
7884import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor ;
7985import java.util.Collections ;
8086import org.springframework.context.annotation.Bean ;
8187import org.springframework.context.annotation.Configuration ;
8288import org.springframework.web.client.RestTemplate ;
8389import org.springframework.web.util.UriTemplateHandler ;
90+ import org.springframework.beans.factory.annotation.Autowired ;
91+ import org.springframework.context.ApplicationContext ;
8492
8593@Configuration
8694class AppConfig {
8795
96+ @Autowired
97+ private ApplicationContext applicationContext;
98+
8899 @Bean
89- RestTemplate restTemplate (IHub hub ) {
100+ RestTemplate restTemplate () {
90101 RestTemplate restTemplate = new RestTemplate ();
91102 SentrySpanClientHttpRequestInterceptor sentryRestTemplateInterceptor =
92- new SentrySpanClientHttpRequestInterceptor (hub );
103+ new SentrySpanClientHttpRequestInterceptor (applicationContext . getBean( IScopes . class) );
93104 restTemplate. setInterceptors(Collections . singletonList(sentryRestTemplateInterceptor));
94105 return restTemplate;
95106 }
96107}
97108```
98109
99110``` kotlin {tabTitle:Kotlin (Spring 5)}
100- import io.sentry.IHub
111+ import io.sentry.IScopes
101112import io.sentry.spring.tracing.SentrySpanClientHttpRequestInterceptor
102113import org.springframework.context.annotation.Bean
103114import org.springframework.context.annotation.Configuration
104115import org.springframework.web.client.RestTemplate
105116import org.springframework.web.util.UriTemplateHandler
117+ import org.springframework.beans.factory.annotation.Autowired
118+ import org.springframework.context.ApplicationContext
106119
107120@Configuration
108121class AppConfig {
109122
123+ @Autowired
124+ private ApplicationContext applicationContext;
125+
110126 @Bean
111- fun restTemplate (hub : IHub ): RestTemplate {
112- val sentryRestTemplateInterceptor = SentrySpanClientHttpRequestInterceptor (hub )
127+ fun restTemplate (): RestTemplate {
128+ val sentryRestTemplateInterceptor = SentrySpanClientHttpRequestInterceptor (applicationContext.getBean( IScopes . class ) )
113129
114130 return RestTemplate ().apply {
115131 interceptors = listOf (sentryRestTemplateInterceptor)
@@ -119,19 +135,24 @@ class AppConfig {
119135```
120136
121137``` kotlin {tabTitle:Kotlin (Spring 6)}
122- import io.sentry.IHub
138+ import io.sentry.IScopes
123139import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor
124140import org.springframework.context.annotation.Bean
125141import org.springframework.context.annotation.Configuration
126142import org.springframework.web.client.RestTemplate
127143import org.springframework.web.util.UriTemplateHandler
144+ import org.springframework.beans.factory.annotation.Autowired
145+ import org.springframework.context.ApplicationContext
128146
129147@Configuration
130148class AppConfig {
131149
150+ @Autowired
151+ private ApplicationContext applicationContext;
152+
132153 @Bean
133- fun restTemplate (hub : IHub ): RestTemplate {
134- val sentryRestTemplateInterceptor = SentrySpanClientHttpRequestInterceptor (hub )
154+ fun restTemplate (): RestTemplate {
155+ val sentryRestTemplateInterceptor = SentrySpanClientHttpRequestInterceptor (applicationContext.getBean( IScopes . class ) )
135156
136157 return RestTemplate ().apply {
137158 interceptors = listOf (sentryRestTemplateInterceptor)
0 commit comments