From 35c2e214db090bf6819775a9eedaafeab0a77537 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 12 Sep 2022 07:36:07 -0700 Subject: [PATCH] Move extractFromRequest() to internal (#6585) * Move extractFromRequest() to internal * Javadoc --- .../api/instrumenter/SpanLinksExtractor.java | 11 ----------- .../PropagatorBasedSpanLinksExtractor.java | 15 ++++++++++++--- .../PropagatorBasedSpanLinksExtractorTest.java | 3 ++- .../KafkaBatchProcessSpanLinksExtractor.java | 3 ++- .../kafka/internal/KafkaInstrumenterFactory.java | 4 ++-- .../rocketmq/RocketMqInstrumenterFactory.java | 3 ++- 6 files changed, 20 insertions(+), 19 deletions(-) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/{instrumenter => internal}/PropagatorBasedSpanLinksExtractor.java (56%) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanLinksExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanLinksExtractor.java index 71a7173b2ffd..77ce0e2c0fea 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanLinksExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanLinksExtractor.java @@ -7,8 +7,6 @@ import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.context.propagation.TextMapPropagator; /** Extractor of span links for a request. */ @FunctionalInterface @@ -19,13 +17,4 @@ public interface SpanLinksExtractor { * {@code spanLinks}. */ void extract(SpanLinksBuilder spanLinks, Context parentContext, REQUEST request); - - /** - * Returns a new {@link SpanLinksExtractor} that will extract a {@link SpanContext} from the - * request using configured {@link TextMapPropagator}. - */ - static SpanLinksExtractor extractFromRequest( - TextMapPropagator propagator, TextMapGetter getter) { - return new PropagatorBasedSpanLinksExtractor<>(propagator, getter); - } } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PropagatorBasedSpanLinksExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/PropagatorBasedSpanLinksExtractor.java similarity index 56% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PropagatorBasedSpanLinksExtractor.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/PropagatorBasedSpanLinksExtractor.java index 529c8c6bc6df..5439ea25995a 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PropagatorBasedSpanLinksExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/PropagatorBasedSpanLinksExtractor.java @@ -3,18 +3,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter; +package io.opentelemetry.instrumentation.api.internal; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.instrumentation.api.instrumenter.SpanLinksBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.SpanLinksExtractor; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class PropagatorBasedSpanLinksExtractor + implements SpanLinksExtractor { -final class PropagatorBasedSpanLinksExtractor implements SpanLinksExtractor { private final TextMapPropagator propagator; private final TextMapGetter getter; - PropagatorBasedSpanLinksExtractor(TextMapPropagator propagator, TextMapGetter getter) { + public PropagatorBasedSpanLinksExtractor( + TextMapPropagator propagator, TextMapGetter getter) { this.propagator = propagator; this.getter = getter; } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PropagatorBasedSpanLinksExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PropagatorBasedSpanLinksExtractorTest.java index ac78b15a8adb..aad6c32c6726 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PropagatorBasedSpanLinksExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PropagatorBasedSpanLinksExtractorTest.java @@ -17,6 +17,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.instrumentation.api.internal.PropagatorBasedSpanLinksExtractor; import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -36,7 +37,7 @@ void shouldExtractSpanLink() { TextMapPropagator propagator = W3CTraceContextPropagator.getInstance(); SpanLinksExtractor> underTest = - SpanLinksExtractor.extractFromRequest(propagator, new MapGetter()); + new PropagatorBasedSpanLinksExtractor<>(propagator, new MapGetter()); Map request = singletonMap("traceparent", String.format("00-%s-%s-01", TRACE_ID, SPAN_ID)); diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaBatchProcessSpanLinksExtractor.java b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaBatchProcessSpanLinksExtractor.java index dbb638bec1e1..ce60593501b8 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaBatchProcessSpanLinksExtractor.java +++ b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaBatchProcessSpanLinksExtractor.java @@ -9,6 +9,7 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.instrumentation.api.instrumenter.SpanLinksBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanLinksExtractor; +import io.opentelemetry.instrumentation.api.internal.PropagatorBasedSpanLinksExtractor; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; @@ -19,7 +20,7 @@ final class KafkaBatchProcessSpanLinksExtractor KafkaBatchProcessSpanLinksExtractor(TextMapPropagator propagator) { this.singleRecordLinkExtractor = - SpanLinksExtractor.extractFromRequest(propagator, KafkaConsumerRecordGetter.INSTANCE); + new PropagatorBasedSpanLinksExtractor<>(propagator, KafkaConsumerRecordGetter.INSTANCE); } @Override diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java index e8d146a4dc6a..20ca8229cf12 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java +++ b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaInstrumenterFactory.java @@ -13,11 +13,11 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.SpanLinksExtractor; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingSpanNameExtractor; +import io.opentelemetry.instrumentation.api.internal.PropagatorBasedSpanLinksExtractor; import java.util.Collections; import java.util.List; import org.apache.kafka.clients.consumer.ConsumerRecord; @@ -135,7 +135,7 @@ public KafkaInstrumenterFactory setMessagingReceiveInstrumentationEnabled( return builder.buildInstrumenter(SpanKindExtractor.alwaysConsumer()); } else if (messagingReceiveInstrumentationEnabled) { builder.addSpanLinksExtractor( - SpanLinksExtractor.extractFromRequest( + new PropagatorBasedSpanLinksExtractor>( openTelemetry.getPropagators().getTextMapPropagator(), KafkaConsumerRecordGetter.INSTANCE)); return builder.buildInstrumenter(SpanKindExtractor.alwaysConsumer()); diff --git a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RocketMqInstrumenterFactory.java b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RocketMqInstrumenterFactory.java index 7e5eeef13d81..84a43684b7fb 100644 --- a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RocketMqInstrumenterFactory.java +++ b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RocketMqInstrumenterFactory.java @@ -18,6 +18,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingSpanNameExtractor; +import io.opentelemetry.instrumentation.api.internal.PropagatorBasedSpanLinksExtractor; import java.util.List; import org.apache.rocketmq.client.hook.SendMessageContext; import org.apache.rocketmq.common.message.MessageExt; @@ -110,7 +111,7 @@ private static Instrumenter createProcessInstrumenter( if (batch) { SpanLinksExtractor spanLinksExtractor = - SpanLinksExtractor.extractFromRequest( + new PropagatorBasedSpanLinksExtractor<>( openTelemetry.getPropagators().getTextMapPropagator(), TextMapExtractAdapter.INSTANCE);