-
-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathWebConfig.java
More file actions
37 lines (33 loc) · 1.41 KB
/
WebConfig.java
File metadata and controls
37 lines (33 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package io.sentry.samples.spring;
import io.sentry.IScopes;
import io.sentry.spring.tracing.SentrySpanClientHttpRequestInterceptor;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@ComponentScan("io.sentry.samples.spring.web")
@EnableWebMvc
public class WebConfig {
@Autowired private ApplicationContext applicationContext;
/**
* Creates a {@link RestTemplate} which calls are intercepted with {@link
* SentrySpanClientHttpRequestInterceptor} to create spans around HTTP calls.
*
* @return RestTemplate
*/
@Bean
RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
SentrySpanClientHttpRequestInterceptor sentryRestTemplateInterceptor =
new SentrySpanClientHttpRequestInterceptor(applicationContext.getBean(IScopes.class));
restTemplate.setInterceptors(Collections.singletonList(sentryRestTemplateInterceptor));
return restTemplate;
}
}