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

Move extractFromRequest() to internal #6585

Merged
merged 2 commits into from
Sep 12, 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 @@ -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
Expand All @@ -19,13 +17,4 @@ public interface SpanLinksExtractor<REQUEST> {
* {@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 <REQUEST> SpanLinksExtractor<REQUEST> extractFromRequest(
TextMapPropagator propagator, TextMapGetter<REQUEST> getter) {
return new PropagatorBasedSpanLinksExtractor<>(propagator, getter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<REQUEST>
implements SpanLinksExtractor<REQUEST> {

final class PropagatorBasedSpanLinksExtractor<REQUEST> implements SpanLinksExtractor<REQUEST> {
private final TextMapPropagator propagator;
private final TextMapGetter<REQUEST> getter;

PropagatorBasedSpanLinksExtractor(TextMapPropagator propagator, TextMapGetter<REQUEST> getter) {
public PropagatorBasedSpanLinksExtractor(
TextMapPropagator propagator, TextMapGetter<REQUEST> getter) {
this.propagator = propagator;
this.getter = getter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@ void shouldExtractSpanLink() {
TextMapPropagator propagator = W3CTraceContextPropagator.getInstance();

SpanLinksExtractor<Map<String, String>> underTest =
SpanLinksExtractor.extractFromRequest(propagator, new MapGetter());
new PropagatorBasedSpanLinksExtractor<>(propagator, new MapGetter());

Map<String, String> request =
singletonMap("traceparent", String.format("00-%s-%s-01", TRACE_ID, SPAN_ID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,7 +20,7 @@ final class KafkaBatchProcessSpanLinksExtractor

KafkaBatchProcessSpanLinksExtractor(TextMapPropagator propagator) {
this.singleRecordLinkExtractor =
SpanLinksExtractor.extractFromRequest(propagator, KafkaConsumerRecordGetter.INSTANCE);
new PropagatorBasedSpanLinksExtractor<>(propagator, KafkaConsumerRecordGetter.INSTANCE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,7 +135,7 @@ public KafkaInstrumenterFactory setMessagingReceiveInstrumentationEnabled(
return builder.buildInstrumenter(SpanKindExtractor.alwaysConsumer());
} else if (messagingReceiveInstrumentationEnabled) {
builder.addSpanLinksExtractor(
SpanLinksExtractor.extractFromRequest(
new PropagatorBasedSpanLinksExtractor<ConsumerRecord<?, ?>>(
openTelemetry.getPropagators().getTextMapPropagator(),
KafkaConsumerRecordGetter.INSTANCE));
return builder.buildInstrumenter(SpanKindExtractor.alwaysConsumer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +111,7 @@ private static Instrumenter<MessageExt, Void> createProcessInstrumenter(

if (batch) {
SpanLinksExtractor<MessageExt> spanLinksExtractor =
SpanLinksExtractor.extractFromRequest(
new PropagatorBasedSpanLinksExtractor<>(
openTelemetry.getPropagators().getTextMapPropagator(),
TextMapExtractAdapter.INSTANCE);

Expand Down