diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ClassNames.java similarity index 94% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ClassNames.java index 6baa06f04af2..cbd08f437489 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClassNames.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ClassNames.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.tracer; +package io.opentelemetry.instrumentation.api.instrumenter; import io.opentelemetry.instrumentation.api.cache.Cache; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanNames.java similarity index 97% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanNames.java index dae6f14b235d..ba631c90d2d1 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/SpanNames.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/SpanNames.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.tracer; +package io.opentelemetry.instrumentation.api.instrumenter; import io.opentelemetry.instrumentation.api.cache.Cache; import io.opentelemetry.instrumentation.api.util.ClassAndMethod; diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java index 4bb701296fbd..52172fa654ea 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeSpanNameExtractor.java @@ -5,8 +5,8 @@ package io.opentelemetry.instrumentation.api.instrumenter.code; +import io.opentelemetry.instrumentation.api.instrumenter.ClassNames; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.tracer.ClassNames; import javax.annotation.Nullable; /** diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/AttributeSetter.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/AttributeSetter.java deleted file mode 100644 index d901d0d2d632..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/AttributeSetter.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanBuilder; - -/** - * This helper interface allows setting attributes on both {@link Span} and {@link SpanBuilder}. - * - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} instead. - */ -@Deprecated -@FunctionalInterface -public interface AttributeSetter { - void setAttribute(AttributeKey key, T value); -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java deleted file mode 100644 index 754e45b27c11..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/BaseTracer.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.api.trace.StatusCode; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.context.propagation.TextMapPropagator; -import io.opentelemetry.context.propagation.TextMapSetter; -import io.opentelemetry.instrumentation.api.InstrumentationVersion; -import io.opentelemetry.instrumentation.api.internal.ContextPropagationDebug; -import io.opentelemetry.instrumentation.api.internal.SupportabilityMetrics; -import io.opentelemetry.instrumentation.api.server.ServerSpan; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.UndeclaredThrowableException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; - -/** - * Base class for all instrumentation specific tracer implementations. - * - *

Tracers should not use {@link Span} directly in their public APIs: ideally all lifecycle - * methods (ex. start/end methods) should return/accept {@link Context}. By convention, {@link - * Context} should be passed to all methods as the first parameter. - * - *

The {@link BaseTracer} offers several {@code startSpan()} utility methods for creating bare - * spans without any attributes. If you want to provide some additional attributes on span start - * please consider writing your own specific {@code startSpan()} method in your tracer. - * - *

A {@link Context} returned by any {@code startSpan()} method will always contain a new - * span. If there is a need to suppress span creation {@link #shouldStartSpan(Context, SpanKind)} - * should be called before {@code startSpan()}. - * - *

When constructing {@link Span}s tracers should set all attributes available during - * construction on a {@link SpanBuilder} instead of a {@link Span}. This way {@code SpanProcessor}s - * are able to see those attributes in the {@code onStart()} method and can freely read/modify them. - * - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} instead. - */ -@Deprecated -public abstract class BaseTracer { - private static final SupportabilityMetrics supportability = SupportabilityMetrics.instance(); - - @Nullable - private static final Class COMPLETION_EXCEPTION_CLASS = getCompletionExceptionClass(); - - private final Tracer tracer; - private final ContextPropagators propagators; - - /** - * Instead of using this always pass an OpenTelemetry instance; javaagent tracers should - * explicitly pass {@code GlobalOpenTelemetry.get()} to the constructor. - * - * @deprecated always pass an OpenTelemetry instance. - */ - @Deprecated - protected BaseTracer() { - this(GlobalOpenTelemetry.get()); - } - - protected BaseTracer(OpenTelemetry openTelemetry) { - this.tracer = openTelemetry.getTracer(getInstrumentationName(), getVersion()); - this.propagators = openTelemetry.getPropagators(); - } - - /** - * The name of the instrumentation library, not the name of the instrument*ed* library. The value - * returned by this method should uniquely identify the instrumentation library so that during - * troubleshooting it's possible to pinpoint what tracer produced problematic telemetry. - * - *

In this project we use a convention to encode the version of the instrument*ed* library into - * the instrumentation name, for example {@code io.opentelemetry.apache-httpclient-4.0}. This way, - * if there are different instrumentations for different library versions it's easy to find out - * which instrumentations produced the telemetry data. - * - * @see io.opentelemetry.api.trace.TracerProvider#get(String, String) - */ - protected abstract String getInstrumentationName(); - - /** - * The version of the instrumentation library - defaults to the value of JAR manifest attribute - * {@code Implementation-Version}. - */ - protected String getVersion() { - return InstrumentationVersion.VERSION; - } - - /** - * Returns true if a new span of the {@code proposedKind} should be suppressed. - * - *

If the passed {@code context} contains a {@link SpanKind#SERVER} span the instrumentation - * must not create another {@code SERVER} span. The same is true for a {@link SpanKind#CLIENT} - * span: if one {@code CLIENT} span is already present in the passed {@code context} then another - * one must not be started. - * - * @see #withClientSpan(Context, Span) - * @see #withServerSpan(Context, Span) - */ - public final boolean shouldStartSpan(Context context, SpanKind proposedKind) { - boolean suppressed = false; - switch (proposedKind) { - case CLIENT: - suppressed = ClientSpan.exists(context); - break; - case SERVER: - suppressed = ServerSpan.exists(context); - break; - case CONSUMER: - suppressed = ConsumerSpan.exists(context); - break; - default: - break; - } - if (suppressed) { - supportability.recordSuppressedSpan(proposedKind, getInstrumentationName()); - } - return !suppressed; - } - - /** - * Returns a {@link Context} inheriting from {@code Context.current()} that contains a new span - * with name {@code spanName} and kind {@link SpanKind#INTERNAL}. - */ - public Context startSpan(String spanName) { - return startSpan(spanName, SpanKind.INTERNAL); - } - - /** - * Returns a {@link Context} inheriting from {@code Context.current()} that contains a new span - * with name {@code spanName} and kind {@code kind}. - */ - public Context startSpan(String spanName, SpanKind kind) { - return startSpan(Context.current(), spanName, kind); - } - - /** - * Returns a {@link Context} inheriting from {@code parentContext} that contains a new span with - * name {@code spanName} and kind {@code kind}. - */ - public Context startSpan(Context parentContext, String spanName, SpanKind kind) { - Span span = spanBuilder(parentContext, spanName, kind).startSpan(); - return parentContext.with(span); - } - - /** Returns a {@link SpanBuilder} to create and start a new {@link Span}. */ - protected final SpanBuilder spanBuilder(Context parentContext, String spanName, SpanKind kind) { - return tracer.spanBuilder(spanName).setSpanKind(kind).setParent(parentContext); - } - - /** - * Returns a {@link Context} containing the passed {@code span} marked as the current {@link - * SpanKind#CLIENT} span. - * - * @see #shouldStartSpan(Context, SpanKind) - */ - protected final Context withClientSpan(Context parentContext, Span span) { - return ClientSpan.with(parentContext.with(span), span); - } - - /** - * Returns a {@link Context} containing the passed {@code span} marked as the current {@link - * SpanKind#SERVER} span. - * - * @see #shouldStartSpan(Context, SpanKind) - */ - protected final Context withServerSpan(Context parentContext, Span span) { - return ServerSpan.with(parentContext.with(span), span); - } - - /** - * Returns a {@link Context} containing the passed {@code span} marked as the current {@link - * SpanKind#CONSUMER} span. - * - * @see #shouldStartSpan(Context, SpanKind) - */ - protected final Context withConsumerSpan(Context parentContext, Span span) { - return ConsumerSpan.with(parentContext.with(span), span); - } - - /** Ends the execution of a span stored in the passed {@code context}. */ - public void end(Context context) { - end(context, -1); - } - - /** - * Ends the execution of a span stored in the passed {@code context}. - * - * @param endTimeNanos Explicit nanoseconds timestamp from the epoch. - */ - public void end(Context context, long endTimeNanos) { - Span span = Span.fromContext(context); - if (endTimeNanos > 0) { - span.end(endTimeNanos, TimeUnit.NANOSECONDS); - } else { - span.end(); - } - } - - /** - * Records the {@code throwable} in the span stored in the passed {@code context} and marks the - * end of the span's execution. - * - * @see #onException(Context, Throwable) - * @see #end(Context) - */ - public void endExceptionally(Context context, Throwable throwable) { - endExceptionally(context, throwable, -1); - } - - /** - * Records the {@code throwable} in the span stored in the passed {@code context} and marks the - * end of the span's execution. - * - * @param endTimeNanos Explicit nanoseconds timestamp from the epoch. - * @see #onException(Context, Throwable) - * @see #end(Context, long) - */ - public void endExceptionally(Context context, Throwable throwable, long endTimeNanos) { - onException(context, throwable); - end(context, endTimeNanos); - } - - /** - * Records the {@code throwable} in the span stored in the passed {@code context} and sets the - * span's status to {@link StatusCode#ERROR}. The throwable is unwrapped ({@link - * #unwrapThrowable(Throwable)}) before being added to the span. - */ - public void onException(Context context, Throwable throwable) { - Span span = Span.fromContext(context); - span.setStatus(StatusCode.ERROR); - span.recordException(unwrapThrowable(throwable)); - } - - /** - * Extracts the actual cause by unwrapping passed {@code throwable} from known wrapper exceptions, - * e.g {@link ExecutionException}. - */ - protected Throwable unwrapThrowable(Throwable throwable) { - if (throwable.getCause() != null - && (throwable instanceof ExecutionException - || isInstanceOfCompletionException(throwable) - || throwable instanceof InvocationTargetException - || throwable instanceof UndeclaredThrowableException)) { - return unwrapThrowable(throwable.getCause()); - } - return throwable; - } - - /** - * Extracts a {@link Context} from {@code carrier} using the propagator embedded in this tracer. - * This method can be used to propagate {@link Context} passed from upstream services. - * - * @see TextMapPropagator#extract(Context, Object, TextMapGetter) - */ - public Context extract(C carrier, TextMapGetter getter) { - ContextPropagationDebug.debugContextLeakIfEnabled(); - - Context parent = Context.current(); - if (Span.fromContextOrNull(parent) != null) { - // A span has leaked from another thread. - // We want either span context extracted from the carrier or invalid one. - // We DO NOT want any span context potentially lingering in the current context. - // We reset to the root context, which may not always be appropriate (e.g., a framework added - // an item to the context before we create a span) but it is safer than removing all the - // possible spans that instrumentation may have added and such frameworks as of now do not - // have leaks. - parent = Context.root(); - } - - return propagators.getTextMapPropagator().extract(parent, carrier, getter); - } - - /** - * Injects {@code context} data into {@code carrier} using the propagator embedded in this tracer. - * This method can be used to propagate passed {@code context} to downstream services. - * - * @see TextMapPropagator#inject(Context, Object, TextMapSetter) - */ - public void inject(Context context, C carrier, TextMapSetter setter) { - propagators.getTextMapPropagator().inject(context, carrier, setter); - } - - private static boolean isInstanceOfCompletionException(Throwable error) { - return COMPLETION_EXCEPTION_CLASS != null && COMPLETION_EXCEPTION_CLASS.isInstance(error); - } - - @Nullable - private static Class getCompletionExceptionClass() { - try { - return Class.forName("java.util.concurrent.CompletionException"); - } catch (ClassNotFoundException e) { - // Android level 21 does not support java.util.concurrent.CompletionException - return null; - } - } -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClientSpan.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClientSpan.java deleted file mode 100644 index ccf899ccb02f..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ClientSpan.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -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.internal.SpanKey; -import javax.annotation.Nullable; - -/** - * This class encapsulates the context key for storing the current {@link SpanKind#CLIENT} span in - * the {@link Context}. - * - * @deprecated This class should not be used directly; it's functionality is encapsulated inside the - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.Instrumenter Instrumenter API}. - */ -@Deprecated -public final class ClientSpan { - - /** Returns true when a {@link SpanKind#CLIENT} span is present in the passed {@code context}. */ - public static boolean exists(Context context) { - return fromContextOrNull(context) != null; - } - - /** - * Returns span of type {@link SpanKind#CLIENT} from the given context or {@code null} if not - * found. - */ - @Nullable - public static Span fromContextOrNull(Context context) { - return SpanKey.ALL_CLIENTS.fromContextOrNull(context); - } - - public static Context with(Context context, Span clientSpan) { - return SpanKey.ALL_CLIENTS.storeInContext(context, clientSpan); - } - - private ClientSpan() {} -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ConsumerSpan.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ConsumerSpan.java deleted file mode 100644 index a2adf5f2ed48..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/ConsumerSpan.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -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.internal.SpanKey; -import javax.annotation.Nullable; - -/** - * This class encapsulates the context key for storing the current {@link SpanKind#CONSUMER} span in - * the {@link Context}. - * - * @deprecated This class should not be used directly; it's functionality is encapsulated inside the - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.Instrumenter Instrumenter API}. - */ -@Deprecated -public final class ConsumerSpan { - - /** - * Returns true when a {@link SpanKind#CONSUMER} span is present in the passed {@code context}. - */ - public static boolean exists(Context context) { - return fromContextOrNull(context) != null; - } - - /** - * Returns span of type {@link SpanKind#CONSUMER} from the given context or {@code null} if not - * found. - */ - @Nullable - public static Span fromContextOrNull(Context context) { - return SpanKey.CONSUMER_PROCESS.fromContextOrNull(context); - } - - public static Context with(Context context, Span consumerSpan) { - return SpanKey.CONSUMER_PROCESS.storeInContext(context, consumerSpan); - } - - private ConsumerSpan() {} -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java deleted file mode 100644 index 0bc46b652ee4..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/DatabaseClientTracer.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import static io.opentelemetry.api.trace.SpanKind.CLIENT; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.context.Context; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.net.InetSocketAddress; -import javax.annotation.Nullable; - -/** - * Base class for implementing Tracers for database clients. - * - * @param type of the database connection. - * @param type of the database statement being executed. - * @param type of the database statement after sanitization. - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} and - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.db the database semantic - * convention utilities package} instead. - */ -@Deprecated -public abstract class DatabaseClientTracer - extends BaseTracer { - private static final String DB_QUERY = "DB Query"; - - protected final io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes - netPeerAttributes; - - protected DatabaseClientTracer( - io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) { - this.netPeerAttributes = netPeerAttributes; - } - - protected DatabaseClientTracer( - OpenTelemetry openTelemetry, - io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) { - super(openTelemetry); - this.netPeerAttributes = netPeerAttributes; - } - - public boolean shouldStartSpan(Context parentContext) { - return shouldStartSpan(parentContext, CLIENT); - } - - public Context startSpan(Context parentContext, CONNECTION connection, STATEMENT statement) { - SANITIZEDSTATEMENT sanitizedStatement = sanitizeStatement(statement); - - SpanBuilder span = - spanBuilder(parentContext, spanName(connection, statement, sanitizedStatement), CLIENT) - .setAttribute(SemanticAttributes.DB_SYSTEM, dbSystem(connection)); - - if (connection != null) { - onConnection(span, connection); - setNetSemanticConvention(span, connection); - } - onStatement(span, connection, statement, sanitizedStatement); - - return withClientSpan(parentContext, span.startSpan()); - } - - protected abstract SANITIZEDSTATEMENT sanitizeStatement(STATEMENT statement); - - protected String spanName( - CONNECTION connection, STATEMENT statement, SANITIZEDSTATEMENT sanitizedStatement) { - return conventionSpanName( - dbName(connection), dbOperation(connection, statement, sanitizedStatement), null); - } - - /** - * A helper method for constructing the span name formatting according to DB semantic conventions: - * {@code }. - */ - public static String conventionSpanName( - @Nullable String dbName, @Nullable String operation, @Nullable String table) { - return conventionSpanName(dbName, operation, table, DB_QUERY); - } - - /** - * A helper method for constructing the span name formatting according to DB semantic conventions: - * {@code
}. If {@code dbName} and {@code operation} are not - * provided then {@code defaultValue} is returned. - */ - public static String conventionSpanName( - @Nullable String dbName, - @Nullable String operation, - @Nullable String table, - String defaultValue) { - if (operation == null) { - return dbName == null ? defaultValue : dbName; - } - - StringBuilder name = new StringBuilder(operation); - if (dbName != null || table != null) { - name.append(' '); - } - if (dbName != null) { - name.append(dbName); - if (table != null) { - name.append('.'); - } - } - if (table != null) { - name.append(table); - } - return name.toString(); - } - - protected abstract String dbSystem(CONNECTION connection); - - /** This should be called when the connection is being used, not when it's created. */ - protected void onConnection(SpanBuilder span, CONNECTION connection) { - span.setAttribute(SemanticAttributes.DB_USER, dbUser(connection)); - span.setAttribute(SemanticAttributes.DB_NAME, dbName(connection)); - span.setAttribute(SemanticAttributes.DB_CONNECTION_STRING, dbConnectionString(connection)); - } - - protected String dbUser(CONNECTION connection) { - return null; - } - - protected String dbName(CONNECTION connection) { - return null; - } - - @Nullable - protected String dbConnectionString(CONNECTION connection) { - return null; - } - - protected void setNetSemanticConvention(SpanBuilder span, CONNECTION connection) { - netPeerAttributes.setNetPeer(span, peerAddress(connection)); - } - - @Nullable - protected abstract InetSocketAddress peerAddress(CONNECTION connection); - - protected void onStatement( - SpanBuilder span, - CONNECTION connection, - STATEMENT statement, - SANITIZEDSTATEMENT sanitizedStatement) { - span.setAttribute( - SemanticAttributes.DB_STATEMENT, dbStatement(connection, statement, sanitizedStatement)); - span.setAttribute( - SemanticAttributes.DB_OPERATION, dbOperation(connection, statement, sanitizedStatement)); - } - - protected String dbStatement( - CONNECTION connection, STATEMENT statement, SANITIZEDSTATEMENT sanitizedStatement) { - return null; - } - - protected String dbOperation( - CONNECTION connection, STATEMENT statement, SANITIZEDSTATEMENT sanitizedStatement) { - return null; - } -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientTracer.java deleted file mode 100644 index fa54651df9cb..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpClientTracer.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import static io.opentelemetry.api.trace.SpanKind.CLIENT; -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.api.trace.StatusCode; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.TextMapSetter; -import io.opentelemetry.instrumentation.api.instrumenter.http.HttpStatusConverter; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Base class for implementing Tracers for HTTP clients. - * - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} and - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.http the HTTP semantic - * convention utilities package} instead. - */ -@Deprecated -public abstract class HttpClientTracer extends BaseTracer { - - private static final Logger logger = LoggerFactory.getLogger(HttpClientTracer.class); - - public static final String DEFAULT_SPAN_NAME = "HTTP request"; - - protected static final String USER_AGENT = "User-Agent"; - - protected final io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes - netPeerAttributes; - - protected HttpClientTracer( - io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) { - super(); - this.netPeerAttributes = netPeerAttributes; - } - - protected HttpClientTracer( - OpenTelemetry openTelemetry, - io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) { - super(openTelemetry); - this.netPeerAttributes = netPeerAttributes; - } - - protected abstract String method(REQUEST request); - - @Nullable - protected abstract URI url(REQUEST request) throws URISyntaxException; - - @Nullable - protected String flavor(REQUEST request) { - // This is de facto standard nowadays, so let us use it, unless overridden - return "1.1"; - } - - @Nullable - protected abstract Integer status(RESPONSE response); - - @Nullable - protected abstract String requestHeader(REQUEST request, String name); - - @Nullable - protected abstract String responseHeader(RESPONSE response, String name); - - protected abstract TextMapSetter getSetter(); - - public boolean shouldStartSpan(Context parentContext) { - return shouldStartSpan(parentContext, CLIENT); - } - - public Context startSpan(Context parentContext, REQUEST request, CARRIER carrier) { - return startSpan(parentContext, request, carrier, -1); - } - - public Context startSpan( - SpanKind kind, Context parentContext, REQUEST request, CARRIER carrier, long startTimeNanos) { - Span span = - internalStartSpan( - kind, parentContext, request, spanNameForRequest(request), startTimeNanos); - Context context = withClientSpan(parentContext, span); - inject(context, carrier); - return context; - } - - public Context startSpan( - Context parentContext, REQUEST request, CARRIER carrier, long startTimeNanos) { - return startSpan(SpanKind.CLIENT, parentContext, request, carrier, startTimeNanos); - } - - protected void inject(Context context, CARRIER carrier) { - TextMapSetter setter = getSetter(); - if (setter == null) { - throw new IllegalStateException( - "getSetter() not defined but calling inject(), either getSetter must be implemented or the scope should be setup manually"); - } - inject(context, carrier, setter); - } - - public void end(Context context, RESPONSE response) { - end(context, response, -1); - } - - public void end(Context context, RESPONSE response, long endTimeNanos) { - Span span = Span.fromContext(context); - onResponse(span, response); - super.end(context, endTimeNanos); - } - - public void endExceptionally(Context context, RESPONSE response, Throwable throwable) { - endExceptionally(context, response, throwable, -1); - } - - public void endExceptionally( - Context context, RESPONSE response, Throwable throwable, long endTimeNanos) { - Span span = Span.fromContext(context); - onResponse(span, response); - super.endExceptionally(context, throwable, endTimeNanos); - } - - // TODO (trask) see if we can reduce the number of end..() variants - // see https://github.com/open-telemetry/opentelemetry-java-instrumentation - // /pull/1893#discussion_r542111699 - public void endMaybeExceptionally( - Context context, RESPONSE response, @Nullable Throwable throwable) { - if (throwable != null) { - endExceptionally(context, throwable); - } else { - end(context, response); - } - } - - private Span internalStartSpan( - SpanKind kind, Context parentContext, REQUEST request, String name, long startTimeNanos) { - SpanBuilder spanBuilder = spanBuilder(parentContext, name, kind); - if (startTimeNanos > 0) { - spanBuilder.setStartTimestamp(startTimeNanos, TimeUnit.NANOSECONDS); - } - onRequest(spanBuilder, request); - return spanBuilder.startSpan(); - } - - protected void onRequest(SpanBuilder spanBuilder, REQUEST request) { - onRequest(spanBuilder::setAttribute, request); - } - - /** - * This method should only be used when the request is not yet available when {@link #startSpan} - * is called. Otherwise {@link #onRequest(SpanBuilder, Object)} should be used. - */ - protected void onRequest(Span span, REQUEST request) { - onRequest(span::setAttribute, request); - } - - private void onRequest(AttributeSetter setter, REQUEST request) { - assert setter != null; - if (request != null) { - setter.setAttribute(SemanticAttributes.NET_TRANSPORT, IP_TCP); - setter.setAttribute(SemanticAttributes.HTTP_METHOD, method(request)); - setter.setAttribute(SemanticAttributes.HTTP_USER_AGENT, requestHeader(request, USER_AGENT)); - - setFlavor(setter, request); - setUrl(setter, request); - } - } - - private void setFlavor(AttributeSetter setter, REQUEST request) { - String flavor = flavor(request); - if (flavor == null) { - return; - } - - String httpProtocolPrefix = "HTTP/"; - if (flavor.startsWith(httpProtocolPrefix)) { - flavor = flavor.substring(httpProtocolPrefix.length()); - } - - setter.setAttribute(SemanticAttributes.HTTP_FLAVOR, flavor); - } - - private void setUrl(AttributeSetter setter, REQUEST request) { - try { - URI url = url(request); - if (url != null) { - netPeerAttributes.setNetPeer(setter, url.getHost(), null, url.getPort()); - URI sanitized; - if (url.getUserInfo() != null) { - sanitized = - new URI( - url.getScheme(), - null, - url.getHost(), - url.getPort(), - url.getPath(), - url.getQuery(), - url.getFragment()); - } else { - sanitized = url; - } - setter.setAttribute(SemanticAttributes.HTTP_URL, sanitized.toString()); - } - } catch (Exception e) { - logger.debug("Error tagging url", e); - } - } - - protected void onResponse(Span span, RESPONSE response) { - assert span != null; - if (response != null) { - Integer status = status(response); - if (status != null) { - span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, (long) status); - StatusCode statusCode = HttpStatusConverter.CLIENT.statusFromHttpStatus(status); - if (statusCode != StatusCode.UNSET) { - span.setStatus(statusCode); - } - } - } - } - - protected String spanNameForRequest(REQUEST request) { - if (request == null) { - return DEFAULT_SPAN_NAME; - } - String method = method(request); - return method != null ? "HTTP " + method : DEFAULT_SPAN_NAME; - } -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java deleted file mode 100644 index 24b5cd1bac8f..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracer.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import static io.opentelemetry.api.trace.SpanKind.SERVER; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.api.trace.StatusCode; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.propagation.TextMapGetter; -import io.opentelemetry.instrumentation.api.instrumenter.http.HttpStatusConverter; -import io.opentelemetry.instrumentation.api.server.ServerSpan; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.lang.reflect.Method; -import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; - -// TODO In search for a better home package - -/** - * Base class for implementing Tracers for HTTP servers. It has 3 types that must be specified by - * subclasses: - * - * @param - The specific type for HTTP requests - * @param - The specific type for HTTP responses - * @param - The specific type of HTTP connection, used to get peer address information - * and HTTP flavor. - * @param - Implementation specific storage type for attaching/getting the server context. - * Use Void if your subclass does not have an implementation specific storage need. - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} and - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.http the HTTP semantic - * convention utilities package} instead. - */ -@Deprecated -public abstract class HttpServerTracer extends BaseTracer { - - // the class name is part of the attribute name, so that it will be shaded when used in javaagent - // instrumentation, and won't conflict with usage outside javaagent instrumentation - public static final String CONTEXT_ATTRIBUTE = HttpServerTracer.class.getName() + ".Context"; - - protected static final String USER_AGENT = "User-Agent"; - - protected HttpServerTracer() { - super(); - } - - protected HttpServerTracer(OpenTelemetry openTelemetry) { - super(openTelemetry); - } - - public Context startSpan(REQUEST request, CONNECTION connection, STORAGE storage, Method origin) { - String spanName = SpanNames.fromMethod(origin); - return startSpan(request, connection, storage, spanName); - } - - public Context startSpan( - REQUEST request, CONNECTION connection, STORAGE storage, String spanName) { - return startSpan(request, connection, storage, spanName, -1); - } - - public Context startSpan( - REQUEST request, - CONNECTION connection, - @Nullable STORAGE storage, - String spanName, - long startTimestamp) { - - // not checking if inside of nested SERVER span because of concerns about context leaking - // and so always starting with a clean context here - - // also we can't conditionally start a span in this method, because the caller won't know - // whether to call end() or not on the Span in the returned Context - - Context parentContext = extract(request, getGetter()); - SpanBuilder spanBuilder = spanBuilder(parentContext, spanName, SERVER); - - if (startTimestamp >= 0) { - spanBuilder.setStartTimestamp(startTimestamp, TimeUnit.NANOSECONDS); - } - - onConnection(spanBuilder, connection); - onRequest(spanBuilder, request); - onConnectionAndRequest(spanBuilder, connection, request); - - Context context = withServerSpan(parentContext, spanBuilder.startSpan()); - context = customizeContext(context, request); - attachServerContext(context, storage); - - return context; - } - - /** Override in subclass to customize context that is returned by {@code startSpan}. */ - protected Context customizeContext(Context context, REQUEST request) { - return context; - } - - /** - * Convenience method. Delegates to {@link #end(Context, Object, long)}, passing {@code timestamp} - * value of {@code -1}. - */ - // TODO should end methods remove SPAN attribute from request as well? - public void end(Context context, RESPONSE response) { - end(context, response, -1); - } - - // TODO should end methods remove SPAN attribute from request as well? - public void end(Context context, RESPONSE response, long timestamp) { - Span span = Span.fromContext(context); - setStatus(span, responseStatus(response)); - end(context, timestamp); - } - - /** - * Convenience method. Delegates to {@link #endExceptionally(Context, Throwable, Object)}, passing - * {@code response} value of {@code null}. - */ - @Override - public void endExceptionally(Context context, Throwable throwable) { - endExceptionally(context, throwable, null); - } - - /** - * Convenience method. Delegates to {@link #endExceptionally(Context, Throwable, Object, long)}, - * passing {@code timestamp} value of {@code -1}. - */ - public void endExceptionally(Context context, Throwable throwable, RESPONSE response) { - endExceptionally(context, throwable, response, -1); - } - - /** - * If {@code response} is {@code null}, the {@code http.status_code} will be set to {@code 500} - * and the {@link Span} status will be set to {@link io.opentelemetry.api.trace.StatusCode#ERROR}. - */ - public void endExceptionally( - Context context, Throwable throwable, RESPONSE response, long timestamp) { - onException(context, throwable); - Span span = Span.fromContext(context); - if (response == null) { - setStatus(span, 500); - } else { - setStatus(span, responseStatus(response)); - } - end(context, timestamp); - } - - public Span getServerSpan(STORAGE storage) { - Context attachedContext = getServerContext(storage); - return attachedContext == null ? null : ServerSpan.fromContextOrNull(attachedContext); - } - - /** - * Returns context stored to the given request-response-loop storage by {@link - * #attachServerContext(Context, Object)}. - */ - @Nullable - public abstract Context getServerContext(STORAGE storage); - - protected void onConnection(SpanBuilder spanBuilder, CONNECTION connection) { - // TODO: use NetPeerAttributes here - spanBuilder.setAttribute(SemanticAttributes.NET_PEER_IP, peerHostIp(connection)); - Integer port = peerPort(connection); - // Negative or Zero ports might represent an unset/null value for an int type. Skip setting. - if (port != null && port > 0) { - spanBuilder.setAttribute(SemanticAttributes.NET_PEER_PORT, (long) port); - } - } - - protected void onRequest(SpanBuilder spanBuilder, REQUEST request) { - spanBuilder.setAttribute(SemanticAttributes.HTTP_METHOD, method(request)); - spanBuilder.setAttribute( - SemanticAttributes.HTTP_USER_AGENT, requestHeader(request, USER_AGENT)); - - String url = url(request); - if (url != null) { - // netty instrumentation uses this - spanBuilder.setAttribute(SemanticAttributes.HTTP_URL, url); - } else { - spanBuilder.setAttribute(SemanticAttributes.HTTP_SCHEME, scheme(request)); - spanBuilder.setAttribute(SemanticAttributes.HTTP_HOST, host(request)); - spanBuilder.setAttribute(SemanticAttributes.HTTP_TARGET, target(request)); - } - } - - protected void onConnectionAndRequest( - SpanBuilder spanBuilder, CONNECTION connection, REQUEST request) { - String flavor = flavor(connection, request); - if (flavor != null) { - // remove HTTP/ prefix to comply with semantic conventions - if (flavor.startsWith("HTTP/")) { - flavor = flavor.substring("HTTP/".length()); - } - spanBuilder.setAttribute(SemanticAttributes.HTTP_FLAVOR, flavor); - } - spanBuilder.setAttribute(SemanticAttributes.HTTP_CLIENT_IP, clientIp(request)); - } - - private String clientIp(REQUEST request) { - // try Forwarded - String forwarded = requestHeader(request, "Forwarded"); - if (forwarded != null) { - forwarded = extractForwarded(forwarded); - if (forwarded != null) { - return forwarded; - } - } - - // try X-Forwarded-For - forwarded = requestHeader(request, "X-Forwarded-For"); - if (forwarded != null) { - forwarded = extractForwardedFor(forwarded); - if (forwarded != null) { - return forwarded; - } - } - - return null; - } - - // VisibleForTesting - static String extractForwarded(String forwarded) { - int start = forwarded.toLowerCase().indexOf("for="); - if (start < 0) { - return null; - } - start += 4; // start is now the index after for= - if (start >= forwarded.length() - 1) { // the value after for= must not be empty - return null; - } - return extractIpAddress(forwarded, start); - } - - // VisibleForTesting - static String extractForwardedFor(String forwarded) { - return extractIpAddress(forwarded, 0); - } - - // from https://www.rfc-editor.org/rfc/rfc7239 - // "Note that IPv6 addresses may not be quoted in - // X-Forwarded-For and may not be enclosed by square brackets, but they - // are quoted and enclosed in square brackets in Forwarded" - // and also (applying to Forwarded but not X-Forwarded-For) - // "It is important to note that an IPv6 address and any nodename with - // node-port specified MUST be quoted, since ':' is not an allowed - // character in 'token'." - private static String extractIpAddress(String forwarded, int start) { - if (forwarded.length() == start) { - return null; - } - if (forwarded.charAt(start) == '"') { - return extractIpAddress(forwarded, start + 1); - } - if (forwarded.charAt(start) == '[') { - int end = forwarded.indexOf(']', start + 1); - if (end == -1) { - return null; - } - return forwarded.substring(start + 1, end); - } - boolean inIpv4 = false; - for (int i = start; i < forwarded.length() - 1; i++) { - char c = forwarded.charAt(i); - if (c == '.') { - inIpv4 = true; - } else if (c == ',' || c == ';' || c == '"' || (inIpv4 && c == ':')) { - if (i == start) { // empty string - return null; - } - return forwarded.substring(start, i); - } - } - return forwarded.substring(start); - } - - private static void setStatus(Span span, int status) { - span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, (long) status); - StatusCode statusCode = HttpStatusConverter.SERVER.statusFromHttpStatus(status); - if (statusCode != StatusCode.UNSET) { - span.setStatus(statusCode); - } - } - - @Nullable - protected abstract Integer peerPort(CONNECTION connection); - - @Nullable - protected abstract String peerHostIp(CONNECTION connection); - - protected abstract String flavor(CONNECTION connection, REQUEST request); - - protected abstract TextMapGetter getGetter(); - - // netty still uses this, otherwise should prefer scheme/host/target - @Nullable - protected String url(REQUEST request) { - return null; - } - - protected abstract String scheme(REQUEST request); - - protected abstract String host(REQUEST request); - - protected abstract String target(REQUEST request); - - protected abstract String method(REQUEST request); - - @Nullable - protected abstract String requestHeader(REQUEST request, String name); - - protected abstract int responseStatus(RESPONSE response); - - /** - * Stores given context in the given request-response-loop storage in implementation specific way. - */ - protected abstract void attachServerContext(Context context, STORAGE storage); - - /* - We are making quite simple check by just verifying the presence of schema. - */ - protected boolean isRelativeUrl(String url) { - return !(url.startsWith("http://") || url.startsWith("https://")); - } -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcClientTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcClientTracer.java deleted file mode 100644 index 3d8235c7c494..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcClientTracer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import io.opentelemetry.api.OpenTelemetry; - -/** - * Base class for implementing Tracers for RPC clients. - * - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} and - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.rpc the RPC semantic convention - * utilities package} instead. - */ -@Deprecated -public abstract class RpcClientTracer extends BaseTracer { - protected RpcClientTracer() {} - - protected RpcClientTracer(OpenTelemetry openTelemetry) { - super(openTelemetry); - } - - protected abstract String getRpcSystem(); -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcServerTracer.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcServerTracer.java deleted file mode 100644 index 296a200cd9b4..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/RpcServerTracer.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.context.propagation.TextMapGetter; - -/** - * Base class for implementing Tracers for RPC servers. - * - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} and - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.rpc the RPC semantic convention - * utilities package} instead. - */ -@Deprecated -public abstract class RpcServerTracer extends BaseTracer { - - protected RpcServerTracer() {} - - protected RpcServerTracer(OpenTelemetry openTelemetry) { - super(openTelemetry); - } - - protected abstract TextMapGetter getGetter(); -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributes.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributes.java deleted file mode 100644 index 53785e74a9e9..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributes.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer.net; - -import static java.util.Collections.emptyMap; - -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.instrumentation.api.config.Config; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.util.Map; -import javax.annotation.Nullable; - -/** - * Utility class settings the {@code net.peer.*} attributes. - * - * @deprecated Use {@link io.opentelemetry.instrumentation.api.instrumenter.Instrumenter} and - * {@linkplain io.opentelemetry.instrumentation.api.instrumenter.net the net semantic convention - * utilities package} instead. - */ -@Deprecated -public final class NetPeerAttributes { - - public static final NetPeerAttributes INSTANCE = - new NetPeerAttributes( - Config.get().getMap("otel.instrumentation.common.peer-service-mapping", emptyMap())); - - private final Map peerServiceMapping; - - public NetPeerAttributes() { - this(emptyMap()); - } - - public NetPeerAttributes(Map peerServiceMapping) { - this.peerServiceMapping = peerServiceMapping; - } - - public void setNetPeer(Span span, @Nullable InetSocketAddress remoteConnection) { - setNetPeer(span::setAttribute, remoteConnection); - } - - public void setNetPeer(SpanBuilder span, @Nullable InetSocketAddress remoteConnection) { - setNetPeer(span::setAttribute, remoteConnection); - } - - public void setNetPeer( - io.opentelemetry.instrumentation.api.tracer.AttributeSetter span, - @Nullable InetSocketAddress remoteConnection) { - if (remoteConnection != null) { - InetAddress remoteAddress = remoteConnection.getAddress(); - if (remoteAddress != null) { - setNetPeer( - span, - remoteAddress.getHostName(), - remoteAddress.getHostAddress(), - remoteConnection.getPort()); - } else { - // Failed DNS lookup, the host string is the name. - setNetPeer(span, remoteConnection.getHostString(), null, remoteConnection.getPort()); - } - } - } - - public void setNetPeer(SpanBuilder span, InetAddress remoteAddress, int port) { - setNetPeer( - span::setAttribute, remoteAddress.getHostName(), remoteAddress.getHostAddress(), port); - } - - public void setNetPeer(Span span, String peerName, String peerIp) { - setNetPeer(span::setAttribute, peerName, peerIp, -1); - } - - public void setNetPeer(Span span, String peerName, String peerIp, int port) { - setNetPeer(span::setAttribute, peerName, peerIp, port); - } - - public void setNetPeer( - io.opentelemetry.instrumentation.api.tracer.AttributeSetter span, - @Nullable String peerName, - @Nullable String peerIp, - int port) { - if (peerName != null && !peerName.equals(peerIp)) { - span.setAttribute(SemanticAttributes.NET_PEER_NAME, peerName); - } - if (peerIp != null) { - span.setAttribute(SemanticAttributes.NET_PEER_IP, peerIp); - } - - String peerService = mapToPeerService(peerName); - if (peerService == null) { - peerService = mapToPeerService(peerIp); - } - if (peerService != null) { - span.setAttribute(SemanticAttributes.PEER_SERVICE, peerService); - } - if (port > 0) { - span.setAttribute(SemanticAttributes.NET_PEER_PORT, (long) port); - } - } - - @Nullable - private String mapToPeerService(String endpoint) { - if (endpoint == null) { - return null; - } - - return peerServiceMapping.get(endpoint); - } -} diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/BaseTracerTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/BaseTracerTest.groovy deleted file mode 100644 index e4b45e6af09f..000000000000 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/BaseTracerTest.groovy +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer - -import io.opentelemetry.api.trace.Span -import io.opentelemetry.api.trace.SpanKind -import io.opentelemetry.context.Context -import spock.lang.Shared -import spock.lang.Specification - -// TODO add tests for BaseTracer -class BaseTracerTest extends Specification { - @Shared - def tracer = newTracer() - - def span = Mock(Span) - - @Shared - def root = Context.root() - - @Shared - def existingSpan = Span.getInvalid() - - def newTracer() { - return new BaseTracer() { - @Override - protected String getInstrumentationName() { - return "BaseTracerTest" - } - } - } - - def "test shouldStartSpan"() { - when: - boolean result = tracer.shouldStartSpan(context, kind) - - then: - result == expected - - where: - kind | context | expected - SpanKind.CLIENT | root | true - SpanKind.SERVER | root | true - SpanKind.INTERNAL | root | true - SpanKind.PRODUCER | root | true - SpanKind.CONSUMER | root | true - SpanKind.CLIENT | tracer.withClientSpan(root, existingSpan) | false - SpanKind.SERVER | tracer.withClientSpan(root, existingSpan) | true - SpanKind.INTERNAL | tracer.withClientSpan(root, existingSpan) | true - SpanKind.CONSUMER | tracer.withClientSpan(root, existingSpan) | true - SpanKind.PRODUCER | tracer.withClientSpan(root, existingSpan) | true - SpanKind.SERVER | tracer.withServerSpan(root, existingSpan) | false - SpanKind.INTERNAL | tracer.withServerSpan(root, existingSpan) | true - SpanKind.CONSUMER | tracer.withServerSpan(root, existingSpan) | true - SpanKind.PRODUCER | tracer.withServerSpan(root, existingSpan) | true - SpanKind.CLIENT | tracer.withServerSpan(root, existingSpan) | true - SpanKind.SERVER | tracer.withConsumerSpan(root, existingSpan) | true - SpanKind.INTERNAL | tracer.withConsumerSpan(root, existingSpan) | true - SpanKind.CONSUMER | tracer.withConsumerSpan(root, existingSpan) | false - SpanKind.PRODUCER | tracer.withConsumerSpan(root, existingSpan) | true - SpanKind.CLIENT | tracer.withConsumerSpan(root, existingSpan) | true - } - - - class SomeInnerClass implements Runnable { - void run() { - } - } - - static class SomeNestedClass implements Runnable { - void run() { - } - } -} diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/ClassNamesTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/ClassNamesTest.groovy deleted file mode 100644 index c8718fd5e7e9..000000000000 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/ClassNamesTest.groovy +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer - -import spock.lang.Specification - -class ClassNamesTest extends Specification { - - def "test simpleName"() { - when: - String result = ClassNames.simpleName(clazz) - - then: - result == expected - - where: - clazz | expected - ClassNamesTest | "ClassNamesTest" - ClassNames | "ClassNames" - } -} diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientTracerTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientTracerTest.groovy deleted file mode 100644 index 84b0968662a0..000000000000 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/HttpClientTracerTest.groovy +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer - -import io.opentelemetry.api.trace.StatusCode -import io.opentelemetry.context.propagation.TextMapSetter -import io.opentelemetry.instrumentation.api.instrumenter.http.HttpStatusConverter -import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes -import spock.lang.Shared - -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP - -class HttpClientTracerTest extends BaseTracerTest { - - @Shared - def testUrl = new URI("http://myhost:123/somepath") - - @Shared - def testUrlMapped = new URI("http://dogs.com:123/somepath") - - @Shared - def testUserAgent = "Apache HttpClient" - - def "test onRequest"() { - setup: - def tracer = newTracer() - - when: - tracer.onRequest(span, req) - - then: - if (req) { - 1 * span.setAttribute(SemanticAttributes.NET_TRANSPORT, IP_TCP) - 1 * span.setAttribute(SemanticAttributes.HTTP_METHOD, req.method) - 1 * span.setAttribute(SemanticAttributes.HTTP_URL, "$req.url") - 1 * span.setAttribute(SemanticAttributes.NET_PEER_NAME, req.url.host) - 1 * span.setAttribute(SemanticAttributes.NET_PEER_PORT, req.url.port) - 1 * span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, req["User-Agent"]) - 1 * span.setAttribute(SemanticAttributes.HTTP_FLAVOR, "1.1") - } - 0 * _ - - where: - req << [ - null, - [method: "test-method", url: testUrl, "User-Agent": testUserAgent] - ] - } - - def "test onRequest with mapped peer"() { - setup: - def tracer = newTracer() - def req = [method: "test-method", url: testUrlMapped, "User-Agent": testUserAgent] - - when: - tracer.onRequest(span, req) - - then: - if (req) { - 1 * span.setAttribute(SemanticAttributes.NET_TRANSPORT, IP_TCP) - 1 * span.setAttribute(SemanticAttributes.HTTP_METHOD, req.method) - 1 * span.setAttribute(SemanticAttributes.HTTP_URL, "$req.url") - 1 * span.setAttribute(SemanticAttributes.NET_PEER_NAME, req.url.host) - 1 * span.setAttribute(SemanticAttributes.NET_PEER_PORT, req.url.port) - 1 * span.setAttribute(SemanticAttributes.PEER_SERVICE, "dogsservice") - 1 * span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, req["User-Agent"]) - 1 * span.setAttribute(SemanticAttributes.HTTP_FLAVOR, "1.1") - } - 0 * _ - } - - def "test url handling for #url"() { - setup: - def tracer = newTracer() - - when: - tracer.onRequest(span, req) - - then: - 1 * span.setAttribute(SemanticAttributes.NET_TRANSPORT, IP_TCP) - if (expectedUrl != null) { - 1 * span.setAttribute(SemanticAttributes.HTTP_URL, expectedUrl) - } - 1 * span.setAttribute(SemanticAttributes.HTTP_METHOD, null) - 1 * span.setAttribute(SemanticAttributes.HTTP_FLAVOR, "1.1") - 1 * span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, null) - if (hostname) { - 1 * span.setAttribute(SemanticAttributes.NET_PEER_NAME, hostname) - } - if (port) { - 1 * span.setAttribute(SemanticAttributes.NET_PEER_PORT, port) - } - 0 * _ - - where: - tagQueryString | url | expectedUrl | expectedQuery | expectedFragment | hostname | port - false | null | null | null | null | null | null - false | "" | "" | "" | null | null | null - false | "/path?query" | "/path?query" | "" | null | null | null - false | "https://host:0" | "https://host:0" | "" | null | "host" | null - false | "https://host/path" | "https://host/path" | "" | null | "host" | null - false | "http://host:99/path?query#fragment" | "http://host:99/path?query#fragment" | "" | null | "host" | 99 - false | "https://usr:pswd@host/path" | "https://host/path" | "" | null | "host" | null - - req = [url: url == null ? null : new URI(url)] - } - - def "test onResponse"() { - setup: - def tracer = newTracer() - def statusCode = status != null ? HttpStatusConverter.CLIENT.statusFromHttpStatus(status) : null - - when: - tracer.onResponse(span, resp) - - then: - if (status) { - 1 * span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, status) - } - if (statusCode != null && statusCode != StatusCode.UNSET) { - 1 * span.setStatus(statusCode) - } - 0 * _ - - where: - status | resp - 200 | [status: 200] - 399 | [status: 399] - 400 | [status: 400] - 499 | [status: 499] - 500 | [status: 500] - 500 | [status: 500] - 600 | [status: 600] - null | [status: null] - null | null - } - - @Override - def newTracer() { - def netPeerAttributes = new NetPeerAttributes([ - "1.2.3.4": "catservice", "dogs.com": "dogsservice" - ]) - return new HttpClientTracer(netPeerAttributes) { - - @Override - protected String method(Map m) { - return m.method - } - - @Override - protected URI url(Map m) { - return m.url - } - - @Override - protected Integer status(Map m) { - return m.status - } - - @Override - protected String requestHeader(Map m, String name) { - return m[name] - } - - @Override - protected String responseHeader(Map m, String name) { - return m[name] - } - - @Override - protected TextMapSetter getSetter() { - return null - } - - @Override - protected String getInstrumentationName() { - return "HttpClientTracerTest" - } - } - } -} diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy deleted file mode 100644 index a835a189f9d0..000000000000 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/SpanNamesTest.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer - -import org.spockframework.util.ReflectionUtil -import spock.lang.Specification - -class SpanNamesTest extends Specification { - - def "test fromMethod"() { - when: - String result = SpanNames.fromMethod(method) - - then: - result == expected - - where: - method | expected - ReflectionUtil.getMethodByName(SpanNames, "fromMethod") | "SpanNames.fromMethod" - ReflectionUtil.getMethodByName(String, "length") | "String.length" - } - - def "test fromMethod with class and method ref"() { - when: - String result = SpanNames.fromMethod(clazz, method) - - then: - result == expected - - where: - clazz = SpanNames - method = ReflectionUtil.getMethodByName(SpanNames, "fromMethod") - expected = "SpanNames.fromMethod" - } - - def "test fromMethod with class and method name"() { - when: - String result = SpanNames.fromMethod(clazz, method) - - then: - result == expected - - where: - clazz = SpanNames - method = "test" - expected = "SpanNames.test" - } -} diff --git a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributesTest.groovy b/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributesTest.groovy deleted file mode 100644 index 2f4f4a261781..000000000000 --- a/instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/tracer/net/NetPeerAttributesTest.groovy +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer.net - -import io.opentelemetry.api.trace.Span -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes -import spock.lang.Shared -import spock.lang.Specification - -class NetPeerAttributesTest extends Specification { - - @Shared - def resolvedAddress = new InetSocketAddress("github.com", 999) - - def span = Mock(Span) - - def "test setAttributes"() { - setup: - def utils = new NetPeerAttributes([:]) - - when: - utils.setNetPeer(span, connection) - - then: - if (expectedPeerName) { - 1 * span.setAttribute(SemanticAttributes.NET_PEER_NAME, expectedPeerName) - } - if (expectedPeerIp) { - 1 * span.setAttribute(SemanticAttributes.NET_PEER_IP, expectedPeerIp) - } - 1 * span.setAttribute(SemanticAttributes.NET_PEER_PORT, connection.port) - 0 * _ - - where: - connection | expectedPeerName | expectedPeerIp - new InetSocketAddress("localhost", 888) | "localhost" | "127.0.0.1" - new InetSocketAddress("1.2.1.2", 888) | null | "1.2.1.2" - resolvedAddress | "github.com" | resolvedAddress.address.hostAddress - new InetSocketAddress("bad.address.local", 999) | "bad.address.local" | null - } - - def "test setAttributes with mapped peer"() { - setup: - def utils = new NetPeerAttributes([ - "1.2.3.4": "catservice", "dogs.com": "dogsservice" - ]) - - when: - utils.setNetPeer(span, connection) - - then: - if (expectedPeerService) { - 1 * span.setAttribute(SemanticAttributes.PEER_SERVICE, expectedPeerService) - } else { - 0 * span.setAttribute(SemanticAttributes.PEER_SERVICE, _) - } - - where: - connection | expectedPeerService - new InetSocketAddress("1.2.3.4", 888) | "catservice" - new InetSocketAddress("2.3.4.5", 888) | null - new InetSocketAddress("dogs.com", 999) | "dogsservice" - new InetSocketAddress("github.com", 999) | null - } -} diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracerTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracerTest.java deleted file mode 100644 index a5ac1a1226c7..000000000000 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/tracer/HttpServerTracerTest.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.tracer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -public class HttpServerTracerTest { - @Test - public void extractForwarded() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwarded("for=1.1.1.1")); - } - - @Test - public void extractForwardedIpv6() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwarded("for=\"[1111:1111:1111:1111:1111:1111:1111:1111]\"")); - } - - @Test - public void extractForwardedWithPort() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwarded("for=\"1.1.1.1:2222\"")); - } - - @Test - public void extractForwardedIpv6WithPort() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwarded( - "for=\"[1111:1111:1111:1111:1111:1111:1111:1111]:2222\"")); - } - - @Test - public void extractForwardedCaps() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwarded("For=1.1.1.1")); - } - - @Test - public void extractForwardedMalformed() { - assertNull(HttpServerTracer.extractForwarded("for=;for=1.1.1.1")); - } - - @Test - public void extractForwardedEmpty() { - assertNull(HttpServerTracer.extractForwarded("")); - } - - @Test - public void extractForwardedEmptyValue() { - assertNull(HttpServerTracer.extractForwarded("for=")); - } - - @Test - public void extractForwardedEmptyValueWithSemicolon() { - assertNull(HttpServerTracer.extractForwarded("for=;")); - } - - @Test - public void extractForwardedNoFor() { - assertNull(HttpServerTracer.extractForwarded("by=1.1.1.1;test=1.1.1.1")); - } - - @Test - public void extractForwardedMultiple() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwarded("for=1.1.1.1;for=1.2.3.4")); - } - - @Test - public void extractForwardedMultipleIpV6() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwarded( - "for=\"[1111:1111:1111:1111:1111:1111:1111:1111]\";for=1.2.3.4")); - } - - @Test - public void extractForwardedMultipleWithPort() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwarded("for=\"1.1.1.1:2222\";for=1.2.3.4")); - } - - @Test - public void extractForwardedMultipleIpV6WithPort() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwarded( - "for=\"[1111:1111:1111:1111:1111:1111:1111:1111]:2222\";for=1.2.3.4")); - } - - @Test - public void extractForwardedMixedSplitter() { - assertEquals( - "1.1.1.1", - HttpServerTracer.extractForwarded("test=abcd; by=1.2.3.4, for=1.1.1.1;for=1.2.3.4")); - } - - @Test - public void extractForwardedMixedSplitterIpv6() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwarded( - "test=abcd; by=1.2.3.4, for=\"[1111:1111:1111:1111:1111:1111:1111:1111]\";for=1.2.3.4")); - } - - @Test - public void extractForwardedMixedSplitterWithPort() { - assertEquals( - "1.1.1.1", - HttpServerTracer.extractForwarded( - "test=abcd; by=1.2.3.4, for=\"1.1.1.1:2222\";for=1.2.3.4")); - } - - @Test - public void extractForwardedMixedSplitterIpv6WithPort() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwarded( - "test=abcd; by=1.2.3.4, for=\"[1111:1111:1111:1111:1111:1111:1111:1111]:2222\";for=1.2.3.4")); - } - - @Test - public void extractForwardedFor() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwardedFor("1.1.1.1")); - } - - @Test - public void extractForwardedForIpv6() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor("\"[1111:1111:1111:1111:1111:1111:1111:1111]\"")); - } - - @Test - public void extractForwardedForIpv6Unquoted() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor("[1111:1111:1111:1111:1111:1111:1111:1111]")); - } - - @Test - public void extractForwardedForIpv6Unbracketed() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor("1111:1111:1111:1111:1111:1111:1111:1111")); - } - - @Test - public void extractForwardedForWithPort() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwardedFor("1.1.1.1:2222")); - } - - @Test - public void extractForwardedForIpv6WithPort() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor("\"[1111:1111:1111:1111:1111:1111:1111:1111]:2222\"")); - } - - @Test - public void extractForwardedForIpv6UnquotedWithPort() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor("[1111:1111:1111:1111:1111:1111:1111:1111]:2222")); - } - - @Test - public void extractForwardedForEmpty() { - assertNull(HttpServerTracer.extractForwardedFor("")); - } - - @Test - public void extractForwardedForMultiple() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwardedFor("1.1.1.1,1.2.3.4")); - } - - @Test - public void extractForwardedForMultipleIpv6() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor( - "\"[1111:1111:1111:1111:1111:1111:1111:1111]\",1.2.3.4")); - } - - @Test - public void extractForwardedForMultipleIpv6Unquoted() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor("[1111:1111:1111:1111:1111:1111:1111:1111],1.2.3.4")); - } - - @Test - public void extractForwardedForMultipleIpv6Unbracketed() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor("1111:1111:1111:1111:1111:1111:1111:1111,1.2.3.4")); - } - - @Test - public void extractForwardedForMultipleWithPort() { - assertEquals("1.1.1.1", HttpServerTracer.extractForwardedFor("1.1.1.1:2222,1.2.3.4")); - } - - @Test - public void extractForwardedForMultipleIpv6WithPort() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor( - "\"[1111:1111:1111:1111:1111:1111:1111:1111]:2222\",1.2.3.4")); - } - - @Test - public void extractForwardedForMultipleIpv6UnquotedWithPort() { - assertEquals( - "1111:1111:1111:1111:1111:1111:1111:1111", - HttpServerTracer.extractForwardedFor( - "[1111:1111:1111:1111:1111:1111:1111:1111]:2222,1.2.3.4")); - } -} diff --git a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java index b30434ad9a9a..43f7472e97fc 100644 --- a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java +++ b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java @@ -8,9 +8,9 @@ import com.twitter.finatra.http.contexts.RouteInfo; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.ClassNames; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; -import io.opentelemetry.instrumentation.api.tracer.ClassNames; public final class FinatraSingletons { diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java index f559fffb1482..40dd8c5add36 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/HandlerData.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.grails; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; public class HandlerData { diff --git a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java index 6cd3cd826d32..80bc1768b15f 100644 --- a/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java +++ b/instrumentation/methods/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/methods/MethodSingletons.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import io.opentelemetry.instrumentation.api.util.ClassAndMethod; public final class MethodSingletons { diff --git a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanSingletons.java b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanSingletons.java index ee761c303ac6..53dccd5fc0f3 100644 --- a/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanSingletons.java +++ b/instrumentation/opentelemetry-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/otelannotations/WithSpanSingletons.java @@ -10,7 +10,7 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.api.annotation.support.MethodSpanAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import java.lang.reflect.Method; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesExtractor.java b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesExtractor.java index 95c782a2f0fb..6ed69b97dfa8 100644 --- a/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesExtractor.java +++ b/instrumentation/rediscala-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rediscala/RediscalaAttributesExtractor.java @@ -5,8 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.rediscala; +import io.opentelemetry.instrumentation.api.instrumenter.ClassNames; import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor; -import io.opentelemetry.instrumentation.api.tracer.ClassNames; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Locale; import javax.annotation.Nullable; diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseSingletons.java b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseSingletons.java index c8ad094fdd0c..278a2748f366 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseSingletons.java +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/response/ResponseSingletons.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import io.opentelemetry.instrumentation.api.util.ClassAndMethod; public class ResponseSingletons { diff --git a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseSingletons.java b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseSingletons.java index 83f84e788de2..c05720ed60b4 100644 --- a/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseSingletons.java +++ b/instrumentation/servlet/servlet-javax-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/javax/response/ResponseSingletons.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import io.opentelemetry.instrumentation.api.util.ClassAndMethod; public class ResponseSingletons { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java index 272a85793759..40ded1e90cd7 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/aspects/WithSpanAspect.java @@ -14,7 +14,7 @@ import io.opentelemetry.instrumentation.api.annotation.support.ParameterAttributeNamesExtractor; import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndSupport; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; diff --git a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java index 01d9046891b7..e5ae3f9b5294 100644 --- a/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java +++ b/instrumentation/spring/spring-data-1.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/data/SpringDataSingletons.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import java.lang.reflect.Method; public final class SpringDataSingletons { diff --git a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingSingletons.java b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingSingletons.java index 78fa0cb8c7cd..e328dd3afaee 100644 --- a/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingSingletons.java +++ b/instrumentation/spring/spring-scheduling-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/scheduling/SpringSchedulingSingletons.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import org.springframework.scheduling.support.ScheduledMethodRunnable; public final class SpringSchedulingSingletons { diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java index ae643800f54b..4dc07e8cffbf 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/AdviceUtils.java @@ -8,7 +8,7 @@ import static io.opentelemetry.javaagent.instrumentation.spring.webflux.server.WebfluxSingletons.instrumenter; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.tracer.ClassNames; +import io.opentelemetry.instrumentation.api.instrumenter.ClassNames; import javax.annotation.Nullable; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/WebfluxSpanNameExtractor.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/WebfluxSpanNameExtractor.java index 55d73465f34b..0198df229261 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/WebfluxSpanNameExtractor.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/WebfluxSpanNameExtractor.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.spring.webflux.server; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import org.springframework.web.method.HandlerMethod; public class WebfluxSpanNameExtractor implements SpanNameExtractor { diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java index 3e75809d06aa..cd6242b3c757 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerSpanNameExtractor.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.springwebmvc; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; import java.lang.reflect.Method; import javax.servlet.Servlet; import org.springframework.web.HttpRequestHandler; diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java index 1f71dca5a017..55fbc9944832 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/ModelAndViewAttributesExtractor.java @@ -8,7 +8,7 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.tracer.ClassNames; +import io.opentelemetry.instrumentation.api.instrumenter.ClassNames; import javax.annotation.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.View; diff --git a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java index 66e776d83251..1a6deaca1478 100644 --- a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java +++ b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioSingletons.java @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; public class TwilioSingletons { diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java index 0d21af3ed47a..ef873233f8ae 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHandlerRequest.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.vaadin; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; @AutoValue public abstract class VaadinHandlerRequest { diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java index f7601669656b..f173d79ff99d 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceRequest.java @@ -6,7 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.vaadin; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; @AutoValue public abstract class VaadinServiceRequest { diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java index c3770b8eb7b1..f682afe4b53b 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinSingletons.java @@ -10,7 +10,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.config.ExperimentalConfig; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.tracer.SpanNames; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNames; public class VaadinSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.vaadin-14.2";