Skip to content

Move SpanKey to internal package #4869

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

Merged
merged 2 commits into from
Dec 14, 2021
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 @@ -21,6 +21,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public static Context newContextWrapper(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import io.opentelemetry.instrumentation.api.internal.SpanKey;

public class AgentSpanTesting {

/**
Expand All @@ -23,8 +25,7 @@ public static void runWithClientSpan(String spanName, Runnable runnable) {

/**
* 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
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 {

Expand All @@ -35,7 +34,7 @@ public static Context startClientSpan(String name) {
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;
Expand All @@ -59,30 +58,17 @@ public Request(String name, SpanKind kind) {
}
}

private static final class SpanKeyAccess {

public static SpanKey[] getSpanKeys() {
return new SpanKey[] {
SpanKey.SERVER,
getSpanKeyByName("HTTP_CLIENT"),
getSpanKeyByName("RPC_CLIENT"),
getSpanKeyByName("DB_CLIENT"),
SpanKey.ALL_CLIENTS,
getSpanKeyByName("PRODUCER"),
getSpanKeyByName("CONSUMER_RECEIVE"),
getSpanKeyByName("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 static SpanKey[] getSpanKeys() {
return new SpanKey[] {
SpanKey.SERVER,
SpanKey.HTTP_CLIENT,
SpanKey.RPC_CLIENT,
SpanKey.DB_CLIENT,
SpanKey.ALL_CLIENTS,
SpanKey.PRODUCER,
SpanKey.CONSUMER_RECEIVE,
SpanKey.CONSUMER_PROCESS
};
}

private AgentSpanTestingInstrumenter() {}
Expand Down