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 96f4e96
Show file tree
Hide file tree
Showing 29 changed files with 541 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
Comparing source compatibility of opentelemetry-instrumentation-api-2.11.0-SNAPSHOT.jar against opentelemetry-instrumentation-api-2.10.0.jar
No changes.
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpClientTelemetryBuilder (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
GENERIC TEMPLATES: +++ REQUEST:java.lang.Object, +++ RESPONSE:java.lang.Object
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpClientTelemetryBuilder<REQUEST,RESPONSE> addAttributesExtractor(io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor<REQUEST,RESPONSE>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Object build()
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpClientTelemetryBuilder<REQUEST,RESPONSE> setCapturedRequestHeaders(java.util.List<java.lang.String>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpClientTelemetryBuilder<REQUEST,RESPONSE> setCapturedResponseHeaders(java.util.List<java.lang.String>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpClientTelemetryBuilder<REQUEST,RESPONSE> setKnownMethods(java.util.Set<java.lang.String>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpClientTelemetryBuilder<REQUEST,RESPONSE> setSpanNameExtractor(java.util.function.Function<io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor<REQUEST>,io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor<REQUEST>>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpClientTelemetryBuilder<REQUEST,RESPONSE> setStatusExtractor(java.util.function.Function<io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor<REQUEST,RESPONSE>,io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor<REQUEST,RESPONSE>>)
+++ NEW INTERFACE: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpServerTelemetryBuilder (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
GENERIC TEMPLATES: +++ REQUEST:java.lang.Object, +++ RESPONSE:java.lang.Object
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpServerTelemetryBuilder<REQUEST,RESPONSE> addAttributesExtractor(io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor<REQUEST,RESPONSE>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) java.lang.Object build()
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpServerTelemetryBuilder<REQUEST,RESPONSE> setCapturedRequestHeaders(java.util.List<java.lang.String>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpServerTelemetryBuilder<REQUEST,RESPONSE> setCapturedResponseHeaders(java.util.List<java.lang.String>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpServerTelemetryBuilder<REQUEST,RESPONSE> setKnownMethods(java.util.Set<java.lang.String>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpServerTelemetryBuilder<REQUEST,RESPONSE> setSpanNameExtractor(java.util.function.Function<io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor<REQUEST>,io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor<REQUEST>>)
+++ NEW METHOD: PUBLIC(+) ABSTRACT(+) io.opentelemetry.instrumentation.api.semconv.http.HttpServerTelemetryBuilder<REQUEST,RESPONSE> setStatusExtractor(java.util.function.Function<io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor<REQUEST,RESPONSE>,io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor<REQUEST,RESPONSE>>)
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
@@ -0,0 +1,44 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.semconv.http;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

public interface HttpClientTelemetryBuilder<REQUEST, RESPONSE> {

@CanIgnoreReturnValue
HttpClientTelemetryBuilder<REQUEST, RESPONSE> addAttributesExtractor(
AttributesExtractor<REQUEST, RESPONSE> attributesExtractor);

@CanIgnoreReturnValue
HttpClientTelemetryBuilder<REQUEST, RESPONSE> setCapturedRequestHeaders(
List<String> requestHeaders);

@CanIgnoreReturnValue
HttpClientTelemetryBuilder<REQUEST, RESPONSE> setCapturedResponseHeaders(
List<String> responseHeaders);

@CanIgnoreReturnValue
HttpClientTelemetryBuilder<REQUEST, RESPONSE> setKnownMethods(Set<String> knownMethods);

@CanIgnoreReturnValue
HttpClientTelemetryBuilder<REQUEST, RESPONSE> setSpanNameExtractor(
Function<SpanNameExtractor<REQUEST>, SpanNameExtractor<REQUEST>>
spanNameExtractorTransformer);

@CanIgnoreReturnValue
HttpClientTelemetryBuilder<REQUEST, RESPONSE> setStatusExtractor(
Function<SpanStatusExtractor<REQUEST, RESPONSE>, SpanStatusExtractor<REQUEST, RESPONSE>>
statusExtractorTransformer);

Object build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.semconv.http;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

public interface HttpServerTelemetryBuilder<REQUEST, RESPONSE> {

@CanIgnoreReturnValue
HttpServerTelemetryBuilder<REQUEST, RESPONSE> addAttributesExtractor(
AttributesExtractor<REQUEST, RESPONSE> attributesExtractor);

@CanIgnoreReturnValue
HttpServerTelemetryBuilder<REQUEST, RESPONSE> setCapturedRequestHeaders(
List<String> requestHeaders);

@CanIgnoreReturnValue
HttpServerTelemetryBuilder<REQUEST, RESPONSE> setCapturedResponseHeaders(
List<String> responseHeaders);

@CanIgnoreReturnValue
HttpServerTelemetryBuilder<REQUEST, RESPONSE> setKnownMethods(Set<String> knownMethods);

@CanIgnoreReturnValue
HttpServerTelemetryBuilder<REQUEST, RESPONSE> setSpanNameExtractor(
Function<SpanNameExtractor<REQUEST>, SpanNameExtractor<REQUEST>>
spanNameExtractorTransformer);

@CanIgnoreReturnValue
HttpServerTelemetryBuilder<REQUEST, RESPONSE> setStatusExtractor(
Function<SpanStatusExtractor<REQUEST, RESPONSE>, SpanStatusExtractor<REQUEST, RESPONSE>>
statusExtractorTransformer);

Object build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
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.api.semconv.http.HttpClientTelemetryBuilder;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import org.apache.http.HttpResponse;

/** A builder for {@link ApacheHttpClientTelemetry}. */
public final class ApacheHttpClientTelemetryBuilder {
public final class ApacheHttpClientTelemetryBuilder
implements HttpClientTelemetryBuilder<ApacheHttpClientRequest, HttpResponse> {

private static final String INSTRUMENTATION_NAME = "io.opentelemetry.apache-httpclient-4.3";
private final DefaultHttpClientInstrumenterBuilder<ApacheHttpClientRequest, HttpResponse> builder;
Expand Down Expand Up @@ -50,10 +53,10 @@ public ApacheHttpClientTelemetryBuilder addAttributeExtractor(
* Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented
* items. The {@link AttributesExtractor} will be executed after all default extractors.
*/
@Override
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder addAttributesExtractor(
AttributesExtractor<? super ApacheHttpClientRequest, ? super HttpResponse>
attributesExtractor) {
AttributesExtractor<ApacheHttpClientRequest, HttpResponse> attributesExtractor) {
builder.addAttributesExtractor(attributesExtractor);
return this;
}
Expand All @@ -63,6 +66,7 @@ public ApacheHttpClientTelemetryBuilder addAttributesExtractor(
*
* @param requestHeaders A list of HTTP header names.
*/
@Override
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder setCapturedRequestHeaders(List<String> requestHeaders) {
builder.setCapturedRequestHeaders(requestHeaders);
Expand All @@ -74,6 +78,7 @@ public ApacheHttpClientTelemetryBuilder setCapturedRequestHeaders(List<String> r
*
* @param responseHeaders A list of HTTP header names.
*/
@Override
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder setCapturedResponseHeaders(List<String> responseHeaders) {
builder.setCapturedResponseHeaders(responseHeaders);
Expand All @@ -93,6 +98,7 @@ public ApacheHttpClientTelemetryBuilder setCapturedResponseHeaders(List<String>
* @param knownMethods A set of recognized HTTP request methods.
* @see HttpClientAttributesExtractorBuilder#setKnownMethods(Set)
*/
@Override
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder setKnownMethods(Set<String> knownMethods) {
builder.setKnownMethods(knownMethods);
Expand All @@ -117,20 +123,32 @@ public ApacheHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics(
}

/** Sets custom {@link SpanNameExtractor} via transform function. */
@Override
@CanIgnoreReturnValue
public ApacheHttpClientTelemetryBuilder setSpanNameExtractor(
Function<
SpanNameExtractor<? super ApacheHttpClientRequest>,
? extends SpanNameExtractor<? super ApacheHttpClientRequest>>
SpanNameExtractor<ApacheHttpClientRequest>,
SpanNameExtractor<ApacheHttpClientRequest>>
spanNameExtractorTransformer) {
builder.setSpanNameExtractor(spanNameExtractorTransformer);
return this;
}

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

/**
* Returns a new {@link ApacheHttpClientTelemetry} configured with this {@link
* ApacheHttpClientTelemetryBuilder}.
*/
@Override
public ApacheHttpClientTelemetry build() {
return new ApacheHttpClientTelemetry(builder.build(), openTelemetry.getPropagators());
}
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
Loading

0 comments on commit 96f4e96

Please # to comment.