Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename newInstrumenter() into buildInstrumenter() #6363

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void shouldSetRouteEvenIfSpanIsNotSampled() {
Instrumenter<String, Void> instrumenter =
Instrumenter.<String, Void>builder(testing.getOpenTelemetry(), "test", s -> s)
.addContextCustomizer(HttpRouteHolder.get())
.newInstrumenter();
.buildInstrumenter();

Context context = instrumenter.start(Context.root(), "test");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class InstrumenterBenchmark {
HttpClientAttributesExtractor.create(ConstantHttpAttributesGetter.INSTANCE))
.addAttributesExtractor(
NetServerAttributesExtractor.create(new ConstantNetAttributesGetter()))
.newInstrumenter();
.buildInstrumenter();

@Benchmark
public Context start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,59 +183,134 @@ public InstrumenterBuilder<REQUEST, RESPONSE> setEnabled(boolean enabled) {
/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#CLIENT client} spans
* and inject context into requests.
*
* @deprecated Use {@link #buildClientInstrumenter(TextMapSetter)} instead.
*/
@Deprecated
public Instrumenter<REQUEST, RESPONSE> newClientInstrumenter(TextMapSetter<REQUEST> setter) {
return newInstrumenter(
return buildInstrumenter(
InstrumenterConstructor.propagatingToDownstream(setter), SpanKindExtractor.alwaysClient());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#SERVER server} spans
* and extract context from requests.
*
* @deprecated Use {@link #buildServerInstrumenter(TextMapGetter)} instead.
*/
@Deprecated
public Instrumenter<REQUEST, RESPONSE> newServerInstrumenter(TextMapGetter<REQUEST> getter) {
return newInstrumenter(
return buildInstrumenter(
InstrumenterConstructor.propagatingFromUpstream(getter), SpanKindExtractor.alwaysServer());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#PRODUCER producer}
* spans and inject context into requests.
*
* @deprecated Use {@link #buildProducerInstrumenter(TextMapSetter)} instead.
*/
@Deprecated
public Instrumenter<REQUEST, RESPONSE> newProducerInstrumenter(TextMapSetter<REQUEST> setter) {
return newInstrumenter(
return buildInstrumenter(
InstrumenterConstructor.propagatingToDownstream(setter),
SpanKindExtractor.alwaysProducer());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#CONSUMER consumer}
* spans and extract context from requests.
*
* @deprecated Use {@link #buildConsumerInstrumenter(TextMapGetter)} instead.
*/
@Deprecated
public Instrumenter<REQUEST, RESPONSE> newConsumerInstrumenter(TextMapGetter<REQUEST> getter) {
return newInstrumenter(
return buildInstrumenter(
InstrumenterConstructor.propagatingFromUpstream(getter),
SpanKindExtractor.alwaysConsumer());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#INTERNAL internal}
* spans and do no context propagation.
*
* @deprecated Use {@link #buildInstrumenter()} instead.
*/
@Deprecated
public Instrumenter<REQUEST, RESPONSE> newInstrumenter() {
return newInstrumenter(InstrumenterConstructor.internal(), SpanKindExtractor.alwaysInternal());
return buildInstrumenter(
InstrumenterConstructor.internal(), SpanKindExtractor.alwaysInternal());
}

/**
* Returns a new {@link Instrumenter} which will create spans with kind determined by the passed
* {@link SpanKindExtractor} and do no context propagation.
*
* @deprecated Use {@link #buildInstrumenter(SpanKindExtractor)} instead.
*/
@Deprecated
public Instrumenter<REQUEST, RESPONSE> newInstrumenter(
SpanKindExtractor<? super REQUEST> spanKindExtractor) {
return newInstrumenter(InstrumenterConstructor.internal(), spanKindExtractor);
return buildInstrumenter(InstrumenterConstructor.internal(), spanKindExtractor);
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#CLIENT client} spans
* and inject context into requests.
*/
public Instrumenter<REQUEST, RESPONSE> buildClientInstrumenter(TextMapSetter<REQUEST> setter) {
return buildInstrumenter(
InstrumenterConstructor.propagatingToDownstream(setter), SpanKindExtractor.alwaysClient());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#SERVER server} spans
* and extract context from requests.
*/
public Instrumenter<REQUEST, RESPONSE> buildServerInstrumenter(TextMapGetter<REQUEST> getter) {
return buildInstrumenter(
InstrumenterConstructor.propagatingFromUpstream(getter), SpanKindExtractor.alwaysServer());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#PRODUCER producer}
* spans and inject context into requests.
*/
public Instrumenter<REQUEST, RESPONSE> buildProducerInstrumenter(TextMapSetter<REQUEST> setter) {
return buildInstrumenter(
InstrumenterConstructor.propagatingToDownstream(setter),
SpanKindExtractor.alwaysProducer());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#CONSUMER consumer}
* spans and extract context from requests.
*/
public Instrumenter<REQUEST, RESPONSE> buildConsumerInstrumenter(TextMapGetter<REQUEST> getter) {
return buildInstrumenter(
InstrumenterConstructor.propagatingFromUpstream(getter),
SpanKindExtractor.alwaysConsumer());
}

/**
* Returns a new {@link Instrumenter} which will create {@linkplain SpanKind#INTERNAL internal}
* spans and do no context propagation.
*/
public Instrumenter<REQUEST, RESPONSE> buildInstrumenter() {
return buildInstrumenter(
InstrumenterConstructor.internal(), SpanKindExtractor.alwaysInternal());
}

/**
* Returns a new {@link Instrumenter} which will create spans with kind determined by the passed
* {@link SpanKindExtractor} and do no context propagation.
*/
public Instrumenter<REQUEST, RESPONSE> buildInstrumenter(
SpanKindExtractor<? super REQUEST> spanKindExtractor) {
return buildInstrumenter(InstrumenterConstructor.internal(), spanKindExtractor);
}

private Instrumenter<REQUEST, RESPONSE> newInstrumenter(
private Instrumenter<REQUEST, RESPONSE> buildInstrumenter(
InstrumenterConstructor<REQUEST, RESPONSE> constructor,
SpanKindExtractor<? super REQUEST> spanKindExtractor) {
this.spanKindExtractor = spanKindExtractor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void server() {
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.addSpanLinksExtractor(new LinksExtractor())
.newServerInstrumenter(new MapGetter());
.buildServerInstrumenter(new MapGetter());

Context context = instrumenter.start(Context.root(), REQUEST);
SpanContext spanContext = Span.fromContext(context).getSpanContext();
Expand Down Expand Up @@ -196,7 +196,7 @@ void server_error() {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.newServerInstrumenter(new MapGetter());
.buildServerInstrumenter(new MapGetter());

Context context = instrumenter.start(Context.root(), REQUEST);
assertThat(Span.fromContext(context).getSpanContext().isValid()).isTrue();
Expand All @@ -217,7 +217,7 @@ void server_parent() {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.newServerInstrumenter(new MapGetter());
.buildServerInstrumenter(new MapGetter());

Map<String, String> request = new HashMap<>(REQUEST);
W3CTraceContextPropagator.getInstance()
Expand Down Expand Up @@ -258,7 +258,7 @@ void client() {
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.addSpanLinksExtractor(new LinksExtractor())
.newClientInstrumenter(Map::put);
.buildClientInstrumenter(Map::put);

Map<String, String> request = new HashMap<>(REQUEST);
Context context = instrumenter.start(Context.root(), request);
Expand Down Expand Up @@ -301,7 +301,7 @@ void client_error() {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.newClientInstrumenter(Map::put);
.buildClientInstrumenter(Map::put);

Map<String, String> request = new HashMap<>(REQUEST);
Context context = instrumenter.start(Context.root(), request);
Expand All @@ -326,7 +326,7 @@ void client_parent() {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addAttributesExtractors(new AttributesExtractor1(), new AttributesExtractor2())
.newClientInstrumenter(Map::put);
.buildClientInstrumenter(Map::put);

Context parent =
Context.root()
Expand Down Expand Up @@ -383,7 +383,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addOperationListener(operationListener)
.newServerInstrumenter(new MapGetter());
.buildServerInstrumenter(new MapGetter());

Context context = instrumenter.start(Context.root(), REQUEST);
instrumenter.end(context, REQUEST, RESPONSE, null);
Expand Down Expand Up @@ -415,7 +415,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", unused -> "span")
.addOperationMetrics(meter -> operationListener)
.newServerInstrumenter(new MapGetter());
.buildServerInstrumenter(new MapGetter());

Context context = instrumenter.start(Context.root(), REQUEST);
instrumenter.end(context, REQUEST, RESPONSE, null);
Expand All @@ -432,7 +432,7 @@ void shouldNotAddInvalidLink() {
otelTesting.getOpenTelemetry(), "test", request -> "test span")
.addSpanLinksExtractor(
(spanLinks, parentContext, request) -> spanLinks.addLink(SpanContext.getInvalid()))
.newInstrumenter();
.buildInstrumenter();

// when
Context context = instrumenter.start(Context.root(), "request");
Expand All @@ -456,7 +456,7 @@ void shouldUseContextCustomizer() {
otelTesting.getOpenTelemetry(), "test", request -> "test span")
.addContextCustomizer(
(context, request, attributes) -> context.with(testKey, "testVal"))
.newInstrumenter();
.buildInstrumenter();

// when
Context context = instrumenter.start(Context.root(), "request");
Expand All @@ -471,7 +471,7 @@ void shouldDisableInstrumenter() {
Instrumenter.<String, String>builder(
otelTesting.getOpenTelemetry(), "test", request -> "test span")
.setEnabled(false)
.newInstrumenter();
.buildInstrumenter();

assertThat(instrumenter.shouldStart(Context.root(), "request")).isFalse();
}
Expand All @@ -482,7 +482,8 @@ void instrumentationVersion_default() {
Instrumenter.builder(
otelTesting.getOpenTelemetry(), "test-instrumentation", name -> "span");

Instrumenter<Map<String, String>, Map<String, String>> instrumenter = builder.newInstrumenter();
Instrumenter<Map<String, String>, Map<String, String>> instrumenter =
builder.buildInstrumenter();

Context context = instrumenter.start(Context.root(), Collections.emptyMap());
assertThat(Span.fromContext(context)).isNotNull();
Expand All @@ -507,7 +508,7 @@ void instrumentationVersion_custom() {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", name -> "span")
.setInstrumentationVersion("1.0")
.newInstrumenter();
.buildInstrumenter();

Context context = instrumenter.start(Context.root(), Collections.emptyMap());
assertThat(Span.fromContext(context)).isNotNull();
Expand All @@ -532,7 +533,7 @@ void schemaUrl() {
Instrumenter.<Map<String, String>, Map<String, String>>builder(
otelTesting.getOpenTelemetry(), "test", name -> "span")
.setSchemaUrl("https://opentelemetry.io/schemas/1.0.0")
.newInstrumenter();
.buildInstrumenter();

Context context = instrumenter.start(Context.root(), Collections.emptyMap());
assertThat(Span.fromContext(context)).isNotNull();
Expand Down Expand Up @@ -564,7 +565,7 @@ void shouldRetrieveSpanKeysFromAttributesExtractors() {
mockHttpClientAttributes,
mockNetClientAttributes,
mockDbClientAttributes)
.newInstrumenter();
.buildInstrumenter();

Context context = instrumenter.start(Context.root(), REQUEST);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AkkaHttpClientSingletons {
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.newInstrumenter(SpanKindExtractor.alwaysClient());
.buildInstrumenter(SpanKindExtractor.alwaysClient());
}

public static Instrumenter<HttpRequest, HttpResponse> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AkkaHttpServerSingletons {
.build())
.addOperationMetrics(HttpServerMetrics.get())
.addContextCustomizer(HttpRouteHolder.get())
.newServerInstrumenter(AkkaHttpServerHeaders.INSTANCE);
.buildServerInstrumenter(AkkaHttpServerHeaders.INSTANCE);
}

public static Instrumenter<HttpRequest, HttpResponse> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onEnd(
builder.addAttributesExtractor(attributesExtractor);
builder.setSpanStatusExtractor(spanStatusExtractor);

INSTRUMENTER = builder.newInstrumenter(request -> request.getSpanKind());
INSTRUMENTER = builder.buildInstrumenter(request -> request.getSpanKind());
}

public static Instrumenter<CamelRequest, Void> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public DubboTelemetry build() {
}

return new DubboTelemetry(
serverInstrumenterBuilder.newServerInstrumenter(DubboHeadersGetter.INSTANCE),
clientInstrumenterBuilder.newClientInstrumenter(DubboHeadersSetter.INSTANCE));
serverInstrumenterBuilder.buildServerInstrumenter(DubboHeadersGetter.INSTANCE),
clientInstrumenterBuilder.buildClientInstrumenter(DubboHeadersSetter.INSTANCE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class ApacheHttpAsyncClientSingletons {
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
.buildClientInstrumenter(HttpHeaderSetter.INSTANCE);
}

public static Instrumenter<ApacheHttpClientRequest, HttpResponse> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class ApacheHttpClientSingletons {
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
.buildClientInstrumenter(HttpHeaderSetter.INSTANCE);
}

public static Instrumenter<HttpMethod, HttpMethod> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final class ApacheHttpClientSingletons {
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
.buildClientInstrumenter(HttpHeaderSetter.INSTANCE);
}

public static Instrumenter<ApacheHttpClientRequest, HttpResponse> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public ApacheHttpClientTelemetry build() {
.addAttributesExtractor(NetClientAttributesExtractor.create(netAttributesGetter))
.addAttributesExtractors(additionalExtractors)
// We manually inject because we need to inject internal requests for redirects.
.newInstrumenter(SpanKindExtractor.alwaysClient());
.buildInstrumenter(SpanKindExtractor.alwaysClient());

return new ApacheHttpClientTelemetry(instrumenter, openTelemetry.getPropagators());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class ApacheHttpClientSingletons {
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
.buildClientInstrumenter(HttpHeaderSetter.INSTANCE);
}

public static Instrumenter<HttpRequest, HttpResponse> instrumenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public ArmeriaTelemetry build() {
}

return new ArmeriaTelemetry(
clientInstrumenterBuilder.newClientInstrumenter(ClientRequestContextSetter.INSTANCE),
serverInstrumenterBuilder.newServerInstrumenter(RequestContextGetter.INSTANCE));
clientInstrumenterBuilder.buildClientInstrumenter(ClientRequestContextSetter.INSTANCE),
serverInstrumenterBuilder.buildServerInstrumenter(RequestContextGetter.INSTANCE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class AsyncHttpClientSingletons {
PeerServiceAttributesExtractor.create(
netAttributesGetter, CommonConfig.get().getPeerServiceMapping()))
.addOperationMetrics(HttpClientMetrics.get())
.newClientInstrumenter(HttpHeaderSetter.INSTANCE);
.buildClientInstrumenter(HttpHeaderSetter.INSTANCE);
}

public static Instrumenter<Request, Response> instrumenter() {
Expand Down
Loading