Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide non-specd attributes behind experimental flag #2376

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,14 @@
/*
* 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 class CouchbaseConfig {
trask marked this conversation as resolved.
Show resolved Hide resolved
public static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
Config.get()
.getBooleanProperty("otel.instrumentation.couchbase.experimental-span-attributes", false);
}
Expand Up @@ -57,8 +57,9 @@ public static void addOperationIdToSpan(@Advice.Argument(0) CouchbaseRequest req
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());
}
}
}
}
Expand Down
Expand Up @@ -79,7 +79,9 @@ public static void addNetworkTagsToSpan(
}
}

span.setAttribute("couchbase.local.address", localSocket);
if (CouchbaseConfig.CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) {
span.setAttribute("couchbase.local.address", localSocket);
}
}
}
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
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;
Expand All @@ -27,6 +28,10 @@

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());
}
Expand Down Expand Up @@ -139,7 +144,9 @@ public void onHalfClose() {
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;
Expand Down
Expand Up @@ -95,7 +95,9 @@ public static void stopSpan(@Advice.This AsyncResponse asyncResponse) {
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);
}
}
Expand Down
@@ -0,0 +1,15 @@
/*
* 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 class JaxrsConfig {

public static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
Config.get()
.getBooleanProperty("otel.instrumentation.jaxrs.experimental-span-attributes", false);
}
Expand Up @@ -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"
}
Expand Up @@ -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"
}
Expand Up @@ -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"
}
Expand Up @@ -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"
}
3 changes: 3 additions & 0 deletions instrumentation/jsp-2.3/javaagent/jsp-2.3-javaagent.gradle
Expand Up @@ -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"
}
Expand Up @@ -7,6 +7,7 @@

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;
Expand All @@ -18,6 +19,11 @@
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() {
Expand All @@ -31,7 +37,7 @@ public String spanNameOnCompile(JspCompilationContext jspCompilationContext) {
}

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) {
Expand All @@ -52,6 +58,9 @@ public String spanNameOnRender(HttpServletRequest req) {
}

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);
Expand Down
Expand Up @@ -9,14 +9,22 @@

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() {
Expand All @@ -29,14 +37,14 @@ public static KubernetesClientTracer tracer() {
*/
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()
Expand Down
Expand Up @@ -16,12 +16,17 @@
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(
Expand All @@ -37,8 +42,10 @@ public static void afterCommand(
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);
Expand Down
Expand Up @@ -9,6 +9,7 @@

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;

Expand All @@ -24,6 +25,10 @@
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) {
Expand All @@ -33,8 +38,10 @@ public LettuceAsyncBiFunction(Context context) {
@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);
Expand Down
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -19,6 +20,10 @@

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;
Expand All @@ -34,9 +39,11 @@ public FluxOnSubscribeConsumer getOnSubscribeConsumer() {
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);
Expand Down
Expand Up @@ -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"
}