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