-
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
588 additions
and
47 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); | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
...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,149 @@ | ||
/* | ||
* 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( | ||
ArmeriaClientTelemetryBuilder::getBuilder); | ||
} | ||
|
||
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; | ||
} | ||
|
||
/** | ||
* Sets the {@code peer.service} attribute for http client spans. | ||
* | ||
* @deprecated Use {@link Experimental#setClientPeerService(ArmeriaClientTelemetryBuilder, | ||
* String)} instead. | ||
*/ | ||
@Deprecated | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder setPeerService(String peerService) { | ||
builder.setPeerService(peerService); | ||
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; | ||
} | ||
|
||
/** | ||
* Configures the instrumentation to emit experimental HTTP client metrics. | ||
* | ||
* @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics | ||
* are to be emitted. | ||
* @deprecated Use {@link | ||
* Experimental#setEmitExperimentalHttpClientMetrics(ArmeriaClientTelemetryBuilder, boolean)} | ||
* instead. | ||
*/ | ||
@Deprecated | ||
@CanIgnoreReturnValue | ||
public ArmeriaClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( | ||
boolean emitExperimentalHttpClientMetrics) { | ||
builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); | ||
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()); | ||
} | ||
|
||
private DefaultHttpClientInstrumenterBuilder<ClientRequestContext, RequestLog> getBuilder() { | ||
return builder; | ||
} | ||
} |
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); | ||
} | ||
} |
Oops, something went wrong.