-
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 ArmeriaTelemetry into client and server #12851
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ad478d5
Split ArmeriaTelemetry into client and server
trask 32b923b
Merge remote-tracking branch 'upstream/main' into split-armeria
trask a4463f6
Fix javadoc todo
trask 1e35fa5
Merge remote-tracking branch 'upstream/main' into split-armeria
trask b7c02d3
remove reflection
trask f396767
volatile
trask d114ae6
fix
trask 06d5be8
Merge remote-tracking branch 'upstream/main' into split-armeria
trask 28b4c18
Remove unused
trask b8b6bbe
Test deprecated API
trask 89e09d0
comment
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
42 changes: 42 additions & 0 deletions
42
...y/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetry.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,42 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.armeria.v1_3; | ||
|
||
import com.linecorp.armeria.client.ClientRequestContext; | ||
import com.linecorp.armeria.client.HttpClient; | ||
import com.linecorp.armeria.common.logging.RequestLog; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import java.util.function.Function; | ||
|
||
/** Entrypoint for instrumenting Armeria clients. */ | ||
public final class ArmeriaClientTelemetry { | ||
|
||
/** | ||
* Returns a new {@link ArmeriaClientTelemetry} configured with the given {@link OpenTelemetry}. | ||
*/ | ||
public static ArmeriaClientTelemetry create(OpenTelemetry openTelemetry) { | ||
return builder(openTelemetry).build(); | ||
} | ||
|
||
public static ArmeriaClientTelemetryBuilder builder(OpenTelemetry openTelemetry) { | ||
return new ArmeriaClientTelemetryBuilder(openTelemetry); | ||
} | ||
|
||
private final Instrumenter<ClientRequestContext, RequestLog> instrumenter; | ||
|
||
ArmeriaClientTelemetry(Instrumenter<ClientRequestContext, RequestLog> instrumenter) { | ||
this.instrumenter = instrumenter; | ||
} | ||
|
||
/** | ||
* Returns a new {@link HttpClient} decorator for use with methods like {@link | ||
* com.linecorp.armeria.client.ClientBuilder#decorator(Function)}. | ||
*/ | ||
public Function<? super HttpClient, ? extends HttpClient> newDecorator() { | ||
return client -> new OpenTelemetryClient(client, instrumenter); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...ain/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetryBuilder.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,117 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.armeria.v1_3; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import com.linecorp.armeria.client.ClientRequestContext; | ||
import com.linecorp.armeria.common.logging.RequestLog; | ||
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.instrumenter.SpanStatusExtractor; | ||
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; | ||
import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderFactory; | ||
import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; | ||
import io.opentelemetry.instrumentation.armeria.v1_3.internal.Experimental; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
public final class ArmeriaClientTelemetryBuilder { | ||
|
||
private final DefaultHttpClientInstrumenterBuilder<ClientRequestContext, RequestLog> builder; | ||
|
||
static { | ||
ArmeriaInstrumenterBuilderUtil.setClientBuilderExtractor(builder -> builder.builder); | ||
Experimental.setSetEmitExperimentalClientTelemetry( | ||
(builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); | ||
Experimental.setSetClientPeerService( | ||
(builder, peerService) -> builder.builder.setPeerService(peerService)); | ||
} | ||
|
||
ArmeriaClientTelemetryBuilder(OpenTelemetry openTelemetry) { | ||
builder = ArmeriaInstrumenterBuilderFactory.getClientBuilder(openTelemetry); | ||
} | ||
|
||
/** Sets the status extractor for client spans. */ | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder setStatusExtractor( | ||
Function< | ||
SpanStatusExtractor<? super ClientRequestContext, ? super RequestLog>, | ||
? extends SpanStatusExtractor<? super ClientRequestContext, ? super RequestLog>> | ||
statusExtractor) { | ||
builder.setStatusExtractor(statusExtractor); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds an extra {@link AttributesExtractor} to invoke to set attributes to instrumented items. | ||
* The {@link AttributesExtractor} will be executed after all default extractors. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder addAttributesExtractor( | ||
AttributesExtractor<? super ClientRequestContext, ? super RequestLog> attributesExtractor) { | ||
builder.addAttributesExtractor(attributesExtractor); | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the HTTP client request headers that will be captured as span attributes. | ||
* | ||
* @param requestHeaders A list of HTTP header names. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder setCapturedRequestHeaders(List<String> requestHeaders) { | ||
builder.setCapturedRequestHeaders(requestHeaders); | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the HTTP client response headers that will be captured as span attributes. | ||
* | ||
* @param responseHeaders A list of HTTP header names. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder 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 ArmeriaClientTelemetryBuilder setKnownMethods(Set<String> knownMethods) { | ||
builder.setKnownMethods(knownMethods); | ||
return this; | ||
} | ||
|
||
/** Sets custom client {@link SpanNameExtractor} via transform function. */ | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder setSpanNameExtractor( | ||
Function< | ||
SpanNameExtractor<? super ClientRequestContext>, | ||
? extends SpanNameExtractor<? super ClientRequestContext>> | ||
clientSpanNameExtractor) { | ||
builder.setSpanNameExtractor(clientSpanNameExtractor); | ||
return this; | ||
} | ||
|
||
public ArmeriaClientTelemetry build() { | ||
return new ArmeriaClientTelemetry(builder.build()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...y/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetry.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,42 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.armeria.v1_3; | ||
|
||
import com.linecorp.armeria.common.logging.RequestLog; | ||
import com.linecorp.armeria.server.HttpService; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import java.util.function.Function; | ||
|
||
/** Entrypoint for instrumenting Armeria services. */ | ||
public final class ArmeriaServerTelemetry { | ||
|
||
/** | ||
* Returns a new {@link ArmeriaServerTelemetry} configured with the given {@link OpenTelemetry}. | ||
*/ | ||
public static ArmeriaServerTelemetry create(OpenTelemetry openTelemetry) { | ||
return builder(openTelemetry).build(); | ||
} | ||
|
||
public static ArmeriaServerTelemetryBuilder builder(OpenTelemetry openTelemetry) { | ||
return new ArmeriaServerTelemetryBuilder(openTelemetry); | ||
} | ||
|
||
private final Instrumenter<ServiceRequestContext, RequestLog> instrumenter; | ||
|
||
ArmeriaServerTelemetry(Instrumenter<ServiceRequestContext, RequestLog> instrumenter) { | ||
this.instrumenter = instrumenter; | ||
} | ||
|
||
/** | ||
* Returns a new {@link HttpService} decorator for use with methods like {@link | ||
* HttpService#decorate(Function)}. | ||
*/ | ||
public Function<? super HttpService, ? extends HttpService> newDecorator() { | ||
return service -> new OpenTelemetryService(service, instrumenter); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...ain/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetryBuilder.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.armeria.v1_3; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import com.linecorp.armeria.common.logging.RequestLog; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; | ||
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; | ||
import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderFactory; | ||
import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; | ||
import io.opentelemetry.instrumentation.armeria.v1_3.internal.Experimental; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
public final class ArmeriaServerTelemetryBuilder { | ||
|
||
private final DefaultHttpServerInstrumenterBuilder<ServiceRequestContext, RequestLog> builder; | ||
|
||
static { | ||
ArmeriaInstrumenterBuilderUtil.setServerBuilderExtractor(builder -> builder.builder); | ||
Experimental.setSetEmitExperimentalServerTelemetry( | ||
(builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); | ||
} | ||
|
||
ArmeriaServerTelemetryBuilder(OpenTelemetry openTelemetry) { | ||
builder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); | ||
} | ||
|
||
/** Sets the status extractor for server spans. */ | ||
@CanIgnoreReturnValue | ||
public ArmeriaServerTelemetryBuilder setStatusExtractor( | ||
Function< | ||
SpanStatusExtractor<? super ServiceRequestContext, ? super RequestLog>, | ||
? extends SpanStatusExtractor<? super ServiceRequestContext, ? super RequestLog>> | ||
statusExtractor) { | ||
builder.setStatusExtractor(statusExtractor); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds an extra {@link AttributesExtractor} to invoke to set attributes to instrumented items. | ||
* The {@link AttributesExtractor} will be executed after all default extractors. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaServerTelemetryBuilder addAttributesExtractor( | ||
AttributesExtractor<? super ServiceRequestContext, ? super RequestLog> attributesExtractor) { | ||
builder.addAttributesExtractor(attributesExtractor); | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the HTTP server request headers that will be captured as span attributes. | ||
* | ||
* @param requestHeaders A list of HTTP header names. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaServerTelemetryBuilder setCapturedRequestHeaders(List<String> requestHeaders) { | ||
builder.setCapturedRequestHeaders(requestHeaders); | ||
return this; | ||
} | ||
|
||
/** | ||
* Configures the HTTP server response headers that will be captured as span attributes. | ||
* | ||
* @param responseHeaders A list of HTTP header names. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaServerTelemetryBuilder 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 HttpServerAttributesExtractorBuilder#setKnownMethods(Set) | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaServerTelemetryBuilder setKnownMethods(Set<String> knownMethods) { | ||
builder.setKnownMethods(knownMethods); | ||
return this; | ||
} | ||
|
||
/** Sets custom server {@link SpanNameExtractor} via transform function. */ | ||
@CanIgnoreReturnValue | ||
public ArmeriaServerTelemetryBuilder setSpanNameExtractor( | ||
Function< | ||
SpanNameExtractor<? super ServiceRequestContext>, | ||
? extends SpanNameExtractor<? super ServiceRequestContext>> | ||
serverSpanNameExtractor) { | ||
builder.setSpanNameExtractor(serverSpanNameExtractor); | ||
return this; | ||
} | ||
|
||
public ArmeriaServerTelemetry build() { | ||
return new ArmeriaServerTelemetry(builder.build()); | ||
} | ||
} |
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.
ktor has server and client instrumentations in separate packages, should we do the same here or change ktor?
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.
good question... 🤔
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.
since they're small packages and we'd probably want to keep "Client" and "Server" in the class names not to conflict anyways, I think I'm leaning towards single package (and changing ktor)
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.
one benefit for having a single package could be that when you initially have only server instrumentation, like in ktor-1, then adding client instrumentation wouldn't force changing the package (unless the author had the foresight to use the correct package from the start).