Move SpanKey to internal package
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBuilder.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterBuilder.java
@@ -21,6 +21,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtracto
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcAttributesExtractor;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanKeyExtractor.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanKeyExtractor.java
@@ -9,6 +9,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtracto
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcAttributesExtractor;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanSuppressionStrategy.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanSuppressionStrategy.java
@@ -10,6 +10,7 @@ import static java.util.Collections.singleton;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import java.util.Set;
abstract class SpanSuppressionStrategy {

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SuppressIfSameSpanKeyStrategy.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SuppressIfSameSpanKeyStrategy.java
@@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.api.instrumenter;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import java.util.Set;
final class SuppressIfSameSpanKeyStrategy extends SpanSuppressionStrategy {

RENAME
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanKey.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/SpanKey.java
* 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;
@@ -43,16 +43,16 @@ public final class SpanKey {
public static final SpanKey SERVER = new SpanKey(SERVER_KEY);
- static final SpanKey HTTP_CLIENT = new SpanKey(HTTP_CLIENT_KEY);
- static final SpanKey RPC_CLIENT = new SpanKey(RPC_CLIENT_KEY);
- static final SpanKey DB_CLIENT = new SpanKey(DB_CLIENT_KEY);
+ public static final SpanKey HTTP_CLIENT = new SpanKey(HTTP_CLIENT_KEY);
+ public static final SpanKey RPC_CLIENT = new SpanKey(RPC_CLIENT_KEY);
+ public static final SpanKey DB_CLIENT = new SpanKey(DB_CLIENT_KEY);
// this is used instead of above, depending on the configuration value for
// otel.instrumentation.experimental.outgoing-span-suppression-by-type
public static final SpanKey ALL_CLIENTS = new SpanKey(CLIENT_KEY);
- static final SpanKey PRODUCER = new SpanKey(PRODUCER_KEY);
- static final SpanKey CONSUMER_RECEIVE = new SpanKey(CONSUMER_RECEIVE_KEY);
+ public static final SpanKey PRODUCER = new SpanKey(PRODUCER_KEY);
+ public static final SpanKey CONSUMER_RECEIVE = new SpanKey(CONSUMER_RECEIVE_KEY);
public static final SpanKey CONSUMER_PROCESS = new SpanKey(CONSUMER_PROCESS_KEY);
private final ContextKey<Span> key;

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClientSpan.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClientSpan.java
@@ -8,7 +8,7 @@ package io.opentelemetry.instrumentation.api.tracer;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
-import io.opentelemetry.instrumentation.api.instrumenter.SpanKey;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import javax.annotation.Nullable;
/**

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ConsumerSpan.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ConsumerSpan.java
@@ -8,7 +8,7 @@ package io.opentelemetry.instrumentation.api.tracer;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
-import io.opentelemetry.instrumentation.api.instrumenter.SpanKey;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import javax.annotation.Nullable;
/**

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ServerSpan.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ServerSpan.java
@@ -8,7 +8,7 @@ package io.opentelemetry.instrumentation.api.tracer;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
-import io.opentelemetry.instrumentation.api.instrumenter.SpanKey;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import javax.annotation.Nullable;
/**

MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java
@@ -31,6 +31,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperat
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcAttributesExtractor;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import io.opentelemetry.sdk.trace.data.LinkData;

MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/SpanKeyExtractorTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/SpanKeyExtractorTest.java
@@ -16,6 +16,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation;
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcAttributesExtractor;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import java.util.Set;
import java.util.stream.Stream;
import org.junit.jupiter.api.extension.ExtensionContext;

MODIFY
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/SpanSuppressionStrategyTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/SpanSuppressionStrategyTest.java
@@ -12,6 +12,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;

MODIFY
instrumentation/kafka-clients/kafka-clients-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/ConsumerRecordsInstrumentation.java
instrumentation/kafka-clients/kafka-clients-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/ConsumerRecordsInstrumentation.java
@@ -15,7 +15,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.field.VirtualField;
-import io.opentelemetry.instrumentation.api.instrumenter.SpanKey;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.util.Iterator;

MODIFY
instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/context/AgentContextStorage.java
instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/context/AgentContextStorage.java
@@ -168,8 +168,8 @@ public class AgentContextStorage implements ContextStorage, AutoCloseable {
private static ContextKeyBridge<Span, io.opentelemetry.api.trace.Span> bridgeSpanKey(
String name) {
return new ContextKeyBridge<>(
- "application.io.opentelemetry.instrumentation.api.instrumenter.SpanKey",
- "io.opentelemetry.instrumentation.api.instrumenter.SpanKey",
+ "application.io.opentelemetry.instrumentation.api.internal.SpanKey",
+ "io.opentelemetry.instrumentation.api.internal.SpanKey",
name,
Bridging::toApplication,
Bridging::toAgentOrNull);

MODIFY
instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/groovy/ContextBridgeTest.groovy
instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/test/groovy/ContextBridgeTest.groovy
@@ -9,7 +9,7 @@ import io.opentelemetry.api.trace.Span
import io.opentelemetry.context.Context
import io.opentelemetry.context.ContextKey
import io.opentelemetry.extension.annotations.WithSpan
-import io.opentelemetry.instrumentation.api.instrumenter.SpanKey
+import io.opentelemetry.instrumentation.api.internal.SpanKey
import io.opentelemetry.instrumentation.api.tracer.ServerSpan
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification

MODIFY
instrumentation/opentelemetry-api/opentelemetry-api-1.0/testing/src/main/java/AgentSpanTesting.java
instrumentation/opentelemetry-api/opentelemetry-api-1.0/testing/src/main/java/AgentSpanTesting.java
* SPDX-License-Identifier: Apache-2.0
*/
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
+
public class AgentSpanTesting {
/**
@@ -23,8 +25,7 @@ public class AgentSpanTesting {
/**
* Runs the provided {@code runnable} inside the scope of an INTERNAL span with name {@code
- * spanName}. Span is added into context under all possible keys from {@link
- * io.opentelemetry.instrumentation.api.instrumenter.SpanKey}
+ * spanName}. Span is added into context under all possible keys from {@link SpanKey}
*/
public static void runWithAllSpanKeys(String spanName, Runnable runnable) {
runnable.run();

MODIFY
instrumentation/opentelemetry-api/opentelemetry-api-1.0/testing/src/main/java/AgentSpanTestingInstrumenter.java
instrumentation/opentelemetry-api/opentelemetry-api-1.0/testing/src/main/java/AgentSpanTestingInstrumenter.java
@@ -9,8 +9,7 @@ import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.ContextKey;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
-import io.opentelemetry.instrumentation.api.instrumenter.SpanKey;
-import java.lang.reflect.Field;
+import io.opentelemetry.instrumentation.api.internal.SpanKey;
public final class AgentSpanTestingInstrumenter {
@@ -35,7 +34,7 @@ public final class AgentSpanTestingInstrumenter {
public static Context startSpanWithAllKeys(String name) {
Context context = start(name, SpanKind.INTERNAL);
Span span = Span.fromContext(context);
- for (SpanKey spanKey : SpanKeyAccess.getSpanKeys()) {
+ for (SpanKey spanKey : getSpanKeys()) {
context = spanKey.storeInContext(context, span);
}
return context;
@@ -59,31 +58,18 @@ public final class AgentSpanTestingInstrumenter {
}
}
- private static final class SpanKeyAccess {
-
- public static SpanKey[] getSpanKeys() {
+ private static SpanKey[] getSpanKeys() {
return new SpanKey[] {
SpanKey.SERVER,
- getSpanKeyByName("HTTP_CLIENT"),
- getSpanKeyByName("RPC_CLIENT"),
- getSpanKeyByName("DB_CLIENT"),
+ SpanKey.HTTP_CLIENT,
+ SpanKey.RPC_CLIENT,
+ SpanKey.DB_CLIENT,
SpanKey.ALL_CLIENTS,
- getSpanKeyByName("PRODUCER"),
- getSpanKeyByName("CONSUMER_RECEIVE"),
- getSpanKeyByName("CONSUMER_PROCESS")
+ SpanKey.PRODUCER,
+ SpanKey.CONSUMER_RECEIVE,
+ SpanKey.CONSUMER_PROCESS
};
}
- private static SpanKey getSpanKeyByName(String name) {
- try {
- Field field = SpanKey.class.getDeclaredField(name);
- field.setAccessible(true);
- return (SpanKey) field.get(name);
- } catch (NoSuchFieldException | IllegalAccessException exception) {
- throw new IllegalStateException("Failed to find span key named " + name, exception);
- }
- }
- }
-
private AgentSpanTestingInstrumenter() {}
}

Move SpanKey to internal package (#4869)

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>