-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add instrumentation for RestTemplateBuilder (#11054)
Co-authored-by: Jean Bisutti <[email protected]>
- Loading branch information
1 parent
4c77b48
commit 7de246b
Showing
5 changed files
with
151 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...instrumentation/spring/autoconfigure/instrumentation/web/RestTemplateInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.web; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.spring.web.v3_1.SpringWebTelemetry; | ||
import java.util.List; | ||
import org.springframework.http.client.ClientHttpRequestInterceptor; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
class RestTemplateInstrumentation { | ||
|
||
private RestTemplateInstrumentation() {} | ||
|
||
@CanIgnoreReturnValue | ||
static RestTemplate addIfNotPresent(RestTemplate restTemplate, OpenTelemetry openTelemetry) { | ||
ClientHttpRequestInterceptor instrumentationInterceptor = | ||
SpringWebTelemetry.create(openTelemetry).newInterceptor(); | ||
|
||
List<ClientHttpRequestInterceptor> restTemplateInterceptors = restTemplate.getInterceptors(); | ||
if (restTemplateInterceptors.stream() | ||
.noneMatch( | ||
interceptor -> interceptor.getClass() == instrumentationInterceptor.getClass())) { | ||
restTemplateInterceptors.add(0, instrumentationInterceptor); | ||
} | ||
return restTemplate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters