Allow configuring captured HTTP headers in library instrumentations (#4309)
This commit is contained in:
parent
d3dbe415a1
commit
f80f4a9f63
|
@ -16,9 +16,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
final class ApacheHttpClientHttpAttributesExtractor
|
final class ApacheHttpClientHttpAttributesExtractor
|
||||||
extends HttpClientAttributesExtractor<ApacheHttpClientRequest, HttpResponse> {
|
extends HttpClientAttributesExtractor<ApacheHttpClientRequest, HttpResponse> {
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
ApacheHttpClientHttpAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
ApacheHttpClientHttpAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
package io.opentelemetry.instrumentation.apachehttpclient.v4_3;
|
package io.opentelemetry.instrumentation.apachehttpclient.v4_3;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
||||||
|
@ -27,6 +29,7 @@ public final class ApacheHttpClientTracingBuilder {
|
||||||
|
|
||||||
private final List<AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>>
|
private final List<AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>>
|
||||||
additionalExtractors = new ArrayList<>();
|
additionalExtractors = new ArrayList<>();
|
||||||
|
private CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.client(Config.get());
|
||||||
|
|
||||||
ApacheHttpClientTracingBuilder(OpenTelemetry openTelemetry) {
|
ApacheHttpClientTracingBuilder(OpenTelemetry openTelemetry) {
|
||||||
this.openTelemetry = openTelemetry;
|
this.openTelemetry = openTelemetry;
|
||||||
|
@ -43,13 +46,26 @@ public final class ApacheHttpClientTracingBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the instrumentation to capture chosen HTTP request and response headers as span
|
||||||
|
* attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpHeaders An instance of {@link CapturedHttpHeaders} containing the configured
|
||||||
|
* HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public ApacheHttpClientTracingBuilder captureHttpHeaders(
|
||||||
|
CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
|
this.capturedHttpHeaders = capturedHttpHeaders;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new {@link ApacheHttpClientTracing} configured with this {@link
|
* Returns a new {@link ApacheHttpClientTracing} configured with this {@link
|
||||||
* ApacheHttpClientTracingBuilder}.
|
* ApacheHttpClientTracingBuilder}.
|
||||||
*/
|
*/
|
||||||
public ApacheHttpClientTracing build() {
|
public ApacheHttpClientTracing build() {
|
||||||
HttpClientAttributesExtractor<ApacheHttpClientRequest, HttpResponse> httpAttributesExtractor =
|
HttpClientAttributesExtractor<ApacheHttpClientRequest, HttpResponse> httpAttributesExtractor =
|
||||||
new ApacheHttpClientHttpAttributesExtractor();
|
new ApacheHttpClientHttpAttributesExtractor(capturedHttpHeaders);
|
||||||
SpanNameExtractor<? super ApacheHttpClientRequest> spanNameExtractor =
|
SpanNameExtractor<? super ApacheHttpClientRequest> spanNameExtractor =
|
||||||
HttpSpanNameExtractor.create(httpAttributesExtractor);
|
HttpSpanNameExtractor.create(httpAttributesExtractor);
|
||||||
SpanStatusExtractor<? super ApacheHttpClientRequest, ? super HttpResponse> spanStatusExtractor =
|
SpanStatusExtractor<? super ApacheHttpClientRequest, ? super HttpResponse> spanStatusExtractor =
|
||||||
|
@ -62,6 +78,7 @@ public final class ApacheHttpClientTracingBuilder {
|
||||||
.setSpanStatusExtractor(spanStatusExtractor)
|
.setSpanStatusExtractor(spanStatusExtractor)
|
||||||
.addAttributesExtractor(httpAttributesExtractor)
|
.addAttributesExtractor(httpAttributesExtractor)
|
||||||
.addAttributesExtractor(netAttributesExtractor)
|
.addAttributesExtractor(netAttributesExtractor)
|
||||||
|
.addAttributesExtractors(additionalExtractors)
|
||||||
// We manually inject because we need to inject internal requests for redirects.
|
// We manually inject because we need to inject internal requests for redirects.
|
||||||
.newInstrumenter(SpanKindExtractor.alwaysClient());
|
.newInstrumenter(SpanKindExtractor.alwaysClient());
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
final class ArmeriaHttpClientAttributesExtractor
|
final class ArmeriaHttpClientAttributesExtractor
|
||||||
extends HttpClientAttributesExtractor<RequestContext, RequestLog> {
|
extends HttpClientAttributesExtractor<RequestContext, RequestLog> {
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
ArmeriaHttpClientAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
ArmeriaHttpClientAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,9 +20,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
final class ArmeriaHttpServerAttributesExtractor
|
final class ArmeriaHttpServerAttributesExtractor
|
||||||
extends HttpServerAttributesExtractor<RequestContext, RequestLog> {
|
extends HttpServerAttributesExtractor<RequestContext, RequestLog> {
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
ArmeriaHttpServerAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
ArmeriaHttpServerAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,10 +10,12 @@ import com.linecorp.armeria.common.RequestContext;
|
||||||
import com.linecorp.armeria.common.logging.RequestLog;
|
import com.linecorp.armeria.common.logging.RequestLog;
|
||||||
import com.linecorp.armeria.server.ServiceRequestContext;
|
import com.linecorp.armeria.server.ServiceRequestContext;
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
|
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
||||||
|
@ -29,6 +31,8 @@ public final class ArmeriaTracingBuilder {
|
||||||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3";
|
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3";
|
||||||
|
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetry openTelemetry;
|
||||||
|
private CapturedHttpHeaders capturedHttpClientHeaders = CapturedHttpHeaders.client(Config.get());
|
||||||
|
private CapturedHttpHeaders capturedHttpServerHeaders = CapturedHttpHeaders.server(Config.get());
|
||||||
|
|
||||||
private final List<AttributesExtractor<? super RequestContext, ? super RequestLog>>
|
private final List<AttributesExtractor<? super RequestContext, ? super RequestLog>>
|
||||||
additionalExtractors = new ArrayList<>();
|
additionalExtractors = new ArrayList<>();
|
||||||
|
@ -61,11 +65,37 @@ public final class ArmeriaTracingBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the HTTP client instrumentation to capture chosen HTTP request and response headers
|
||||||
|
* as span attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpClientHeaders An instance of {@link CapturedHttpHeaders} containing the
|
||||||
|
* configured HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public ArmeriaTracingBuilder captureHttpClientHeaders(
|
||||||
|
CapturedHttpHeaders capturedHttpClientHeaders) {
|
||||||
|
this.capturedHttpClientHeaders = capturedHttpClientHeaders;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the HTTP server instrumentation to capture chosen HTTP request and response headers
|
||||||
|
* as span attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpServerHeaders An instance of {@link CapturedHttpHeaders} containing the
|
||||||
|
* configured HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public ArmeriaTracingBuilder captureHttpServerHeaders(
|
||||||
|
CapturedHttpHeaders capturedHttpServerHeaders) {
|
||||||
|
this.capturedHttpServerHeaders = capturedHttpServerHeaders;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ArmeriaTracing build() {
|
public ArmeriaTracing build() {
|
||||||
ArmeriaHttpClientAttributesExtractor clientAttributesExtractor =
|
ArmeriaHttpClientAttributesExtractor clientAttributesExtractor =
|
||||||
new ArmeriaHttpClientAttributesExtractor();
|
new ArmeriaHttpClientAttributesExtractor(capturedHttpClientHeaders);
|
||||||
ArmeriaHttpServerAttributesExtractor serverAttributesExtractor =
|
ArmeriaHttpServerAttributesExtractor serverAttributesExtractor =
|
||||||
new ArmeriaHttpServerAttributesExtractor();
|
new ArmeriaHttpServerAttributesExtractor(capturedHttpServerHeaders);
|
||||||
|
|
||||||
ArmeriaNetAttributesExtractor netAttributesExtractor = new ArmeriaNetAttributesExtractor();
|
ArmeriaNetAttributesExtractor netAttributesExtractor = new ArmeriaNetAttributesExtractor();
|
||||||
|
|
||||||
|
|
|
@ -11,22 +11,27 @@ import org.eclipse.jetty.client.HttpClient;
|
||||||
/** JettyClientTracing, the Entrypoint for tracing Jetty client. */
|
/** JettyClientTracing, the Entrypoint for tracing Jetty client. */
|
||||||
public final class JettyClientTracing {
|
public final class JettyClientTracing {
|
||||||
|
|
||||||
private final HttpClient httpClient;
|
/** Returns a new {@link JettyClientTracing} configured with the given {@link OpenTelemetry}. */
|
||||||
|
|
||||||
public static JettyClientTracing create(OpenTelemetry openTelemetry) {
|
public static JettyClientTracing create(OpenTelemetry openTelemetry) {
|
||||||
JettyClientTracingBuilder builder = newBuilder(openTelemetry);
|
JettyClientTracingBuilder builder = newBuilder(openTelemetry);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link JettyClientTracingBuilder} configured with the given {@link
|
||||||
|
* OpenTelemetry}.
|
||||||
|
*/
|
||||||
public static JettyClientTracingBuilder newBuilder(OpenTelemetry openTelemetry) {
|
public static JettyClientTracingBuilder newBuilder(OpenTelemetry openTelemetry) {
|
||||||
return new JettyClientTracingBuilder(openTelemetry);
|
return new JettyClientTracingBuilder(openTelemetry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final HttpClient httpClient;
|
||||||
|
|
||||||
|
JettyClientTracing(HttpClient httpClient) {
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
public HttpClient getHttpClient() {
|
public HttpClient getHttpClient() {
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
JettyClientTracing(HttpClient httpClient) {
|
|
||||||
this.httpClient = httpClient;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,23 @@
|
||||||
package io.opentelemetry.instrumentation.jetty.httpclient.v9_2;
|
package io.opentelemetry.instrumentation.jetty.httpclient.v9_2;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal.JettyClientInstrumenterBuilder;
|
import io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal.JettyClientInstrumenterBuilder;
|
||||||
import org.eclipse.jetty.client.HttpClientTransport;
|
import org.eclipse.jetty.client.HttpClientTransport;
|
||||||
import org.eclipse.jetty.client.api.Request;
|
import org.eclipse.jetty.client.api.Request;
|
||||||
import org.eclipse.jetty.client.api.Response;
|
import org.eclipse.jetty.client.api.Response;
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
|
|
||||||
|
/** A builder of {@link JettyClientTracing}. */
|
||||||
public final class JettyClientTracingBuilder {
|
public final class JettyClientTracingBuilder {
|
||||||
|
|
||||||
private final OpenTelemetry openTelemetry;
|
private final JettyClientInstrumenterBuilder instrumenterBuilder;
|
||||||
private HttpClientTransport httpClientTransport;
|
private HttpClientTransport httpClientTransport;
|
||||||
private SslContextFactory sslContextFactory;
|
private SslContextFactory sslContextFactory;
|
||||||
|
|
||||||
public JettyClientTracingBuilder(OpenTelemetry openTelemetry) {
|
JettyClientTracingBuilder(OpenTelemetry openTelemetry) {
|
||||||
this.openTelemetry = openTelemetry;
|
instrumenterBuilder = new JettyClientInstrumenterBuilder(openTelemetry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JettyClientTracingBuilder setHttpClientTransport(HttpClientTransport httpClientTransport) {
|
public JettyClientTracingBuilder setHttpClientTransport(HttpClientTransport httpClientTransport) {
|
||||||
|
@ -33,13 +35,36 @@ public final class JettyClientTracingBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JettyClientTracing build() {
|
/**
|
||||||
JettyClientInstrumenterBuilder instrumenterBuilder =
|
* Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented
|
||||||
new JettyClientInstrumenterBuilder(this.openTelemetry);
|
* items.
|
||||||
Instrumenter<Request, Response> instrumenter = instrumenterBuilder.build();
|
*/
|
||||||
|
public JettyClientTracingBuilder addAttributeExtractor(
|
||||||
|
AttributesExtractor<? super Request, ? super Response> attributesExtractor) {
|
||||||
|
instrumenterBuilder.addAttributeExtractor(attributesExtractor);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the instrumentation to capture chosen HTTP request and response headers as span
|
||||||
|
* attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpHeaders An instance of {@link CapturedHttpHeaders} containing the configured
|
||||||
|
* HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public JettyClientTracingBuilder captureHttpHeaders(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
|
instrumenterBuilder.captureHttpHeaders(capturedHttpHeaders);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link JettyClientTracing} with the settings of this {@link
|
||||||
|
* JettyClientTracingBuilder}.
|
||||||
|
*/
|
||||||
|
public JettyClientTracing build() {
|
||||||
TracingHttpClient tracingHttpClient =
|
TracingHttpClient tracingHttpClient =
|
||||||
TracingHttpClient.buildNew(instrumenter, this.sslContextFactory, this.httpClientTransport);
|
TracingHttpClient.buildNew(
|
||||||
|
instrumenterBuilder.build(), this.sslContextFactory, this.httpClientTransport);
|
||||||
|
|
||||||
return new JettyClientTracing(tracingHttpClient);
|
return new JettyClientTracing(tracingHttpClient);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,12 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
final class JettyClientHttpAttributesExtractor
|
final class JettyClientHttpAttributesExtractor
|
||||||
extends HttpClientAttributesExtractor<Request, Response> {
|
extends HttpClientAttributesExtractor<Request, Response> {
|
||||||
|
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(JettyClientHttpAttributesExtractor.class);
|
LoggerFactory.getLogger(JettyClientHttpAttributesExtractor.class);
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
JettyClientHttpAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
JettyClientHttpAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
package io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal;
|
package io.opentelemetry.instrumentation.jetty.httpclient.v9_2.internal;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
||||||
|
@ -27,6 +29,11 @@ public final class JettyClientInstrumenterBuilder {
|
||||||
|
|
||||||
private final List<AttributesExtractor<? super Request, ? super Response>> additionalExtractors =
|
private final List<AttributesExtractor<? super Request, ? super Response>> additionalExtractors =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
|
private CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.client(Config.get());
|
||||||
|
|
||||||
|
public JettyClientInstrumenterBuilder(OpenTelemetry openTelemetry) {
|
||||||
|
this.openTelemetry = openTelemetry;
|
||||||
|
}
|
||||||
|
|
||||||
public JettyClientInstrumenterBuilder addAttributeExtractor(
|
public JettyClientInstrumenterBuilder addAttributeExtractor(
|
||||||
AttributesExtractor<? super Request, ? super Response> attributesExtractor) {
|
AttributesExtractor<? super Request, ? super Response> attributesExtractor) {
|
||||||
|
@ -34,13 +41,15 @@ public final class JettyClientInstrumenterBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JettyClientInstrumenterBuilder(OpenTelemetry openTelemetry) {
|
public JettyClientInstrumenterBuilder captureHttpHeaders(
|
||||||
this.openTelemetry = openTelemetry;
|
CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
|
this.capturedHttpHeaders = capturedHttpHeaders;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Instrumenter<Request, Response> build() {
|
public Instrumenter<Request, Response> build() {
|
||||||
HttpClientAttributesExtractor<Request, Response> httpAttributesExtractor =
|
HttpClientAttributesExtractor<Request, Response> httpAttributesExtractor =
|
||||||
new JettyClientHttpAttributesExtractor();
|
new JettyClientHttpAttributesExtractor(capturedHttpHeaders);
|
||||||
SpanNameExtractor<Request> spanNameExtractor =
|
SpanNameExtractor<Request> spanNameExtractor =
|
||||||
HttpSpanNameExtractor.create(httpAttributesExtractor);
|
HttpSpanNameExtractor.create(httpAttributesExtractor);
|
||||||
SpanStatusExtractor<Request, Response> spanStatusExtractor =
|
SpanStatusExtractor<Request, Response> spanStatusExtractor =
|
||||||
|
|
|
@ -14,14 +14,12 @@ class JettyHttpClient9LibraryTest extends AbstractJettyClient9Test implements Li
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
HttpClient createStandardClient() {
|
HttpClient createStandardClient() {
|
||||||
JettyClientTracingBuilder jettyClientTracingBuilder = new JettyClientTracingBuilder(getOpenTelemetry())
|
return JettyClientTracing.create(getOpenTelemetry()).getHttpClient()
|
||||||
return jettyClientTracingBuilder.build().getHttpClient()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
HttpClient createHttpsClient(SslContextFactory sslContextFactory) {
|
HttpClient createHttpsClient(SslContextFactory sslContextFactory) {
|
||||||
JettyClientTracingBuilder jettyClientTracingBuilder = new JettyClientTracingBuilder(getOpenTelemetry())
|
return JettyClientTracing.newBuilder(getOpenTelemetry())
|
||||||
return jettyClientTracingBuilder
|
|
||||||
.setSslContextFactory(sslContextFactory)
|
.setSslContextFactory(sslContextFactory)
|
||||||
.build()
|
.build()
|
||||||
.getHttpClient()
|
.getHttpClient()
|
||||||
|
|
|
@ -15,9 +15,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
final class OkHttpAttributesExtractor extends HttpClientAttributesExtractor<Request, Response> {
|
final class OkHttpAttributesExtractor extends HttpClientAttributesExtractor<Request, Response> {
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
OkHttpAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
OkHttpAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,8 +8,10 @@ package io.opentelemetry.instrumentation.okhttp.v3_0;
|
||||||
import static io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor.alwaysClient;
|
import static io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor.alwaysClient;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
||||||
|
@ -26,6 +28,7 @@ public final class OkHttpTracingBuilder {
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetry openTelemetry;
|
||||||
private final List<AttributesExtractor<Request, Response>> additionalExtractors =
|
private final List<AttributesExtractor<Request, Response>> additionalExtractors =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
|
private CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.client(Config.get());
|
||||||
|
|
||||||
OkHttpTracingBuilder(OpenTelemetry openTelemetry) {
|
OkHttpTracingBuilder(OpenTelemetry openTelemetry) {
|
||||||
this.openTelemetry = openTelemetry;
|
this.openTelemetry = openTelemetry;
|
||||||
|
@ -41,9 +44,22 @@ public final class OkHttpTracingBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the instrumentation to capture chosen HTTP request and response headers as span
|
||||||
|
* attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpHeaders An instance of {@link CapturedHttpHeaders} containing the configured
|
||||||
|
* HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public OkHttpTracingBuilder captureHttpHeaders(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
|
this.capturedHttpHeaders = capturedHttpHeaders;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns a new {@link OkHttpTracing} with the settings of this {@link OkHttpTracingBuilder}. */
|
/** Returns a new {@link OkHttpTracing} with the settings of this {@link OkHttpTracingBuilder}. */
|
||||||
public OkHttpTracing build() {
|
public OkHttpTracing build() {
|
||||||
OkHttpAttributesExtractor httpAttributesExtractor = new OkHttpAttributesExtractor();
|
OkHttpAttributesExtractor httpAttributesExtractor =
|
||||||
|
new OkHttpAttributesExtractor(capturedHttpHeaders);
|
||||||
OkHttpNetAttributesExtractor netAttributesExtractor = new OkHttpNetAttributesExtractor();
|
OkHttpNetAttributesExtractor netAttributesExtractor = new OkHttpNetAttributesExtractor();
|
||||||
|
|
||||||
Instrumenter<Request, Response> instrumenter =
|
Instrumenter<Request, Response> instrumenter =
|
||||||
|
|
|
@ -18,9 +18,8 @@ import ratpack.server.PublicAddress;
|
||||||
final class RatpackHttpAttributesExtractor
|
final class RatpackHttpAttributesExtractor
|
||||||
extends HttpServerAttributesExtractor<Request, Response> {
|
extends HttpServerAttributesExtractor<Request, Response> {
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
RatpackHttpAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
RatpackHttpAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
package io.opentelemetry.instrumentation.ratpack;
|
package io.opentelemetry.instrumentation.ratpack;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
|
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
||||||
import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetAttributesExtractor;
|
import io.opentelemetry.instrumentation.ratpack.internal.RatpackNetAttributesExtractor;
|
||||||
|
@ -26,6 +28,7 @@ public final class RatpackTracingBuilder {
|
||||||
|
|
||||||
private final List<AttributesExtractor<? super Request, ? super Response>> additionalExtractors =
|
private final List<AttributesExtractor<? super Request, ? super Response>> additionalExtractors =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
|
private CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.server(Config.get());
|
||||||
|
|
||||||
RatpackTracingBuilder(OpenTelemetry openTelemetry) {
|
RatpackTracingBuilder(OpenTelemetry openTelemetry) {
|
||||||
this.openTelemetry = openTelemetry;
|
this.openTelemetry = openTelemetry;
|
||||||
|
@ -41,10 +44,23 @@ public final class RatpackTracingBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the instrumentation to capture chosen HTTP request and response headers as span
|
||||||
|
* attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpHeaders An instance of {@link CapturedHttpHeaders} containing the configured
|
||||||
|
* HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public RatpackTracingBuilder captureHttpHeaders(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
|
this.capturedHttpHeaders = capturedHttpHeaders;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns a new {@link RatpackTracing} with the configuration of this builder. */
|
/** Returns a new {@link RatpackTracing} with the configuration of this builder. */
|
||||||
public RatpackTracing build() {
|
public RatpackTracing build() {
|
||||||
RatpackNetAttributesExtractor netAttributes = new RatpackNetAttributesExtractor();
|
RatpackNetAttributesExtractor netAttributes = new RatpackNetAttributesExtractor();
|
||||||
RatpackHttpAttributesExtractor httpAttributes = new RatpackHttpAttributesExtractor();
|
RatpackHttpAttributesExtractor httpAttributes =
|
||||||
|
new RatpackHttpAttributesExtractor(capturedHttpHeaders);
|
||||||
|
|
||||||
InstrumenterBuilder<Request, Response> builder =
|
InstrumenterBuilder<Request, Response> builder =
|
||||||
Instrumenter.newBuilder(
|
Instrumenter.newBuilder(
|
||||||
|
|
|
@ -23,9 +23,8 @@ import org.restlet.util.Series;
|
||||||
final class RestletHttpAttributesExtractor
|
final class RestletHttpAttributesExtractor
|
||||||
extends HttpServerAttributesExtractor<Request, Response> {
|
extends HttpServerAttributesExtractor<Request, Response> {
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
RestletHttpAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
RestletHttpAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
package io.opentelemetry.instrumentation.restlet.v1_0;
|
package io.opentelemetry.instrumentation.restlet.v1_0;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor;
|
||||||
|
@ -26,6 +28,7 @@ public final class RestletTracingBuilder {
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetry openTelemetry;
|
||||||
private final List<AttributesExtractor<Request, Response>> additionalExtractors =
|
private final List<AttributesExtractor<Request, Response>> additionalExtractors =
|
||||||
new ArrayList<>();
|
new ArrayList<>();
|
||||||
|
private CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.server(Config.get());
|
||||||
|
|
||||||
RestletTracingBuilder(OpenTelemetry openTelemetry) {
|
RestletTracingBuilder(OpenTelemetry openTelemetry) {
|
||||||
this.openTelemetry = openTelemetry;
|
this.openTelemetry = openTelemetry;
|
||||||
|
@ -41,11 +44,24 @@ public final class RestletTracingBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the instrumentation to capture chosen HTTP request and response headers as span
|
||||||
|
* attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpHeaders An instance of {@link CapturedHttpHeaders} containing the configured
|
||||||
|
* HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public RestletTracingBuilder captureHttpHeaders(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
|
this.capturedHttpHeaders = capturedHttpHeaders;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new {@link RestletTracing} with the settings of this {@link RestletTracingBuilder}.
|
* Returns a new {@link RestletTracing} with the settings of this {@link RestletTracingBuilder}.
|
||||||
*/
|
*/
|
||||||
public RestletTracing build() {
|
public RestletTracing build() {
|
||||||
RestletHttpAttributesExtractor httpAttributesExtractor = new RestletHttpAttributesExtractor();
|
RestletHttpAttributesExtractor httpAttributesExtractor =
|
||||||
|
new RestletHttpAttributesExtractor(capturedHttpHeaders);
|
||||||
SpanNameExtractor<Request> spanNameExtractor =
|
SpanNameExtractor<Request> spanNameExtractor =
|
||||||
HttpSpanNameExtractor.create(httpAttributesExtractor);
|
HttpSpanNameExtractor.create(httpAttributesExtractor);
|
||||||
SpanStatusExtractor<Request, Response> spanStatusExtractor =
|
SpanStatusExtractor<Request, Response> spanStatusExtractor =
|
||||||
|
|
|
@ -19,9 +19,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
final class SpringWebMvcHttpAttributesExtractor
|
final class SpringWebMvcHttpAttributesExtractor
|
||||||
extends HttpServerAttributesExtractor<HttpServletRequest, HttpServletResponse> {
|
extends HttpServerAttributesExtractor<HttpServletRequest, HttpServletResponse> {
|
||||||
|
|
||||||
// TODO: add support for capturing HTTP headers in library instrumentations
|
SpringWebMvcHttpAttributesExtractor(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
SpringWebMvcHttpAttributesExtractor() {
|
super(capturedHttpHeaders);
|
||||||
super(CapturedHttpHeaders.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
package io.opentelemetry.instrumentation.spring.webmvc;
|
package io.opentelemetry.instrumentation.spring.webmvc;
|
||||||
|
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
|
import io.opentelemetry.instrumentation.api.config.Config;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
|
||||||
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
|
||||||
|
@ -25,6 +27,7 @@ public final class SpringWebMvcTracingBuilder {
|
||||||
private final OpenTelemetry openTelemetry;
|
private final OpenTelemetry openTelemetry;
|
||||||
private final List<AttributesExtractor<HttpServletRequest, HttpServletResponse>>
|
private final List<AttributesExtractor<HttpServletRequest, HttpServletResponse>>
|
||||||
additionalExtractors = new ArrayList<>();
|
additionalExtractors = new ArrayList<>();
|
||||||
|
private CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.server(Config.get());
|
||||||
|
|
||||||
SpringWebMvcTracingBuilder(OpenTelemetry openTelemetry) {
|
SpringWebMvcTracingBuilder(OpenTelemetry openTelemetry) {
|
||||||
this.openTelemetry = openTelemetry;
|
this.openTelemetry = openTelemetry;
|
||||||
|
@ -40,13 +43,25 @@ public final class SpringWebMvcTracingBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the instrumentation to capture chosen HTTP request and response headers as span
|
||||||
|
* attributes.
|
||||||
|
*
|
||||||
|
* @param capturedHttpHeaders An instance of {@link CapturedHttpHeaders} containing the configured
|
||||||
|
* HTTP request and response names.
|
||||||
|
*/
|
||||||
|
public SpringWebMvcTracingBuilder captureHttpHeaders(CapturedHttpHeaders capturedHttpHeaders) {
|
||||||
|
this.capturedHttpHeaders = capturedHttpHeaders;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new {@link SpringWebMvcTracing} with the settings of this {@link
|
* Returns a new {@link SpringWebMvcTracing} with the settings of this {@link
|
||||||
* SpringWebMvcTracingBuilder}.
|
* SpringWebMvcTracingBuilder}.
|
||||||
*/
|
*/
|
||||||
public SpringWebMvcTracing build() {
|
public SpringWebMvcTracing build() {
|
||||||
SpringWebMvcHttpAttributesExtractor httpAttributesExtractor =
|
SpringWebMvcHttpAttributesExtractor httpAttributesExtractor =
|
||||||
new SpringWebMvcHttpAttributesExtractor();
|
new SpringWebMvcHttpAttributesExtractor(capturedHttpHeaders);
|
||||||
|
|
||||||
Instrumenter<HttpServletRequest, HttpServletResponse> instrumenter =
|
Instrumenter<HttpServletRequest, HttpServletResponse> instrumenter =
|
||||||
Instrumenter.<HttpServletRequest, HttpServletResponse>newBuilder(
|
Instrumenter.<HttpServletRequest, HttpServletResponse>newBuilder(
|
||||||
|
|
Loading…
Reference in New Issue