-
Notifications
You must be signed in to change notification settings - Fork 872
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ArmeriaTelemetry into client and server
- Loading branch information
Showing
11 changed files
with
579 additions
and
52 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
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); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
...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,130 @@ | ||
/* | ||
* 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); | ||
} | ||
|
||
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 client-only {@link AttributesExtractor} to invoke to set attributes to | ||
* instrumented items. The {@link AttributesExtractor} will be executed after all default | ||
* extractors. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder addAttributeExtractor( | ||
AttributesExtractor<? super ClientRequestContext, ? super RequestLog> attributesExtractor) { | ||
builder.addAttributeExtractor(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; | ||
} | ||
|
||
/** | ||
* Can be used via the unstable method {@link | ||
* Experimental#setClientPeerService(ArmeriaClientTelemetryBuilder, String)}. | ||
*/ | ||
void setPeerService(String peerService) { | ||
builder.setPeerService(peerService); | ||
} | ||
|
||
/** | ||
* Can be used via the unstable method {@link | ||
* Experimental#setEmitExperimentalHttpClientMetrics(ArmeriaClientTelemetryBuilder, boolean)}. | ||
*/ | ||
void setEmitExperimentalHttpClientMetrics(boolean emitExperimentalHttpClientMetrics) { | ||
builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); | ||
} | ||
|
||
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); | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
...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,122 @@ | ||
/* | ||
* 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); | ||
} | ||
|
||
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 server-only {@link AttributesExtractor} to invoke to set attributes to | ||
* instrumented items. The {@link AttributesExtractor} will be executed after all default | ||
* extractors. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public ArmeriaServerTelemetryBuilder addAttributeExtractor( | ||
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; | ||
} | ||
|
||
/** | ||
* Can be used via the unstable method {@link | ||
* Experimental#setEmitExperimentalHttpServerMetrics(ArmeriaServerTelemetryBuilder, boolean)}. | ||
*/ | ||
void setEmitExperimentalHttpServerMetrics(boolean emitExperimentalHttpServerMetrics) { | ||
builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); | ||
} | ||
|
||
public ArmeriaServerTelemetry build() { | ||
return new ArmeriaServerTelemetry(builder.build()); | ||
} | ||
} |
Oops, something went wrong.