Skip to content

Commit 1a37ba3

Browse files
authored
Document RestClient and WebClient for Spring Boot (#9531)
1 parent 1f2f574 commit 1a37ba3

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

docs/platforms/java/guides/spring-boot/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Sentry Spring Boot integration provides `SentrySpanRestTemplateCustomizer` that
5454
import org.springframework.context.annotation.Configuration;
5555
import org.springframework.context.annotation.Bean;
5656
import org.springframework.boot.web.client.RestTemplateBuilder;
57+
import org.springframework.web.client.RestTemplate;
5758

5859
@Configuration
5960
class AppConfig {
@@ -68,10 +69,71 @@ class AppConfig {
6869
import org.springframework.context.annotation.Configuration
6970
import org.springframework.context.annotation.Bean
7071
import org.springframework.boot.web.client.RestTemplateBuilder
72+
import org.springframework.web.client.RestTemplate
7173

7274
@Configuration
7375
class AppConfig {
7476
@Bean
7577
fun restTemplate(builder: RestTemplateBuilder) = builder.build()
7678
}
7779
```
80+
81+
### RestClient Instrumentation
82+
83+
Sentry Spring Boot integration provides `SentrySpanRestClientCustomizer` that creates a span for each outgoing HTTP request executed with a `RestClient`. To use instrumented `RestClient` make sure to create `RestClient` beans using `RestClient.Builder`:
84+
85+
```java {tabTitle:Java}
86+
import org.springframework.context.annotation.Configuration;
87+
import org.springframework.context.annotation.Bean;
88+
import org.springframework.web.client.RestClient;
89+
90+
@Configuration
91+
class AppConfig {
92+
@Bean
93+
RestClient restClient(RestClient.Builder builder) {
94+
return builder.build();
95+
}
96+
}
97+
```
98+
99+
```kotlin {tabTitle:Kotlin}
100+
import org.springframework.context.annotation.Configuration
101+
import org.springframework.context.annotation.Bean
102+
import org.springframework.web.client.RestClient
103+
104+
@Configuration
105+
class AppConfig {
106+
@Bean
107+
fun restClient(builder: RestClient.Builder) = builder.build()
108+
}
109+
```
110+
111+
### WebClient Instrumentation
112+
113+
Sentry Spring Boot integration provides `SentrySpanWebClientCustomizer` that creates a span for each outgoing HTTP request executed with a `WebClient`. To use instrumented `WebClient` make sure to create `WebClient` beans using `WebClient.Builder`:
114+
115+
```java {tabTitle:Java}
116+
import org.springframework.context.annotation.Configuration;
117+
import org.springframework.context.annotation.Bean;
118+
import org.springframework.web.reactive.function.client.WebClient;
119+
120+
@Configuration
121+
class AppConfig {
122+
@Bean
123+
WebClient webClient(WebClient.Builder builder) {
124+
return builder.build();
125+
}
126+
}
127+
```
128+
129+
```kotlin {tabTitle:Kotlin}
130+
import org.springframework.context.annotation.Configuration
131+
import org.springframework.context.annotation.Bean
132+
import org.springframework.web.reactive.function.client.WebClient
133+
134+
@Configuration
135+
class AppConfig {
136+
@Bean
137+
fun webClient(builder: WebClient.Builder) = builder.build()
138+
}
139+
```

0 commit comments

Comments
 (0)