Skip to content

Commit

Permalink
Simplify signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 10, 2024
1 parent b996ef4 commit 54cd5fb
Show file tree
Hide file tree
Showing 27 changed files with 243 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Comparing source compatibility of opentelemetry-instrumentation-api-2.11.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.10.0.jar
No changes.
Comparing source compatibility of opentelemetry-instrumentation-annotations-2.11.0-SNAPSHOT.jar against opentelemetry-instrumentation-annotations-2.10.0.jar
No changes.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ public final class DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> {

private final List<AttributesExtractor<? super REQUEST, ? super RESPONSE>> additionalExtractors =
new ArrayList<>();
private Function<
SpanStatusExtractor<? super REQUEST, ? super RESPONSE>,
? extends SpanStatusExtractor<? super REQUEST, ? super RESPONSE>>
private Function<SpanStatusExtractor<REQUEST, RESPONSE>, SpanStatusExtractor<REQUEST, RESPONSE>>
statusExtractorTransformer = Function.identity();
private final HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE>
httpAttributesExtractorBuilder;
private final HttpClientAttributesGetter<REQUEST, RESPONSE> attributesGetter;
private final HttpSpanNameExtractorBuilder<REQUEST> httpSpanNameExtractorBuilder;

@Nullable private final TextMapSetter<REQUEST> headerSetter;
private Function<SpanNameExtractor<? super REQUEST>, ? extends SpanNameExtractor<? super REQUEST>>
private Function<SpanNameExtractor<REQUEST>, ? extends SpanNameExtractor<REQUEST>>
spanNameExtractorTransformer = Function.identity();
private boolean emitExperimentalHttpClientMetrics = false;
private Consumer<InstrumenterBuilder<REQUEST, RESPONSE>> builderCustomizer = b -> {};
Expand Down Expand Up @@ -111,9 +109,7 @@ public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtr

@CanIgnoreReturnValue
public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> setStatusExtractor(
Function<
SpanStatusExtractor<? super REQUEST, ? super RESPONSE>,
? extends SpanStatusExtractor<? super REQUEST, ? super RESPONSE>>
Function<SpanStatusExtractor<REQUEST, RESPONSE>, SpanStatusExtractor<REQUEST, RESPONSE>>
statusExtractor) {
this.statusExtractorTransformer = statusExtractor;
return this;
Expand Down Expand Up @@ -180,7 +176,7 @@ public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> setKnownMethods(
/** Sets custom {@link SpanNameExtractor} via transform function. */
@CanIgnoreReturnValue
public DefaultHttpClientInstrumenterBuilder<REQUEST, RESPONSE> setSpanNameExtractor(
Function<SpanNameExtractor<? super REQUEST>, ? extends SpanNameExtractor<? super REQUEST>>
Function<SpanNameExtractor<REQUEST>, SpanNameExtractor<REQUEST>>
spanNameExtractorTransformer) {
this.spanNameExtractorTransformer = spanNameExtractorTransformer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ public final class DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> {

private final List<AttributesExtractor<? super REQUEST, ? super RESPONSE>> additionalExtractors =
new ArrayList<>();
private Function<
SpanStatusExtractor<? super REQUEST, ? super RESPONSE>,
? extends SpanStatusExtractor<? super REQUEST, ? super RESPONSE>>
private Function<SpanStatusExtractor<REQUEST, RESPONSE>, SpanStatusExtractor<REQUEST, RESPONSE>>
statusExtractorTransformer = Function.identity();
private final HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE>
httpAttributesExtractorBuilder;
private final HttpSpanNameExtractorBuilder<REQUEST> httpSpanNameExtractorBuilder;

@Nullable private final TextMapGetter<REQUEST> headerGetter;
private Function<SpanNameExtractor<? super REQUEST>, ? extends SpanNameExtractor<? super REQUEST>>
private Function<SpanNameExtractor<REQUEST>, SpanNameExtractor<REQUEST>>
spanNameExtractorTransformer = Function.identity();
private final HttpServerRouteBuilder<REQUEST> httpServerRouteBuilder;
private final HttpServerAttributesGetter<REQUEST, RESPONSE> attributesGetter;
Expand Down Expand Up @@ -109,9 +107,7 @@ public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtr

@CanIgnoreReturnValue
public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> setStatusExtractor(
Function<
SpanStatusExtractor<? super REQUEST, ? super RESPONSE>,
? extends SpanStatusExtractor<? super REQUEST, ? super RESPONSE>>
Function<SpanStatusExtractor<REQUEST, RESPONSE>, SpanStatusExtractor<REQUEST, RESPONSE>>
statusExtractor) {
this.statusExtractorTransformer = statusExtractor;
return this;
Expand Down Expand Up @@ -179,7 +175,7 @@ public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> setKnownMethods(
/** Sets custom {@link SpanNameExtractor} via transform function. */
@CanIgnoreReturnValue
public DefaultHttpServerInstrumenterBuilder<REQUEST, RESPONSE> setSpanNameExtractor(
Function<SpanNameExtractor<? super REQUEST>, ? extends SpanNameExtractor<? super REQUEST>>
Function<SpanNameExtractor<REQUEST>, SpanNameExtractor<REQUEST>>
spanNameExtractorTransformer) {
this.spanNameExtractorTransformer = spanNameExtractorTransformer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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 java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -52,8 +53,7 @@ public ApacheHttpClientTelemetryBuilder addAttributeExtractor(
*/
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>
attributesExtractor) {
AttributesExtractor<ApacheHttpClientRequest, HttpResponse> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}
Expand Down Expand Up @@ -120,13 +120,22 @@ public ApacheHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics(
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super ApacheHttpClientRequest>,
? extends SpanNameExtractor<? super ApacheHttpClientRequest>>
SpanNameExtractor<ApacheHttpClientRequest>,
SpanNameExtractor<ApacheHttpClientRequest>>
spanNameExtractorTransformer) {
builder.setSpanNameExtractor(spanNameExtractorTransformer);
return this;
}

public ApacheHttpClientTelemetryBuilder setStatusExtractor(
Function<
SpanStatusExtractor<ApacheHttpClientRequest, HttpResponse>,
SpanStatusExtractor<ApacheHttpClientRequest, HttpResponse>>
statusExtractorTransformer) {
builder.setStatusExtractor(statusExtractorTransformer);
return this;
}

/**
* Returns a new {@link ApacheHttpClientTelemetry} configured with this {@link
* ApacheHttpClientTelemetryBuilder}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public ApacheHttpClient5TelemetryBuilder setEmitExperimentalHttpClientMetrics(
@CanIgnoreReturnValue
public ApacheHttpClient5TelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super ApacheHttpClient5Request>,
? extends SpanNameExtractor<? super ApacheHttpClient5Request>>
SpanNameExtractor<ApacheHttpClient5Request>,
SpanNameExtractor<ApacheHttpClient5Request>>
spanNameExtractorTransformer) {
builder.setSpanNameExtractor(spanNameExtractorTransformer);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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 java.util.List;
import java.util.Set;
Expand All @@ -36,10 +37,9 @@ public final class ApacheHttpClientTelemetryBuilder {
* items. The {@link AttributesExtractor} will be executed after all default extractors.
*/
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder addAttributeExtractor(
AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>
attributesExtractor) {
builder.addAttributeExtractor(attributesExtractor);
public ApacheHttpClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<ApacheHttpClientRequest, HttpResponse> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}

Expand Down Expand Up @@ -88,13 +88,22 @@ public ApacheHttpClientTelemetryBuilder setKnownMethods(Set<String> knownMethods
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super ApacheHttpClientRequest>,
? extends SpanNameExtractor<? super ApacheHttpClientRequest>>
SpanNameExtractor<ApacheHttpClientRequest>,
SpanNameExtractor<ApacheHttpClientRequest>>
spanNameExtractorTransformer) {
builder.setSpanNameExtractor(spanNameExtractorTransformer);
return this;
}

public ApacheHttpClientTelemetryBuilder setStatusExtractor(
Function<
SpanStatusExtractor<ApacheHttpClientRequest, HttpResponse>,
SpanStatusExtractor<ApacheHttpClientRequest, HttpResponse>>
spanNameExtractorTransformer) {
builder.setStatusExtractor(spanNameExtractorTransformer);
return this;
}

/**
* Can be used via the unstable method {@link
* Experimental#setEmitExperimentalTelemetry(ApacheHttpClientTelemetryBuilder, boolean)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public final class ArmeriaClientTelemetryBuilder {
@CanIgnoreReturnValue
public ArmeriaClientTelemetryBuilder setStatusExtractor(
Function<
SpanStatusExtractor<? super ClientRequestContext, ? super RequestLog>,
? extends SpanStatusExtractor<? super ClientRequestContext, ? super RequestLog>>
SpanStatusExtractor<ClientRequestContext, RequestLog>,
SpanStatusExtractor<ClientRequestContext, RequestLog>>
statusExtractor) {
builder.setStatusExtractor(statusExtractor);
return this;
Expand All @@ -50,8 +50,8 @@ public ArmeriaClientTelemetryBuilder setStatusExtractor(
*/
@CanIgnoreReturnValue
public ArmeriaClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super ClientRequestContext, ? super RequestLog> attributesExtractor) {
builder.addAttributeExtractor(attributesExtractor);
AttributesExtractor<ClientRequestContext, RequestLog> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}

Expand Down Expand Up @@ -99,9 +99,7 @@ public ArmeriaClientTelemetryBuilder setKnownMethods(Set<String> knownMethods) {
/** Sets custom client {@link SpanNameExtractor} via transform function. */
@CanIgnoreReturnValue
public ArmeriaClientTelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super ClientRequestContext>,
? extends SpanNameExtractor<? super ClientRequestContext>>
Function<SpanNameExtractor<ClientRequestContext>, SpanNameExtractor<ClientRequestContext>>
clientSpanNameExtractor) {
builder.setSpanNameExtractor(clientSpanNameExtractor);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public final class ArmeriaServerTelemetryBuilder {
@CanIgnoreReturnValue
public ArmeriaServerTelemetryBuilder setStatusExtractor(
Function<
SpanStatusExtractor<? super ServiceRequestContext, ? super RequestLog>,
? extends SpanStatusExtractor<? super ServiceRequestContext, ? super RequestLog>>
SpanStatusExtractor<ServiceRequestContext, RequestLog>,
SpanStatusExtractor<ServiceRequestContext, RequestLog>>
statusExtractor) {
builder.setStatusExtractor(statusExtractor);
return this;
Expand All @@ -50,7 +50,7 @@ public ArmeriaServerTelemetryBuilder setStatusExtractor(
*/
@CanIgnoreReturnValue
public ArmeriaServerTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super ServiceRequestContext, ? super RequestLog> attributesExtractor) {
AttributesExtractor<ServiceRequestContext, RequestLog> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}
Expand Down Expand Up @@ -99,9 +99,7 @@ public ArmeriaServerTelemetryBuilder setKnownMethods(Set<String> knownMethods) {
/** Sets custom server {@link SpanNameExtractor} via transform function. */
@CanIgnoreReturnValue
public ArmeriaServerTelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super ServiceRequestContext>,
? extends SpanNameExtractor<? super ServiceRequestContext>>
Function<SpanNameExtractor<ServiceRequestContext>, SpanNameExtractor<ServiceRequestContext>>
serverSpanNameExtractor) {
builder.setSpanNameExtractor(serverSpanNameExtractor);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public ArmeriaTelemetryBuilder setStatusExtractor(
@CanIgnoreReturnValue
public ArmeriaTelemetryBuilder setClientStatusExtractor(
Function<
SpanStatusExtractor<? super ClientRequestContext, ? super RequestLog>,
? extends SpanStatusExtractor<? super ClientRequestContext, ? super RequestLog>>
SpanStatusExtractor<ClientRequestContext, RequestLog>,
SpanStatusExtractor<ClientRequestContext, RequestLog>>
statusExtractor) {
clientBuilder.setStatusExtractor(statusExtractor);
return this;
Expand All @@ -85,8 +85,8 @@ public ArmeriaTelemetryBuilder setClientStatusExtractor(
@CanIgnoreReturnValue
public ArmeriaTelemetryBuilder setServerStatusExtractor(
Function<
SpanStatusExtractor<? super ServiceRequestContext, ? super RequestLog>,
? extends SpanStatusExtractor<? super ServiceRequestContext, ? super RequestLog>>
SpanStatusExtractor<ServiceRequestContext, RequestLog>,
SpanStatusExtractor<ServiceRequestContext, RequestLog>>
statusExtractor) {
serverBuilder.setStatusExtractor(statusExtractor);
return this;
Expand Down Expand Up @@ -270,9 +270,7 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpServerMetrics(
@Deprecated
@CanIgnoreReturnValue
public ArmeriaTelemetryBuilder setClientSpanNameExtractor(
Function<
SpanNameExtractor<? super ClientRequestContext>,
? extends SpanNameExtractor<? super ClientRequestContext>>
Function<SpanNameExtractor<ClientRequestContext>, SpanNameExtractor<ClientRequestContext>>
clientSpanNameExtractor) {
clientBuilder.setSpanNameExtractor(clientSpanNameExtractor);
return this;
Expand All @@ -286,9 +284,7 @@ public ArmeriaTelemetryBuilder setClientSpanNameExtractor(
@Deprecated
@CanIgnoreReturnValue
public ArmeriaTelemetryBuilder setServerSpanNameExtractor(
Function<
SpanNameExtractor<? super ServiceRequestContext>,
? extends SpanNameExtractor<? super ServiceRequestContext>>
Function<SpanNameExtractor<ServiceRequestContext>, SpanNameExtractor<ServiceRequestContext>>
serverSpanNameExtractor) {
serverBuilder.setSpanNameExtractor(serverSpanNameExtractor);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.httpclient.internal.Experimental;
import io.opentelemetry.instrumentation.httpclient.internal.HttpHeadersSetter;
Expand Down Expand Up @@ -50,7 +51,7 @@ public JavaHttpClientTelemetryBuilder addAttributeExtractor(
*/
@CanIgnoreReturnValue
public JavaHttpClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super HttpRequest, ? super HttpResponse<?>> attributesExtractor) {
AttributesExtractor<HttpRequest, HttpResponse<?>> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}
Expand Down Expand Up @@ -116,14 +117,21 @@ public JavaHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics(
/** Sets custom {@link SpanNameExtractor} via transform function. */
@CanIgnoreReturnValue
public JavaHttpClientTelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super HttpRequest>,
? extends SpanNameExtractor<? super HttpRequest>>
Function<SpanNameExtractor<HttpRequest>, SpanNameExtractor<HttpRequest>>
spanNameExtractorTransformer) {
builder.setSpanNameExtractor(spanNameExtractorTransformer);
return this;
}

public JavaHttpClientTelemetryBuilder setStatusExtractor(
Function<
SpanStatusExtractor<HttpRequest, HttpResponse<?>>,
SpanStatusExtractor<HttpRequest, HttpResponse<?>>>
statusExtractorTransformer) {
builder.setStatusExtractor(statusExtractorTransformer);
return this;
}

public JavaHttpClientTelemetry build() {
return new JavaHttpClientTelemetry(
builder.build(), new HttpHeadersSetter(openTelemetry.getPropagators()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.jetty.httpclient.v12_0.internal.Experimental;
import io.opentelemetry.instrumentation.jetty.httpclient.v12_0.internal.JettyHttpClientInstrumenterBuilderFactory;
Expand Down Expand Up @@ -65,7 +66,7 @@ public JettyClientTelemetryBuilder addAttributeExtractor(
*/
@CanIgnoreReturnValue
public JettyClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super Request, ? super Response> attributesExtractor) {
AttributesExtractor<Request, Response> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}
Expand Down Expand Up @@ -130,12 +131,19 @@ public JettyClientTelemetryBuilder setEmitExperimentalHttpClientMetrics(
/** Sets custom {@link SpanNameExtractor} via transform function. */
@CanIgnoreReturnValue
public JettyClientTelemetryBuilder setSpanNameExtractor(
Function<SpanNameExtractor<? super Request>, ? extends SpanNameExtractor<? super Request>>
Function<SpanNameExtractor<Request>, SpanNameExtractor<Request>>
spanNameExtractorTransformer) {
builder.setSpanNameExtractor(spanNameExtractorTransformer);
return this;
}

public JettyClientTelemetryBuilder setStatusExtractor(
Function<SpanStatusExtractor<Request, Response>, SpanStatusExtractor<Request, Response>>
statusExtractorTransformer) {
builder.setStatusExtractor(statusExtractorTransformer);
return this;
}

/**
* Returns a new {@link JettyClientTelemetry} with the settings of this {@link
* JettyClientTelemetryBuilder}.
Expand Down
Loading

0 comments on commit 54cd5fb

Please # to comment.