-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix spring webflux latest dep tests #15304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ibrary/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/HeaderUtil.java
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.spring.webflux.v5_3; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
|
|
||
| import java.lang.invoke.MethodHandle; | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.lang.invoke.MethodType; | ||
| import java.util.List; | ||
| import javax.annotation.Nullable; | ||
| import org.springframework.http.HttpHeaders; | ||
|
|
||
| class HeaderUtil { | ||
| @Nullable private static final MethodHandle GET_HEADERS; | ||
|
|
||
| static { | ||
| // since spring web 7.0 | ||
| MethodHandle methodHandle = | ||
| findGetHeadersMethod(MethodType.methodType(List.class, String.class, List.class)); | ||
| if (methodHandle == null) { | ||
| // up to spring web 7.0 | ||
| methodHandle = | ||
| findGetHeadersMethod(MethodType.methodType(Object.class, Object.class, Object.class)); | ||
| } | ||
| GET_HEADERS = methodHandle; | ||
| } | ||
|
|
||
| private static MethodHandle findGetHeadersMethod(MethodType methodType) { | ||
| try { | ||
| return MethodHandles.lookup().findVirtual(HttpHeaders.class, "getOrDefault", methodType); | ||
| } catch (Throwable t) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") // casting MethodHandle.invoke result | ||
| static List<String> getHeader(HttpHeaders headers, String name) { | ||
| if (GET_HEADERS != null) { | ||
| try { | ||
| return (List<String>) GET_HEADERS.invoke(headers, name, emptyList()); | ||
| } catch (Throwable t) { | ||
| // ignore | ||
| } | ||
| } | ||
| return emptyList(); | ||
| } | ||
|
|
||
| private HeaderUtil() {} | ||
| } |
This file contains hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
instrumentation/spring/spring-webflux/spring-webflux-5.3/testing-webflux7/build.gradle.kts
This file contains hidden or 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,8 @@ | ||
| plugins { | ||
| id("otel.java-conventions") | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation("io.opentelemetry.javaagent:opentelemetry-testing-common") | ||
| compileOnly("org.springframework:spring-webflux:7.0.0") | ||
| } |
53 changes: 53 additions & 0 deletions
53
...x7/src/main/java/io/opentelemetry/instrumentation/spring/webflux/client/Webflux7Util.java
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.spring.webflux.client; | ||
|
|
||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
| import org.springframework.web.reactive.function.client.ClientResponse; | ||
| import org.springframework.web.reactive.function.client.WebClient; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| class Webflux7Util { | ||
| static final boolean isWebflux7 = detectWebflux7(); | ||
|
|
||
| private static boolean detectWebflux7() { | ||
| try { | ||
| WebClient.RequestBodySpec.class.getMethod("exchange"); | ||
| return false; | ||
| } catch (NoSuchMethodException e) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| static Mono<ClientResponse> exchangeToMono(WebClient.RequestBodySpec request) { | ||
| return request.exchangeToMono(Mono::just); | ||
| } | ||
|
|
||
| static <T> T doRequest( | ||
| WebClient.RequestBodySpec request, Function<ClientResponse, Mono<T>> handler) { | ||
| return request.exchangeToMono(handler).block(); | ||
| } | ||
|
|
||
| static int doRequest(WebClient.RequestBodySpec request) { | ||
| return doRequest(request, response -> Mono.just(response.statusCode().value())); | ||
| } | ||
|
|
||
| static int getStatusCode(ClientResponse response) { | ||
| return response.statusCode().value(); | ||
| } | ||
|
|
||
| static void sendRequestWithCallback( | ||
| WebClient.RequestBodySpec request, | ||
| Consumer<Integer> callback, | ||
| Consumer<Throwable> errorCallback) { | ||
| request | ||
| .exchangeToMono(response -> Mono.just(response.statusCode().value())) | ||
| .subscribe(callback, errorCallback); | ||
| } | ||
|
|
||
| private Webflux7Util() {} | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to look into this more thoroughly. As far as I can tell context is propagated with the agent but not with the library instrumentation.