-
Notifications
You must be signed in to change notification settings - Fork 871
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
http server and client builder for netty #12083
Changes from all commits
900d778
d6d20c5
dd083c9
a104924
ff4ceff
9258ae8
6358874
119fcc8
0af98e7
67a75d5
41505ec
37c5ac5
1b76b37
eb0cc91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,23 +53,26 @@ public final class DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> { | |
httpAttributesExtractorBuilder; | ||
private final HttpSpanNameExtractorBuilder<REQUEST> httpSpanNameExtractorBuilder; | ||
|
||
@Nullable private TextMapGetter<REQUEST> headerGetter; | ||
@Nullable private final TextMapGetter<REQUEST> headerGetter; | ||
private Function<SpanNameExtractor<? super REQUEST>, ? extends SpanNameExtractor<? super REQUEST>> | ||
spanNameExtractorTransformer = Function.identity(); | ||
private final HttpServerRouteBuilder<REQUEST> httpServerRouteBuilder; | ||
private final HttpServerAttributesGetter<REQUEST, RESPONSE> attributesGetter; | ||
private boolean emitExperimentalHttpServerMetrics = false; | ||
private Consumer<InstrumenterBuilder<REQUEST, RESPONSE>> builderCustomizer = b -> {}; | ||
|
||
public DefaultHttpServerInstrumenterBuilder( | ||
String instrumentationName, | ||
OpenTelemetry openTelemetry, | ||
HttpServerAttributesGetter<REQUEST, RESPONSE> attributesGetter) { | ||
HttpServerAttributesGetter<REQUEST, RESPONSE> attributesGetter, | ||
@Nullable TextMapGetter<REQUEST> headerGetter) { | ||
this.instrumentationName = instrumentationName; | ||
this.openTelemetry = openTelemetry; | ||
httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(attributesGetter); | ||
httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(attributesGetter); | ||
httpServerRouteBuilder = HttpServerRoute.builder(attributesGetter); | ||
this.attributesGetter = attributesGetter; | ||
this.headerGetter = headerGetter; | ||
} | ||
|
||
/** | ||
|
@@ -139,13 +142,6 @@ public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> setKnownMethods( | |
return this; | ||
} | ||
|
||
@CanIgnoreReturnValue | ||
public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> setHeaderGetter( | ||
@Nullable TextMapGetter<REQUEST> headerGetter) { | ||
this.headerGetter = headerGetter; | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the instrumentation to emit experimental HTTP server metrics. | ||
* | ||
|
@@ -168,16 +164,14 @@ public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> setSpanNameExtrac | |
return this; | ||
} | ||
|
||
public Instrumenter<REQUEST, RESPONSE> build() { | ||
InstrumenterBuilder<REQUEST, RESPONSE> builder = builder(); | ||
|
||
if (headerGetter != null) { | ||
return builder.buildServerInstrumenter(headerGetter); | ||
} | ||
return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); | ||
@CanIgnoreReturnValue | ||
public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> setBuilderCustomizer( | ||
Consumer<InstrumenterBuilder<REQUEST, RESPONSE>> builderCustomizer) { | ||
this.builderCustomizer = builderCustomizer; | ||
return this; | ||
} | ||
|
||
private InstrumenterBuilder<REQUEST, RESPONSE> builder() { | ||
public Instrumenter<REQUEST, RESPONSE> build() { | ||
SpanNameExtractor<? super REQUEST> spanNameExtractor = | ||
spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); | ||
|
||
|
@@ -195,8 +189,12 @@ private InstrumenterBuilder<REQUEST, RESPONSE> builder() { | |
.addAttributesExtractor(HttpExperimentalAttributesExtractor.create(attributesGetter)) | ||
.addOperationMetrics(HttpServerExperimentalMetrics.get()); | ||
} | ||
builderCustomizer.accept(builder); | ||
|
||
return builder; | ||
if (headerGetter != null) { | ||
return builder.buildServerInstrumenter(headerGetter); | ||
} | ||
return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); | ||
Comment on lines
+194
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are there any server instrumentations that don't provide a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, they all do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made it part of the ctor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just found that ktor doesn't have the header getter - but this is an upcoming pr |
||
} | ||
|
||
@CanIgnoreReturnValue | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.netty.v4.common.internal.client; | ||
|
||
import io.netty.handler.codec.http.HttpResponse; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; | ||
import io.opentelemetry.instrumentation.netty.v4.common.HttpRequestAndChannel; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public final class NettyClientInstrumenterBuilderFactory { | ||
private NettyClientInstrumenterBuilderFactory() {} | ||
|
||
public static DefaultHttpClientInstrumenterBuilder<HttpRequestAndChannel, HttpResponse> create( | ||
String instrumentationName, OpenTelemetry openTelemetry) { | ||
|
||
return new DefaultHttpClientInstrumenterBuilder<>( | ||
instrumentationName, openTelemetry, new NettyHttpClientAttributesGetter()) | ||
.setHeaderSetter(HttpRequestHeadersSetter.INSTANCE); | ||
} | ||
} |
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.
this method is confusing, I finally understood it, but wonder if there's anything we can do to make it clearer
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.
maybe
toInstrumenterBuilder
?