-
Notifications
You must be signed in to change notification settings - Fork 879
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
Split Webflux into client and server #12852
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3ca45a4
Split Webflux into client and server
trask 15e7735
Merge remote-tracking branch 'upstream/main' into split-webflux
trask 2631775
Fix javadoc todo
trask 9ca4774
Merge remote-tracking branch 'upstream/main' into split-webflux
trask 52101cb
remove reflection
trask f759525
volatile
trask 1e112b0
static
trask ae21b8b
Merge remote-tracking branch 'upstream/main' into split-webflux
trask e141184
Remove unused
trask 0b05aac
test deprecated classes
trask 3e42d98
test deprecated classes
trask 7c6d14b
test deprecated classes
trask af10a0b
test deprecated classes
trask 4e2bc5b
fix
trask e3fd190
Update docs and one more rename
trask 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
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
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
54 changes: 54 additions & 0 deletions
54
...va/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetry.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,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.webflux.v5_3; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.context.propagation.ContextPropagators; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientTracingFilter; | ||
import java.util.List; | ||
import org.springframework.web.reactive.function.client.ClientRequest; | ||
import org.springframework.web.reactive.function.client.ClientResponse; | ||
import org.springframework.web.reactive.function.client.ExchangeFilterFunction; | ||
|
||
/** Entrypoint for instrumenting Spring Webflux HTTP clients. */ | ||
public final class SpringWebfluxClientTelemetry { | ||
|
||
/** | ||
* Returns a new {@link SpringWebfluxClientTelemetry} configured with the given {@link | ||
* OpenTelemetry}. | ||
*/ | ||
public static SpringWebfluxClientTelemetry create(OpenTelemetry openTelemetry) { | ||
return builder(openTelemetry).build(); | ||
} | ||
|
||
/** | ||
* Returns a new {@link SpringWebfluxClientTelemetryBuilder} configured with the given {@link | ||
* OpenTelemetry}. | ||
*/ | ||
public static SpringWebfluxClientTelemetryBuilder builder(OpenTelemetry openTelemetry) { | ||
return new SpringWebfluxClientTelemetryBuilder(openTelemetry); | ||
} | ||
|
||
private final Instrumenter<ClientRequest, ClientResponse> clientInstrumenter; | ||
private final ContextPropagators propagators; | ||
|
||
SpringWebfluxClientTelemetry( | ||
Instrumenter<ClientRequest, ClientResponse> clientInstrumenter, | ||
ContextPropagators propagators) { | ||
this.clientInstrumenter = clientInstrumenter; | ||
this.propagators = propagators; | ||
} | ||
|
||
public void addFilter(List<ExchangeFilterFunction> exchangeFilterFunctions) { | ||
for (ExchangeFilterFunction filterFunction : exchangeFilterFunctions) { | ||
if (filterFunction instanceof WebClientTracingFilter) { | ||
return; | ||
} | ||
} | ||
exchangeFilterFunctions.add(new WebClientTracingFilter(clientInstrumenter, propagators)); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...pentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxClientTelemetryBuilder.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,115 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.webflux.v5_3; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; | ||
import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.Experimental; | ||
import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.SpringWebfluxBuilderUtil; | ||
import io.opentelemetry.instrumentation.spring.webflux.v5_3.internal.WebClientHttpAttributesGetter; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import org.springframework.web.reactive.function.client.ClientRequest; | ||
import org.springframework.web.reactive.function.client.ClientResponse; | ||
|
||
/** A builder of {@link SpringWebfluxClientTelemetry}. */ | ||
public final class SpringWebfluxClientTelemetryBuilder { | ||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.spring-webflux-5.3"; | ||
|
||
private final DefaultHttpClientInstrumenterBuilder<ClientRequest, ClientResponse> builder; | ||
private final OpenTelemetry openTelemetry; | ||
|
||
static { | ||
SpringWebfluxBuilderUtil.setClientBuilderExtractor(builder -> builder.builder); | ||
Experimental.setSetEmitExperimentalClientTelemetry( | ||
(builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); | ||
} | ||
|
||
SpringWebfluxClientTelemetryBuilder(OpenTelemetry openTelemetry) { | ||
builder = | ||
DefaultHttpClientInstrumenterBuilder.create( | ||
INSTRUMENTATION_NAME, openTelemetry, WebClientHttpAttributesGetter.INSTANCE); | ||
this.openTelemetry = openTelemetry; | ||
} | ||
|
||
/** | ||
* Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented | ||
* items for WebClient. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public SpringWebfluxClientTelemetryBuilder addAttributesExtractor( | ||
AttributesExtractor<ClientRequest, ClientResponse> attributesExtractor) { | ||
builder.addAttributesExtractor(attributesExtractor); | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the HTTP WebClient request headers that will be captured as span attributes. | ||
* | ||
* @param requestHeaders A list of HTTP header names. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public SpringWebfluxClientTelemetryBuilder setCapturedRequestHeaders( | ||
List<String> requestHeaders) { | ||
builder.setCapturedRequestHeaders(requestHeaders); | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the HTTP WebClient response headers that will be captured as span attributes. | ||
* | ||
* @param responseHeaders A list of HTTP header names. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public SpringWebfluxClientTelemetryBuilder setCapturedResponseHeaders( | ||
List<String> responseHeaders) { | ||
builder.setCapturedResponseHeaders(responseHeaders); | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the instrumentation to recognize an alternative set of HTTP request methods. | ||
* | ||
* <p>By default, this instrumentation defines "known" methods as the ones listed in <a | ||
* href="https://www.rfc-editor.org/rfc/rfc9110.html#name-methods">RFC9110</a> and the PATCH | ||
* method defined in <a href="https://www.rfc-editor.org/rfc/rfc5789.html">RFC5789</a>. | ||
* | ||
* <p>Note: calling this method <b>overrides</b> the default known method sets completely; it does | ||
* not supplement it. | ||
* | ||
* @param knownMethods A set of recognized HTTP request methods. | ||
* @see HttpClientAttributesExtractorBuilder#setKnownMethods(Set) | ||
*/ | ||
@CanIgnoreReturnValue | ||
public SpringWebfluxClientTelemetryBuilder setKnownMethods(Set<String> knownMethods) { | ||
builder.setKnownMethods(knownMethods); | ||
return this; | ||
} | ||
|
||
/** Sets custom client {@link SpanNameExtractor} via transform function. */ | ||
@CanIgnoreReturnValue | ||
public SpringWebfluxClientTelemetryBuilder setSpanNameExtractor( | ||
Function< | ||
SpanNameExtractor<? super ClientRequest>, | ||
? extends SpanNameExtractor<? super ClientRequest>> | ||
clientSpanNameExtractor) { | ||
builder.setSpanNameExtractor(clientSpanNameExtractor); | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns a new {@link SpringWebfluxClientTelemetry} with the settings of this {@link | ||
* SpringWebfluxClientTelemetryBuilder}. | ||
*/ | ||
public SpringWebfluxClientTelemetry build() { | ||
return new SpringWebfluxClientTelemetry(builder.build(), openTelemetry.getPropagators()); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...va/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxServerTelemetry.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,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.webflux.v5_3; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.instrumentation.reactor.v3_1.ContextPropagationOperator; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebFilter; | ||
|
||
/** Entrypoint for instrumenting Spring Webflux HTTP services. */ | ||
public final class SpringWebfluxServerTelemetry { | ||
|
||
/** | ||
* Returns a new {@link SpringWebfluxServerTelemetry} configured with the given {@link | ||
* OpenTelemetry}. | ||
*/ | ||
public static SpringWebfluxServerTelemetry create(OpenTelemetry openTelemetry) { | ||
return builder(openTelemetry).build(); | ||
} | ||
|
||
/** | ||
* Returns a new {@link SpringWebfluxServerTelemetryBuilder} configured with the given {@link | ||
* OpenTelemetry}. | ||
*/ | ||
public static SpringWebfluxServerTelemetryBuilder builder(OpenTelemetry openTelemetry) { | ||
return new SpringWebfluxServerTelemetryBuilder(openTelemetry); | ||
} | ||
|
||
// We use ServerWebExchange (which holds both the request and response) | ||
// because we need it to get the HTTP route while instrumenting. | ||
private final Instrumenter<ServerWebExchange, ServerWebExchange> serverInstrumenter; | ||
|
||
SpringWebfluxServerTelemetry( | ||
Instrumenter<ServerWebExchange, ServerWebExchange> serverInstrumenter) { | ||
this.serverInstrumenter = serverInstrumenter; | ||
} | ||
|
||
public WebFilter createWebFilter() { | ||
return new TelemetryProducingWebFilter(serverInstrumenter); | ||
} | ||
|
||
public WebFilter createWebFilterAndRegisterReactorHook() { | ||
registerReactorHook(); | ||
return this.createWebFilter(); | ||
} | ||
|
||
private static void registerReactorHook() { | ||
ContextPropagationOperator.builder().build().registerOnEachOperator(); | ||
} | ||
} |
Oops, something went wrong.
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.
same question as with armeria, do we want client and server instrumentation in separate packages as with ktor