Skip to content

Commit

Permalink
Simplify signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 24, 2024
1 parent e5a9d1c commit a34694a
Show file tree
Hide file tree
Showing 30 changed files with 69 additions and 113 deletions.
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 @@ -56,8 +56,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 @@ -126,8 +125,8 @@ 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;
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 @@ -41,8 +41,7 @@ public final class ApacheHttpClientTelemetryBuilder {
*/
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>
attributesExtractor) {
AttributesExtractor<ApacheHttpClientRequest, HttpResponse> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}
Expand Down Expand Up @@ -94,8 +93,8 @@ public ApacheHttpClientTelemetryBuilder setKnownMethods(Collection<String> known
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super ApacheHttpClientRequest>,
? extends SpanNameExtractor<? super ApacheHttpClientRequest>>
SpanNameExtractor<ApacheHttpClientRequest>,
SpanNameExtractor<ApacheHttpClientRequest>>
spanNameExtractorTransformer) {
builder.setSpanNameExtractor(spanNameExtractorTransformer);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,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 @@ -53,7 +53,7 @@ public ArmeriaClientTelemetryBuilder setStatusExtractor(
*/
@CanIgnoreReturnValue
public ArmeriaClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super ClientRequestContext, ? super RequestLog> attributesExtractor) {
AttributesExtractor<ClientRequestContext, RequestLog> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}
Expand Down Expand Up @@ -104,9 +104,7 @@ public ArmeriaClientTelemetryBuilder setKnownMethods(Collection<String> knownMet
/** 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 @@ -38,8 +38,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 @@ -51,7 +51,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 @@ -102,9 +102,7 @@ public ArmeriaServerTelemetryBuilder setKnownMethods(Collection<String> knownMet
/** 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 @@ -70,8 +70,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 @@ -86,8 +86,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 @@ -275,9 +275,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 @@ -291,9 +289,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 @@ -54,7 +54,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 @@ -122,9 +122,7 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 @@ -135,7 +135,7 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 @@ -135,7 +135,7 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class KtorServerTelemetry private constructor(
}

fun setStatusExtractor(
extractor: (SpanStatusExtractor<in ApplicationRequest, in ApplicationResponse>) -> SpanStatusExtractor<in ApplicationRequest, in ApplicationResponse>
extractor: (SpanStatusExtractor<ApplicationRequest, ApplicationResponse>) -> SpanStatusExtractor<ApplicationRequest, ApplicationResponse>
) {
builder.setStatusExtractor { prevExtractor ->
SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder,
Expand All @@ -61,7 +61,7 @@ class KtorServerTelemetry private constructor(
this.spanKindExtractor = extractor
}

fun addAttributesExtractor(extractor: AttributesExtractor<in ApplicationRequest, in ApplicationResponse>) {
fun addAttributesExtractor(extractor: AttributesExtractor<ApplicationRequest, ApplicationResponse>) {
builder.addAttributesExtractor(extractor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class KtorServerTracing private constructor(
}

fun setStatusExtractor(
extractor: (SpanStatusExtractor<in ApplicationRequest, in ApplicationResponse>) -> SpanStatusExtractor<in ApplicationRequest, in ApplicationResponse>
extractor: (SpanStatusExtractor<ApplicationRequest, ApplicationResponse>) -> SpanStatusExtractor<ApplicationRequest, in ApplicationResponse>
) {
builder.setStatusExtractor { prevExtractor ->
SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder,
Expand All @@ -62,7 +62,7 @@ class KtorServerTracing private constructor(
this.spanKindExtractor = extractor
}

fun addAttributeExtractor(extractor: AttributesExtractor<in ApplicationRequest, in ApplicationResponse>) {
fun addAttributeExtractor(extractor: AttributesExtractor<ApplicationRequest, ApplicationResponse>) {
builder.addAttributesExtractor(extractor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ abstract class AbstractKtorClientTelemetryBuilder(
})
}

fun spanNameExtractor(spanNameExtractorTransformer: Function<SpanNameExtractor<in HttpRequestData>, out SpanNameExtractor<in HttpRequestData>>) {
fun spanNameExtractor(spanNameExtractorTransformer: Function<SpanNameExtractor<HttpRequestData>, SpanNameExtractor<HttpRequestData>>) {
builder.setSpanNameExtractor(spanNameExtractorTransformer)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam
)
}

fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor<in ApplicationRequest, in ApplicationResponse>) -> Unit) {
fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor<ApplicationRequest, ApplicationResponse>) -> Unit) {
builder.setStatusExtractor { prevExtractor ->
SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder,
request: ApplicationRequest,
Expand Down Expand Up @@ -86,7 +86,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam
)
}

fun spanNameExtractor(spanNameExtractorTransformer: Function<SpanNameExtractor<in ApplicationRequest>, out SpanNameExtractor<in ApplicationRequest>>) {
fun spanNameExtractor(spanNameExtractorTransformer: Function<SpanNameExtractor<ApplicationRequest>, SpanNameExtractor<ApplicationRequest>>) {
builder.setSpanNameExtractor(spanNameExtractorTransformer)
}

Expand Down
Loading

0 comments on commit a34694a

Please # to comment.