Hide non-specd attributes behind experimental flag (#2376)
This commit is contained in:
parent
e0bd17aca9
commit
b4c8354b56
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.couchbase.v2_6;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
|
||||
public final class CouchbaseConfig {
|
||||
|
||||
public static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.couchbase.experimental-span-attributes", false);
|
||||
|
||||
private CouchbaseConfig() {}
|
||||
}
|
|
@ -57,8 +57,9 @@ public class CouchbaseCoreInstrumentation implements TypeInstrumentation {
|
|||
if (span == null) {
|
||||
span = parentSpan;
|
||||
contextStore.put(request, span);
|
||||
|
||||
span.setAttribute("couchbase.operation_id", request.operationId());
|
||||
if (CouchbaseConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("couchbase.operation_id", request.operationId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,9 @@ public class CouchbaseNetworkInstrumentation implements TypeInstrumentation {
|
|||
}
|
||||
}
|
||||
|
||||
span.setAttribute("couchbase.local.address", localSocket);
|
||||
if (CouchbaseConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("couchbase.local.address", localSocket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import io.opentelemetry.api.trace.Span;
|
|||
import io.opentelemetry.api.trace.Tracer;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.grpc.v1_5.common.GrpcHelper;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -27,6 +28,10 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
|
||||
public class TracingServerInterceptor implements ServerInterceptor {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.grpc.experimental-span-attributes", false);
|
||||
|
||||
public static ServerInterceptor newInterceptor() {
|
||||
return newInterceptor(new GrpcServerTracer());
|
||||
}
|
||||
|
@ -139,7 +144,9 @@ public class TracingServerInterceptor implements ServerInterceptor {
|
|||
public void onCancel() {
|
||||
try (Scope ignored = span.makeCurrent()) {
|
||||
delegate().onCancel();
|
||||
span.setAttribute("grpc.canceled", true);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("grpc.canceled", true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
tracer.endExceptionally(span, e);
|
||||
throw e;
|
||||
|
|
|
@ -95,7 +95,9 @@ public class JaxRsAsyncResponseInstrumentation implements TypeInstrumentation {
|
|||
Span span = contextStore.get(asyncResponse);
|
||||
if (span != null) {
|
||||
contextStore.put(asyncResponse, null);
|
||||
span.setAttribute("jaxrs.canceled", true);
|
||||
if (JaxrsConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("jaxrs.canceled", true);
|
||||
}
|
||||
tracer().end(span);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0;
|
||||
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
|
||||
public final class JaxrsConfig {
|
||||
|
||||
public static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.jaxrs.experimental-span-attributes", false);
|
||||
|
||||
private JaxrsConfig() {}
|
||||
}
|
|
@ -24,4 +24,9 @@ dependencies {
|
|||
|
||||
testLibrary group: 'org.apache.cxf', name: 'cxf-rt-transports-http-jetty', version: '3.2.0'
|
||||
testLibrary group: 'org.apache.cxf', name: 'cxf-rt-ws-policy', version: '3.2.0'
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true"
|
||||
}
|
||||
|
|
|
@ -30,3 +30,8 @@ dependencies {
|
|||
test {
|
||||
systemProperty 'testLatestDeps', testLatestDeps
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true"
|
||||
}
|
||||
|
|
|
@ -45,3 +45,8 @@ dependencies {
|
|||
test {
|
||||
systemProperty 'testLatestDeps', testLatestDeps
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true"
|
||||
}
|
||||
|
|
|
@ -49,3 +49,8 @@ if (findProperty('testLatestDeps')) {
|
|||
testImplementation.exclude group: 'org.jboss.resteasy', module: 'resteasy-jaxrs'
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs "-Dotel.instrumentation.jaxrs.experimental-span-attributes=true"
|
||||
}
|
||||
|
|
|
@ -40,4 +40,7 @@ tasks.withType(Test) {
|
|||
// JarScanFilter did not exist in the tomcat 7 api
|
||||
jvmArgs '-Dorg.apache.catalina.startup.ContextConfig.jarsToSkip=*'
|
||||
jvmArgs '-Dorg.apache.catalina.startup.TldConfig.jarsToSkip=*'
|
||||
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs "-Dotel.instrumentation.jsp.experimental-span-attributes=true"
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.instrumentation.jsp;
|
|||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
@ -18,6 +19,11 @@ import org.apache.jasper.compiler.Compiler;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JspTracer extends BaseTracer {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.jsp.experimental-span-attributes", false);
|
||||
|
||||
private static final JspTracer TRACER = new JspTracer();
|
||||
|
||||
public static JspTracer tracer() {
|
||||
|
@ -31,7 +37,7 @@ public class JspTracer extends BaseTracer {
|
|||
}
|
||||
|
||||
public void onCompile(Context context, JspCompilationContext jspCompilationContext) {
|
||||
if (jspCompilationContext != null) {
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES && jspCompilationContext != null) {
|
||||
Span span = Span.fromContext(context);
|
||||
Compiler compiler = jspCompilationContext.getCompiler();
|
||||
if (compiler != null) {
|
||||
|
@ -52,6 +58,9 @@ public class JspTracer extends BaseTracer {
|
|||
}
|
||||
|
||||
public void onRender(Context context, HttpServletRequest req) {
|
||||
if (!CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
return;
|
||||
}
|
||||
Span span = Span.fromContext(context);
|
||||
|
||||
Object forwardOrigin = req.getAttribute(RequestDispatcher.FORWARD_SERVLET_PATH);
|
||||
|
|
|
@ -9,14 +9,22 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT;
|
|||
|
||||
import io.opentelemetry.api.GlobalOpenTelemetry;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanBuilder;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.propagation.TextMapSetter;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
|
||||
import java.net.URI;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class KubernetesClientTracer extends HttpClientTracer<Request, Request, Response> {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty(
|
||||
"otel.instrumentation.kubernetes-client.experimental-span-attributes", false);
|
||||
|
||||
private static final KubernetesClientTracer TRACER = new KubernetesClientTracer();
|
||||
|
||||
public static KubernetesClientTracer tracer() {
|
||||
|
@ -29,14 +37,14 @@ public class KubernetesClientTracer extends HttpClientTracer<Request, Request, R
|
|||
*/
|
||||
public Context startSpan(Context parentContext, Request request) {
|
||||
KubernetesRequestDigest digest = KubernetesRequestDigest.parse(request);
|
||||
Span span =
|
||||
tracer
|
||||
.spanBuilder(digest.toString())
|
||||
.setSpanKind(CLIENT)
|
||||
.setParent(parentContext)
|
||||
.setAttribute("namespace", digest.getResourceMeta().getNamespace())
|
||||
.setAttribute("name", digest.getResourceMeta().getName())
|
||||
.startSpan();
|
||||
SpanBuilder spanBuilder =
|
||||
tracer.spanBuilder(digest.toString()).setSpanKind(CLIENT).setParent(parentContext);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
spanBuilder
|
||||
.setAttribute("kubernetes-client.namespace", digest.getResourceMeta().getNamespace())
|
||||
.setAttribute("kubernetes-client.name", digest.getResourceMeta().getName());
|
||||
}
|
||||
Span span = spanBuilder.startSpan();
|
||||
Context context = withClientSpan(parentContext, span);
|
||||
GlobalOpenTelemetry.getPropagators()
|
||||
.getTextMapPropagator()
|
||||
|
|
|
@ -16,12 +16,17 @@ import com.lambdaworks.redis.protocol.ProtocolKeyword;
|
|||
import com.lambdaworks.redis.protocol.RedisCommand;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
public final class InstrumentationPoints {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.lettuce.experimental-span-attributes", false);
|
||||
|
||||
private static final Set<CommandType> NON_INSTRUMENTING_COMMANDS = EnumSet.of(SHUTDOWN, DEBUG);
|
||||
|
||||
public static void afterCommand(
|
||||
|
@ -37,8 +42,10 @@ public final class InstrumentationPoints {
|
|||
if (ex == null) {
|
||||
tracer().end(context);
|
||||
} else if (ex instanceof CancellationException) {
|
||||
Span span = Span.fromContext(context);
|
||||
span.setAttribute("lettuce.command.cancelled", true);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
Span span = Span.fromContext(context);
|
||||
span.setAttribute("lettuce.command.cancelled", true);
|
||||
}
|
||||
tracer().end(context);
|
||||
} else {
|
||||
tracer().endExceptionally(context, ex);
|
||||
|
|
|
@ -9,6 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.lettuce.v5_0.LettuceDat
|
|||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
|
@ -24,6 +25,10 @@ import java.util.function.BiFunction;
|
|||
public class LettuceAsyncBiFunction<T, U extends Throwable, R>
|
||||
implements BiFunction<T, Throwable, R> {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.lettuce.experimental-span-attributes", false);
|
||||
|
||||
private final Context context;
|
||||
|
||||
public LettuceAsyncBiFunction(Context context) {
|
||||
|
@ -33,8 +38,10 @@ public class LettuceAsyncBiFunction<T, U extends Throwable, R>
|
|||
@Override
|
||||
public R apply(T t, Throwable throwable) {
|
||||
if (throwable instanceof CancellationException) {
|
||||
Span span = Span.fromContext(context);
|
||||
span.setAttribute("lettuce.command.cancelled", true);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
Span span = Span.fromContext(context);
|
||||
span.setAttribute("lettuce.command.cancelled", true);
|
||||
}
|
||||
tracer().end(context);
|
||||
} else {
|
||||
tracer().endExceptionally(context, throwable);
|
||||
|
|
|
@ -10,6 +10,7 @@ import static io.opentelemetry.javaagent.instrumentation.lettuce.v5_0.LettuceDat
|
|||
import io.lettuce.core.protocol.RedisCommand;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import java.util.function.Consumer;
|
||||
import org.reactivestreams.Subscription;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -19,6 +20,10 @@ import reactor.core.publisher.SignalType;
|
|||
|
||||
public class LettuceFluxTerminationRunnable implements Consumer<Signal<?>>, Runnable {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.lettuce.experimental-span-attributes", false);
|
||||
|
||||
private Context context;
|
||||
private int numResults;
|
||||
private final FluxOnSubscribeConsumer onSubscribeConsumer;
|
||||
|
@ -34,9 +39,11 @@ public class LettuceFluxTerminationRunnable implements Consumer<Signal<?>>, Runn
|
|||
private void finishSpan(boolean isCommandCancelled, Throwable throwable) {
|
||||
if (context != null) {
|
||||
Span span = Span.fromContext(context);
|
||||
span.setAttribute("lettuce.command.results.count", numResults);
|
||||
if (isCommandCancelled) {
|
||||
span.setAttribute("lettuce.command.cancelled", true);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("lettuce.command.results.count", numResults);
|
||||
if (isCommandCancelled) {
|
||||
span.setAttribute("lettuce.command.cancelled", true);
|
||||
}
|
||||
}
|
||||
if (throwable == null) {
|
||||
tracer().end(span);
|
||||
|
|
|
@ -22,3 +22,8 @@ configurations.testRuntime {
|
|||
force group: 'com.rabbitmq', name: 'amqp-client', version: '2.7.0'
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs "-Dotel.instrumentation.rabbitmq.experimental-span-attributes=true"
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.rabbitmq.client.GetResponse;
|
|||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.SpanBuilder;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
|
||||
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils;
|
||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
||||
|
@ -27,6 +28,10 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class RabbitTracer extends BaseTracer {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.rabbitmq.experimental-span-attributes", false);
|
||||
|
||||
private static final RabbitTracer TRACER = new RabbitTracer();
|
||||
|
||||
public static RabbitTracer tracer() {
|
||||
|
@ -60,8 +65,9 @@ public class RabbitTracer extends BaseTracer {
|
|||
spanBuilder.setAttribute(
|
||||
SemanticAttributes.MESSAGING_DESTINATION,
|
||||
normalizeExchangeName(response.getEnvelope().getExchange()));
|
||||
spanBuilder.setAttribute(
|
||||
"messaging.rabbitmq.routing_key", response.getEnvelope().getRoutingKey());
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
spanBuilder.setAttribute("rabbitmq.routing_key", response.getEnvelope().getRoutingKey());
|
||||
}
|
||||
spanBuilder.setAttribute(
|
||||
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES,
|
||||
(long) response.getBody().length);
|
||||
|
@ -92,7 +98,7 @@ public class RabbitTracer extends BaseTracer {
|
|||
span.setAttribute(
|
||||
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES, (long) body.length);
|
||||
}
|
||||
if (properties.getTimestamp() != null) {
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES && properties.getTimestamp() != null) {
|
||||
// this will be set if the sender sets the timestamp,
|
||||
// or if a plugin is installed on the rabbitmq broker
|
||||
long produceTime = properties.getTimestamp().getTime();
|
||||
|
@ -111,9 +117,11 @@ public class RabbitTracer extends BaseTracer {
|
|||
? "<all>"
|
||||
: routingKey.startsWith("amq.gen-") ? "<generated>" : routingKey;
|
||||
span.updateName(exchangeName + " -> " + routing + " send");
|
||||
span.setAttribute("rabbitmq.command", "basic.publish");
|
||||
if (routingKey != null && !routingKey.isEmpty()) {
|
||||
span.setAttribute("messaging.rabbitmq.routing_key", routingKey);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("rabbitmq.command", "basic.publish");
|
||||
if (routingKey != null && !routingKey.isEmpty()) {
|
||||
span.setAttribute("rabbitmq.routing_key", routingKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,8 +130,10 @@ public class RabbitTracer extends BaseTracer {
|
|||
}
|
||||
|
||||
public void onGet(SpanBuilder span, String queue) {
|
||||
span.setAttribute("rabbitmq.command", "basic.get");
|
||||
span.setAttribute("rabbitmq.queue", queue);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("rabbitmq.command", "basic.get");
|
||||
span.setAttribute("rabbitmq.queue", queue);
|
||||
}
|
||||
}
|
||||
|
||||
public String spanNameOnDeliver(String queue) {
|
||||
|
@ -137,14 +147,18 @@ public class RabbitTracer extends BaseTracer {
|
|||
}
|
||||
|
||||
public void onDeliver(Span span, Envelope envelope) {
|
||||
span.setAttribute("rabbitmq.command", "basic.deliver");
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("rabbitmq.command", "basic.deliver");
|
||||
}
|
||||
|
||||
if (envelope != null) {
|
||||
String exchange = envelope.getExchange();
|
||||
span.setAttribute(SemanticAttributes.MESSAGING_DESTINATION, normalizeExchangeName(exchange));
|
||||
String routingKey = envelope.getRoutingKey();
|
||||
if (routingKey != null && !routingKey.isEmpty()) {
|
||||
span.setAttribute("messaging.rabbitmq.routing_key", routingKey);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
String routingKey = envelope.getRoutingKey();
|
||||
if (routingKey != null && !routingKey.isEmpty()) {
|
||||
span.setAttribute("rabbitmq.routing_key", routingKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +173,9 @@ public class RabbitTracer extends BaseTracer {
|
|||
if (!name.equals("basic.publish")) {
|
||||
span.updateName(name);
|
||||
}
|
||||
span.setAttribute("rabbitmq.command", name);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("rabbitmq.command", name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -364,7 +364,7 @@ class RabbitMQTest extends AgentInstrumentationSpecification {
|
|||
"${SemanticAttributes.MESSAGING_DESTINATION.key}" exchange
|
||||
"${SemanticAttributes.MESSAGING_DESTINATION_KIND.key}" "queue"
|
||||
//TODO add to SemanticAttributes
|
||||
"messaging.rabbitmq.routing_key" { it == null || it == routingKey || it.startsWith("amq.gen-") }
|
||||
"rabbitmq.routing_key" { it == null || it == routingKey || it.startsWith("amq.gen-") }
|
||||
if (operation != null && operation != "send") {
|
||||
"${SemanticAttributes.MESSAGING_OPERATION.key}" operation
|
||||
}
|
||||
|
|
|
@ -8,12 +8,17 @@ package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;
|
|||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.api.trace.StatusCode;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.servlet.ServletHttpServerTracer;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class Servlet3HttpServerTracer extends ServletHttpServerTracer<HttpServletResponse> {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.servlet.experimental-span-attributes", false);
|
||||
|
||||
private static final Servlet3HttpServerTracer TRACER = new Servlet3HttpServerTracer();
|
||||
|
||||
public static Servlet3HttpServerTracer tracer() {
|
||||
|
@ -43,7 +48,9 @@ public class Servlet3HttpServerTracer extends ServletHttpServerTracer<HttpServle
|
|||
public void onTimeout(Context context, long timeout) {
|
||||
Span span = Span.fromContext(context);
|
||||
span.setStatus(StatusCode.ERROR);
|
||||
span.setAttribute("servlet.timeout", timeout);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute("servlet.timeout", timeout);
|
||||
}
|
||||
span.end();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,16 +9,22 @@ import static io.opentelemetry.javaagent.instrumentation.spymemcached.MemcacheCl
|
|||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import net.spy.memcached.MemcachedConnection;
|
||||
|
||||
public abstract class CompletionListener<T> {
|
||||
|
||||
static final String DB_COMMAND_CANCELLED = "lettuce.command.cancelled";
|
||||
static final String MEMCACHED_RESULT = "memcached.result";
|
||||
static final String HIT = "hit";
|
||||
static final String MISS = "miss";
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty(
|
||||
"otel.instrumentation.spymemcached.experimental-span-attributes", false);
|
||||
|
||||
private static final String DB_COMMAND_CANCELLED = "spymemcached.command.cancelled";
|
||||
private static final String MEMCACHED_RESULT = "spymemcached.result";
|
||||
private static final String HIT = "hit";
|
||||
private static final String MISS = "miss";
|
||||
|
||||
private final Context context;
|
||||
|
||||
|
@ -32,12 +38,16 @@ public abstract class CompletionListener<T> {
|
|||
try {
|
||||
processResult(span, future);
|
||||
} catch (CancellationException e) {
|
||||
span.setAttribute(DB_COMMAND_CANCELLED, true);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute(DB_COMMAND_CANCELLED, true);
|
||||
}
|
||||
} catch (ExecutionException e) {
|
||||
if (e.getCause() instanceof CancellationException) {
|
||||
// Looks like underlying OperationFuture wraps CancellationException into
|
||||
// ExecutionException
|
||||
span.setAttribute(DB_COMMAND_CANCELLED, true);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute(DB_COMMAND_CANCELLED, true);
|
||||
}
|
||||
} else {
|
||||
tracer().endExceptionally(span, e);
|
||||
}
|
||||
|
@ -61,6 +71,8 @@ public abstract class CompletionListener<T> {
|
|||
throws ExecutionException, InterruptedException;
|
||||
|
||||
protected void setResultTag(Span span, boolean hit) {
|
||||
span.setAttribute(MEMCACHED_RESULT, hit ? HIT : MISS);
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
span.setAttribute(MEMCACHED_RESULT, hit ? HIT : MISS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.twilio.rest.api.v2010.account.Call;
|
|||
import com.twilio.rest.api.v2010.account.Message;
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -20,6 +21,10 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
public class TwilioTracer extends BaseTracer {
|
||||
|
||||
private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
|
||||
Config.get()
|
||||
.getBooleanProperty("otel.instrumentation.twilio.experimental-span-attributes", false);
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TwilioTracer.class);
|
||||
|
||||
public static final TwilioTracer TRACER = new TwilioTracer();
|
||||
|
@ -67,36 +72,38 @@ public class TwilioTracer extends BaseTracer {
|
|||
return;
|
||||
}
|
||||
|
||||
// Provide helpful metadata for some of the more common response types
|
||||
span.setAttribute("twilio.type", result.getClass().getCanonicalName());
|
||||
if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
|
||||
// Provide helpful metadata for some of the more common response types
|
||||
span.setAttribute("twilio.type", result.getClass().getCanonicalName());
|
||||
|
||||
// Instrument the most popular resource types directly
|
||||
if (result instanceof Message) {
|
||||
Message message = (Message) result;
|
||||
span.setAttribute("twilio.account", message.getAccountSid());
|
||||
span.setAttribute("twilio.sid", message.getSid());
|
||||
Message.Status status = message.getStatus();
|
||||
if (status != null) {
|
||||
span.setAttribute("twilio.status", status.toString());
|
||||
// Instrument the most popular resource types directly
|
||||
if (result instanceof Message) {
|
||||
Message message = (Message) result;
|
||||
span.setAttribute("twilio.account", message.getAccountSid());
|
||||
span.setAttribute("twilio.sid", message.getSid());
|
||||
Message.Status status = message.getStatus();
|
||||
if (status != null) {
|
||||
span.setAttribute("twilio.status", status.toString());
|
||||
}
|
||||
} else if (result instanceof Call) {
|
||||
Call call = (Call) result;
|
||||
span.setAttribute("twilio.account", call.getAccountSid());
|
||||
span.setAttribute("twilio.sid", call.getSid());
|
||||
span.setAttribute("twilio.parentSid", call.getParentCallSid());
|
||||
Call.Status status = call.getStatus();
|
||||
if (status != null) {
|
||||
span.setAttribute("twilio.status", status.toString());
|
||||
}
|
||||
} else {
|
||||
// Use reflection to gather insight from other types; note that Twilio requests take close
|
||||
// to
|
||||
// 1 second, so the added hit from reflection here is relatively minimal in the grand scheme
|
||||
// of things
|
||||
setTagIfPresent(span, result, "twilio.sid", "getSid");
|
||||
setTagIfPresent(span, result, "twilio.account", "getAccountSid");
|
||||
setTagIfPresent(span, result, "twilio.status", "getStatus");
|
||||
}
|
||||
} else if (result instanceof Call) {
|
||||
Call call = (Call) result;
|
||||
span.setAttribute("twilio.account", call.getAccountSid());
|
||||
span.setAttribute("twilio.sid", call.getSid());
|
||||
span.setAttribute("twilio.parentSid", call.getParentCallSid());
|
||||
Call.Status status = call.getStatus();
|
||||
if (status != null) {
|
||||
span.setAttribute("twilio.status", status.toString());
|
||||
}
|
||||
} else {
|
||||
// Use reflection to gather insight from other types; note that Twilio requests take close to
|
||||
// 1 second, so the added hit from reflection here is relatively minimal in the grand scheme
|
||||
// of things
|
||||
setTagIfPresent(span, result, "twilio.sid", "getSid");
|
||||
setTagIfPresent(span, result, "twilio.account", "getAccountSid");
|
||||
setTagIfPresent(span, result, "twilio.status", "getStatus");
|
||||
}
|
||||
|
||||
super.end(span);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,3 +17,8 @@ dependencies {
|
|||
|
||||
latestDepTestLibrary group: 'com.twilio.sdk', name: 'twilio', version: '7.+'
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
// TODO run tests both with and without experimental span attributes
|
||||
jvmArgs "-Dotel.instrumentation.twilio.experimental-span-attributes=true"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue