diff --git a/instrumentation/apache-camel-2.20/javaagent/apache-camel-2.20-javaagent.gradle b/instrumentation/apache-camel-2.20/javaagent/apache-camel-2.20-javaagent.gradle index 90469ebfd9..6cf54815b2 100644 --- a/instrumentation/apache-camel-2.20/javaagent/apache-camel-2.20-javaagent.gradle +++ b/instrumentation/apache-camel-2.20/javaagent/apache-camel-2.20-javaagent.gradle @@ -52,3 +52,9 @@ dependencies { latestDepTestLibrary group: 'org.apache.camel', name: 'camel-undertow', version: '2.+' latestDepTestLibrary group: 'org.apache.camel', name: 'camel-aws', version: '2.+' } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.apache-camel.experimental-span-attributes=true" + jvmArgs "-Dotel.instrumentation.aws-sdk.experimental-span-attributes=true" +} diff --git a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/BaseSpanDecorator.java b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/BaseSpanDecorator.java index 978436a0b2..457d879ed9 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/BaseSpanDecorator.java +++ b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/BaseSpanDecorator.java @@ -26,6 +26,7 @@ package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.StatusCode; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection; import io.opentelemetry.javaagent.instrumentation.apachecamel.SpanDecorator; import java.util.Collections; @@ -39,6 +40,11 @@ import org.apache.camel.util.URISupport; /** An abstract base implementation of the {@link SpanDecorator} interface. */ class BaseSpanDecorator implements SpanDecorator { + static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty( + "otel.instrumentation.apache-camel.experimental-span-attributes", false); + static final String DEFAULT_OPERATION_NAME = "CamelOperation"; /** @@ -92,7 +98,9 @@ class BaseSpanDecorator implements SpanDecorator { @Override public void pre(Span span, Exchange exchange, Endpoint endpoint, CamelDirection camelDirection) { - span.setAttribute("apache-camel.uri", URISupport.sanitizeUri(endpoint.getEndpointUri())); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("apache-camel.uri", URISupport.sanitizeUri(endpoint.getEndpointUri())); + } } @Override diff --git a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/KafkaSpanDecorator.java b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/KafkaSpanDecorator.java index 159a00d565..97109067b3 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/KafkaSpanDecorator.java +++ b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/KafkaSpanDecorator.java @@ -64,19 +64,21 @@ class KafkaSpanDecorator extends MessagingSpanDecorator { span.setAttribute(SemanticAttributes.MESSAGING_KAFKA_PARTITION, partition); } - String partitionKey = (String) exchange.getIn().getHeader(PARTITION_KEY); - if (partitionKey != null) { - span.setAttribute("apache-camel.kafka.partitionKey", partitionKey); - } + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + String partitionKey = (String) exchange.getIn().getHeader(PARTITION_KEY); + if (partitionKey != null) { + span.setAttribute("apache-camel.kafka.partitionKey", partitionKey); + } - String key = (String) exchange.getIn().getHeader(KEY); - if (key != null) { - span.setAttribute("apache-camel.kafka.key", key); - } + String key = (String) exchange.getIn().getHeader(KEY); + if (key != null) { + span.setAttribute("apache-camel.kafka.key", key); + } - String offset = getValue(exchange, OFFSET, Long.class); - if (offset != null) { - span.setAttribute("apache-camel.kafka.offset", offset); + String offset = getValue(exchange, OFFSET, Long.class); + if (offset != null) { + span.setAttribute("apache-camel.kafka.offset", offset); + } } } diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/aws-sdk-1.11-javaagent.gradle b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/aws-sdk-1.11-javaagent.gradle index 974ea6e3ac..b59657e650 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/aws-sdk-1.11-javaagent.gradle +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/aws-sdk-1.11-javaagent.gradle @@ -84,3 +84,8 @@ test { if (!testLatestDeps) { test.dependsOn test_before_1_11_106 } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.aws-sdk.experimental-span-attributes=true" +} diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/AwsSdkClientTracer.java b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/AwsSdkClientTracer.java index 14ffda4974..172e3598ed 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/AwsSdkClientTracer.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/awssdk/v1_11/AwsSdkClientTracer.java @@ -14,12 +14,17 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.extension.aws.AwsXrayPropagator; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer; import java.net.URI; import java.util.concurrent.ConcurrentHashMap; public class AwsSdkClientTracer extends HttpClientTracer, Request, Response> { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty("otel.instrumentation.aws-sdk.experimental-span-attributes", false); + static final String COMPONENT_NAME = "java-aws-sdk"; private static final AwsSdkClientTracer TRACER = new AwsSdkClientTracer(); @@ -56,25 +61,29 @@ public class AwsSdkClientTracer extends HttpClientTracer, Request, AmazonWebServiceRequest originalRequest = request.getOriginalRequest(); Class awsOperation = originalRequest.getClass(); - span.setAttribute("aws.agent", COMPONENT_NAME); - span.setAttribute("aws.service", awsServiceName); - span.setAttribute("aws.operation", awsOperation.getSimpleName()); - span.setAttribute("aws.endpoint", request.getEndpoint().toString()); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + span.setAttribute("aws.agent", COMPONENT_NAME); + span.setAttribute("aws.service", awsServiceName); + span.setAttribute("aws.operation", awsOperation.getSimpleName()); + span.setAttribute("aws.endpoint", request.getEndpoint().toString()); - if (requestMeta != null) { - span.setAttribute("aws.bucket.name", requestMeta.getBucketName()); - span.setAttribute("aws.queue.url", requestMeta.getQueueUrl()); - span.setAttribute("aws.queue.name", requestMeta.getQueueName()); - span.setAttribute("aws.stream.name", requestMeta.getStreamName()); - span.setAttribute("aws.table.name", requestMeta.getTableName()); + if (requestMeta != null) { + span.setAttribute("aws.bucket.name", requestMeta.getBucketName()); + span.setAttribute("aws.queue.url", requestMeta.getQueueUrl()); + span.setAttribute("aws.queue.name", requestMeta.getQueueName()); + span.setAttribute("aws.stream.name", requestMeta.getStreamName()); + span.setAttribute("aws.table.name", requestMeta.getTableName()); + } } return context; } @Override public void onResponse(Span span, Response response) { - if (response != null && response.getAwsResponse() instanceof AmazonWebServiceResponse) { - AmazonWebServiceResponse awsResp = (AmazonWebServiceResponse) response.getAwsResponse(); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES + && response != null + && response.getAwsResponse() instanceof AmazonWebServiceResponse) { + AmazonWebServiceResponse awsResp = (AmazonWebServiceResponse) response.getAwsResponse(); span.setAttribute("aws.requestId", awsResp.getRequestId()); } super.onResponse(span, response); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/elasticsearch-transport-5.0-javaagent.gradle b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/elasticsearch-transport-5.0-javaagent.gradle index 1b3d1f399a..b30fa29151 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/elasticsearch-transport-5.0-javaagent.gradle +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/elasticsearch-transport-5.0-javaagent.gradle @@ -39,3 +39,8 @@ dependencies { testImplementation group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '5.0.0' testImplementation group: 'org.elasticsearch.client', name: 'transport', version: '5.0.0' } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.elasticsearch.experimental-span-attributes=true" +} diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/TransportActionListener.java b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/TransportActionListener.java index d57d7f8a38..4f8f7df4bf 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/TransportActionListener.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/TransportActionListener.java @@ -9,6 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.elasticsearch.transport import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.elasticsearch.action.ActionListener; @@ -26,6 +27,11 @@ import org.elasticsearch.action.support.replication.ReplicationResponse; public class TransportActionListener implements ActionListener { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty( + "otel.instrumentation.elasticsearch.experimental-span-attributes", false); + private final ActionListener listener; private final Context context; @@ -36,27 +42,29 @@ public class TransportActionListener implements Action onRequest(actionRequest); } - private void onRequest(ActionRequest request) { - Span span = Span.fromContext(context); + private void onRequest(ActionRequest request) { + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + Span span = Span.fromContext(context); - if (request instanceof IndicesRequest) { - IndicesRequest req = (IndicesRequest) request; - String[] indices = req.indices(); - if (indices != null && indices.length > 0) { - span.setAttribute("elasticsearch.request.indices", String.join(",", indices)); + if (request instanceof IndicesRequest) { + IndicesRequest req = (IndicesRequest) request; + String[] indices = req.indices(); + if (indices != null && indices.length > 0) { + span.setAttribute("elasticsearch.request.indices", String.join(",", indices)); + } } - } - if (request instanceof SearchRequest) { - SearchRequest req = (SearchRequest) request; - String[] types = req.types(); - if (types != null && types.length > 0) { - span.setAttribute("elasticsearch.request.search.types", String.join(",", types)); + if (request instanceof SearchRequest) { + SearchRequest req = (SearchRequest) request; + String[] types = req.types(); + if (types != null && types.length > 0) { + span.setAttribute("elasticsearch.request.search.types", String.join(",", types)); + } + } + if (request instanceof DocumentRequest) { + DocumentRequest req = (DocumentRequest) request; + span.setAttribute("elasticsearch.request.write.type", req.type()); + span.setAttribute("elasticsearch.request.write.routing", req.routing()); } - } - if (request instanceof DocumentRequest) { - DocumentRequest req = (DocumentRequest) request; - span.setAttribute("elasticsearch.request.write.type", req.type()); - span.setAttribute("elasticsearch.request.write.routing", req.routing()); } } @@ -71,45 +79,48 @@ public class TransportActionListener implements Action SemanticAttributes.NET_PEER_PORT, (long) response.remoteAddress().getPort()); } - if (response instanceof GetResponse) { - GetResponse resp = (GetResponse) response; - span.setAttribute("elasticsearch.type", resp.getType()); - span.setAttribute("elasticsearch.id", resp.getId()); - span.setAttribute("elasticsearch.version", resp.getVersion()); - } - - if (response instanceof BroadcastResponse) { - BroadcastResponse resp = (BroadcastResponse) response; - span.setAttribute("elasticsearch.shard.broadcast.total", resp.getTotalShards()); - span.setAttribute("elasticsearch.shard.broadcast.successful", resp.getSuccessfulShards()); - span.setAttribute("elasticsearch.shard.broadcast.failed", resp.getFailedShards()); - } - - if (response instanceof ReplicationResponse) { - ReplicationResponse resp = (ReplicationResponse) response; - span.setAttribute("elasticsearch.shard.replication.total", resp.getShardInfo().getTotal()); - span.setAttribute( - "elasticsearch.shard.replication.successful", resp.getShardInfo().getSuccessful()); - span.setAttribute("elasticsearch.shard.replication.failed", resp.getShardInfo().getFailed()); - } - - if (response instanceof IndexResponse) { - span.setAttribute( - "elasticsearch.response.status", ((IndexResponse) response).status().getStatus()); - } - - if (response instanceof BulkShardResponse) { - BulkShardResponse resp = (BulkShardResponse) response; - span.setAttribute("elasticsearch.shard.bulk.id", resp.getShardId().getId()); - span.setAttribute("elasticsearch.shard.bulk.index", resp.getShardId().getIndexName()); - } - - if (response instanceof BaseNodesResponse) { - BaseNodesResponse resp = (BaseNodesResponse) response; - if (resp.hasFailures()) { - span.setAttribute("elasticsearch.node.failures", resp.failures().size()); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + if (response instanceof GetResponse) { + GetResponse resp = (GetResponse) response; + span.setAttribute("elasticsearch.type", resp.getType()); + span.setAttribute("elasticsearch.id", resp.getId()); + span.setAttribute("elasticsearch.version", resp.getVersion()); + } + + if (response instanceof BroadcastResponse) { + BroadcastResponse resp = (BroadcastResponse) response; + span.setAttribute("elasticsearch.shard.broadcast.total", resp.getTotalShards()); + span.setAttribute("elasticsearch.shard.broadcast.successful", resp.getSuccessfulShards()); + span.setAttribute("elasticsearch.shard.broadcast.failed", resp.getFailedShards()); + } + + if (response instanceof ReplicationResponse) { + ReplicationResponse resp = (ReplicationResponse) response; + span.setAttribute("elasticsearch.shard.replication.total", resp.getShardInfo().getTotal()); + span.setAttribute( + "elasticsearch.shard.replication.successful", resp.getShardInfo().getSuccessful()); + span.setAttribute( + "elasticsearch.shard.replication.failed", resp.getShardInfo().getFailed()); + } + + if (response instanceof IndexResponse) { + span.setAttribute( + "elasticsearch.response.status", ((IndexResponse) response).status().getStatus()); + } + + if (response instanceof BulkShardResponse) { + BulkShardResponse resp = (BulkShardResponse) response; + span.setAttribute("elasticsearch.shard.bulk.id", resp.getShardId().getId()); + span.setAttribute("elasticsearch.shard.bulk.index", resp.getShardId().getIndexName()); + } + + if (response instanceof BaseNodesResponse) { + BaseNodesResponse resp = (BaseNodesResponse) response; + if (resp.hasFailures()) { + span.setAttribute("elasticsearch.node.failures", resp.failures().size()); + } + span.setAttribute("elasticsearch.node.cluster.name", resp.getClusterName().value()); } - span.setAttribute("elasticsearch.node.cluster.name", resp.getClusterName().value()); } tracer().end(span); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/elasticsearch-transport-5.3-javaagent.gradle b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/elasticsearch-transport-5.3-javaagent.gradle index 16a8d9253b..7c4cc9885d 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/elasticsearch-transport-5.3-javaagent.gradle +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/elasticsearch-transport-5.3-javaagent.gradle @@ -44,3 +44,8 @@ dependencies { latestDepTestLibrary group: 'org.elasticsearch.client', name: 'transport', version: '5.+' latestDepTestLibrary group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.0.+' } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.elasticsearch.experimental-span-attributes=true" +} diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/TransportActionListener.java b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/TransportActionListener.java index 605993157a..116b995bb0 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/TransportActionListener.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/TransportActionListener.java @@ -9,6 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.elasticsearch.transport import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.elasticsearch.action.ActionListener; @@ -26,6 +27,11 @@ import org.elasticsearch.action.support.replication.ReplicationResponse; public class TransportActionListener implements ActionListener { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty( + "otel.instrumentation.elasticsearch.experimental-span-attributes", false); + private final ActionListener listener; private final Context context; @@ -37,27 +43,29 @@ public class TransportActionListener implements Action } private void onRequest(ActionRequest request) { - Span span = Span.fromContext(context); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + Span span = Span.fromContext(context); - if (request instanceof IndicesRequest) { - IndicesRequest req = (IndicesRequest) request; - String[] indices = req.indices(); - if (indices != null && indices.length > 0) { - span.setAttribute("elasticsearch.request.indices", String.join(",", indices)); + if (request instanceof IndicesRequest) { + IndicesRequest req = (IndicesRequest) request; + String[] indices = req.indices(); + if (indices != null && indices.length > 0) { + span.setAttribute("elasticsearch.request.indices", String.join(",", indices)); + } } - } - if (request instanceof SearchRequest) { - SearchRequest req = (SearchRequest) request; - String[] types = req.types(); - if (types != null && types.length > 0) { - span.setAttribute("elasticsearch.request.search.types", String.join(",", types)); + if (request instanceof SearchRequest) { + SearchRequest req = (SearchRequest) request; + String[] types = req.types(); + if (types != null && types.length > 0) { + span.setAttribute("elasticsearch.request.search.types", String.join(",", types)); + } + } + if (request instanceof DocWriteRequest) { + DocWriteRequest req = (DocWriteRequest) request; + span.setAttribute("elasticsearch.request.write.type", req.type()); + span.setAttribute("elasticsearch.request.write.routing", req.routing()); + span.setAttribute("elasticsearch.request.write.version", req.version()); } - } - if (request instanceof DocWriteRequest) { - DocWriteRequest req = (DocWriteRequest) request; - span.setAttribute("elasticsearch.request.write.type", req.type()); - span.setAttribute("elasticsearch.request.write.routing", req.routing()); - span.setAttribute("elasticsearch.request.write.version", req.version()); } } @@ -72,45 +80,48 @@ public class TransportActionListener implements Action SemanticAttributes.NET_PEER_PORT, (long) response.remoteAddress().getPort()); } - if (response instanceof GetResponse) { - GetResponse resp = (GetResponse) response; - span.setAttribute("elasticsearch.type", resp.getType()); - span.setAttribute("elasticsearch.id", resp.getId()); - span.setAttribute("elasticsearch.version", resp.getVersion()); - } - - if (response instanceof BroadcastResponse) { - BroadcastResponse resp = (BroadcastResponse) response; - span.setAttribute("elasticsearch.shard.broadcast.total", resp.getTotalShards()); - span.setAttribute("elasticsearch.shard.broadcast.successful", resp.getSuccessfulShards()); - span.setAttribute("elasticsearch.shard.broadcast.failed", resp.getFailedShards()); - } - - if (response instanceof ReplicationResponse) { - ReplicationResponse resp = (ReplicationResponse) response; - span.setAttribute("elasticsearch.shard.replication.total", resp.getShardInfo().getTotal()); - span.setAttribute( - "elasticsearch.shard.replication.successful", resp.getShardInfo().getSuccessful()); - span.setAttribute("elasticsearch.shard.replication.failed", resp.getShardInfo().getFailed()); - } - - if (response instanceof IndexResponse) { - span.setAttribute( - "elasticsearch.response.status", ((IndexResponse) response).status().getStatus()); - } - - if (response instanceof BulkShardResponse) { - BulkShardResponse resp = (BulkShardResponse) response; - span.setAttribute("elasticsearch.shard.bulk.id", resp.getShardId().getId()); - span.setAttribute("elasticsearch.shard.bulk.index", resp.getShardId().getIndexName()); - } - - if (response instanceof BaseNodesResponse) { - BaseNodesResponse resp = (BaseNodesResponse) response; - if (resp.hasFailures()) { - span.setAttribute("elasticsearch.node.failures", resp.failures().size()); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + if (response instanceof GetResponse) { + GetResponse resp = (GetResponse) response; + span.setAttribute("elasticsearch.type", resp.getType()); + span.setAttribute("elasticsearch.id", resp.getId()); + span.setAttribute("elasticsearch.version", resp.getVersion()); + } + + if (response instanceof BroadcastResponse) { + BroadcastResponse resp = (BroadcastResponse) response; + span.setAttribute("elasticsearch.shard.broadcast.total", resp.getTotalShards()); + span.setAttribute("elasticsearch.shard.broadcast.successful", resp.getSuccessfulShards()); + span.setAttribute("elasticsearch.shard.broadcast.failed", resp.getFailedShards()); + } + + if (response instanceof ReplicationResponse) { + ReplicationResponse resp = (ReplicationResponse) response; + span.setAttribute("elasticsearch.shard.replication.total", resp.getShardInfo().getTotal()); + span.setAttribute( + "elasticsearch.shard.replication.successful", resp.getShardInfo().getSuccessful()); + span.setAttribute( + "elasticsearch.shard.replication.failed", resp.getShardInfo().getFailed()); + } + + if (response instanceof IndexResponse) { + span.setAttribute( + "elasticsearch.response.status", ((IndexResponse) response).status().getStatus()); + } + + if (response instanceof BulkShardResponse) { + BulkShardResponse resp = (BulkShardResponse) response; + span.setAttribute("elasticsearch.shard.bulk.id", resp.getShardId().getId()); + span.setAttribute("elasticsearch.shard.bulk.index", resp.getShardId().getIndexName()); + } + + if (response instanceof BaseNodesResponse) { + BaseNodesResponse resp = (BaseNodesResponse) response; + if (resp.hasFailures()) { + span.setAttribute("elasticsearch.node.failures", resp.failures().size()); + } + span.setAttribute("elasticsearch.node.cluster.name", resp.getClusterName().value()); } - span.setAttribute("elasticsearch.node.cluster.name", resp.getClusterName().value()); } tracer().end(span); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/elasticsearch-transport-6.0-javaagent.gradle b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/elasticsearch-transport-6.0-javaagent.gradle index 286d02d55c..a83b5205e7 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/elasticsearch-transport-6.0-javaagent.gradle +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/elasticsearch-transport-6.0-javaagent.gradle @@ -42,3 +42,8 @@ dependencies { latestDepTestLibrary group: 'org.elasticsearch.plugin', name: 'transport-netty4-client', version: '(6.1,6.5)' latestDepTestLibrary group: 'org.elasticsearch.client', name: 'transport', version: '(6.1,6.5)' } + +tasks.withType(Test) { + // TODO run tests both with and without experimental span attributes + jvmArgs "-Dotel.instrumentation.elasticsearch.experimental-span-attributes=true" +} diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/TransportActionListener.java b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/TransportActionListener.java index 97e51dda90..8a35efacbd 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/TransportActionListener.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/TransportActionListener.java @@ -9,6 +9,7 @@ import static io.opentelemetry.javaagent.instrumentation.elasticsearch.transport import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import org.elasticsearch.action.ActionListener; @@ -30,6 +31,11 @@ import org.elasticsearch.action.support.replication.ReplicationResponse; */ public class TransportActionListener implements ActionListener { + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty( + "otel.instrumentation.elasticsearch.experimental-span-attributes", false); + private final ActionListener listener; private final Context context; @@ -41,26 +47,28 @@ public class TransportActionListener implements Action } private void onRequest(ActionRequest request) { - Span span = Span.fromContext(context); - if (request instanceof IndicesRequest) { - IndicesRequest req = (IndicesRequest) request; - String[] indices = req.indices(); - if (indices != null && indices.length > 0) { - span.setAttribute("elasticsearch.request.indices", String.join(",", indices)); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + Span span = Span.fromContext(context); + if (request instanceof IndicesRequest) { + IndicesRequest req = (IndicesRequest) request; + String[] indices = req.indices(); + if (indices != null && indices.length > 0) { + span.setAttribute("elasticsearch.request.indices", String.join(",", indices)); + } } - } - if (request instanceof SearchRequest) { - SearchRequest req = (SearchRequest) request; - String[] types = req.types(); - if (types != null && types.length > 0) { - span.setAttribute("elasticsearch.request.search.types", String.join(",", types)); + if (request instanceof SearchRequest) { + SearchRequest req = (SearchRequest) request; + String[] types = req.types(); + if (types != null && types.length > 0) { + span.setAttribute("elasticsearch.request.search.types", String.join(",", types)); + } + } + if (request instanceof DocWriteRequest) { + DocWriteRequest req = (DocWriteRequest) request; + span.setAttribute("elasticsearch.request.write.type", req.type()); + span.setAttribute("elasticsearch.request.write.routing", req.routing()); + span.setAttribute("elasticsearch.request.write.version", req.version()); } - } - if (request instanceof DocWriteRequest) { - DocWriteRequest req = (DocWriteRequest) request; - span.setAttribute("elasticsearch.request.write.type", req.type()); - span.setAttribute("elasticsearch.request.write.routing", req.routing()); - span.setAttribute("elasticsearch.request.write.version", req.version()); } } @@ -77,45 +85,48 @@ public class TransportActionListener implements Action SemanticAttributes.NET_PEER_PORT, (long) response.remoteAddress().getPort()); } - if (response instanceof GetResponse) { - GetResponse resp = (GetResponse) response; - span.setAttribute("elasticsearch.type", resp.getType()); - span.setAttribute("elasticsearch.id", resp.getId()); - span.setAttribute("elasticsearch.version", resp.getVersion()); - } - - if (response instanceof BroadcastResponse) { - BroadcastResponse resp = (BroadcastResponse) response; - span.setAttribute("elasticsearch.shard.broadcast.total", resp.getTotalShards()); - span.setAttribute("elasticsearch.shard.broadcast.successful", resp.getSuccessfulShards()); - span.setAttribute("elasticsearch.shard.broadcast.failed", resp.getFailedShards()); - } - - if (response instanceof ReplicationResponse) { - ReplicationResponse resp = (ReplicationResponse) response; - span.setAttribute("elasticsearch.shard.replication.total", resp.getShardInfo().getTotal()); - span.setAttribute( - "elasticsearch.shard.replication.successful", resp.getShardInfo().getSuccessful()); - span.setAttribute("elasticsearch.shard.replication.failed", resp.getShardInfo().getFailed()); - } - - if (response instanceof IndexResponse) { - span.setAttribute( - "elasticsearch.response.status", ((IndexResponse) response).status().getStatus()); - } - - if (response instanceof BulkShardResponse) { - BulkShardResponse resp = (BulkShardResponse) response; - span.setAttribute("elasticsearch.shard.bulk.id", resp.getShardId().getId()); - span.setAttribute("elasticsearch.shard.bulk.index", resp.getShardId().getIndexName()); - } - - if (response instanceof BaseNodesResponse) { - BaseNodesResponse resp = (BaseNodesResponse) response; - if (resp.hasFailures()) { - span.setAttribute("elasticsearch.node.failures", resp.failures().size()); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + if (response instanceof GetResponse) { + GetResponse resp = (GetResponse) response; + span.setAttribute("elasticsearch.type", resp.getType()); + span.setAttribute("elasticsearch.id", resp.getId()); + span.setAttribute("elasticsearch.version", resp.getVersion()); + } + + if (response instanceof BroadcastResponse) { + BroadcastResponse resp = (BroadcastResponse) response; + span.setAttribute("elasticsearch.shard.broadcast.total", resp.getTotalShards()); + span.setAttribute("elasticsearch.shard.broadcast.successful", resp.getSuccessfulShards()); + span.setAttribute("elasticsearch.shard.broadcast.failed", resp.getFailedShards()); + } + + if (response instanceof ReplicationResponse) { + ReplicationResponse resp = (ReplicationResponse) response; + span.setAttribute("elasticsearch.shard.replication.total", resp.getShardInfo().getTotal()); + span.setAttribute( + "elasticsearch.shard.replication.successful", resp.getShardInfo().getSuccessful()); + span.setAttribute( + "elasticsearch.shard.replication.failed", resp.getShardInfo().getFailed()); + } + + if (response instanceof IndexResponse) { + span.setAttribute( + "elasticsearch.response.status", ((IndexResponse) response).status().getStatus()); + } + + if (response instanceof BulkShardResponse) { + BulkShardResponse resp = (BulkShardResponse) response; + span.setAttribute("elasticsearch.shard.bulk.id", resp.getShardId().getId()); + span.setAttribute("elasticsearch.shard.bulk.index", resp.getShardId().getIndexName()); + } + + if (response instanceof BaseNodesResponse) { + BaseNodesResponse resp = (BaseNodesResponse) response; + if (resp.hasFailures()) { + span.setAttribute("elasticsearch.node.failures", resp.failures().size()); + } + span.setAttribute("elasticsearch.node.cluster.name", resp.getClusterName().value()); } - span.setAttribute("elasticsearch.node.cluster.name", resp.getClusterName().value()); } tracer().end(context); diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportClientTracer.java b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportClientTracer.java index d07349c558..d0a7317371 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportClientTracer.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportClientTracer.java @@ -7,12 +7,19 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer; import java.net.InetSocketAddress; import org.elasticsearch.action.Action; public class ElasticsearchTransportClientTracer extends DatabaseClientTracer, String> { + + private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = + Config.get() + .getBooleanProperty( + "otel.instrumentation.elasticsearch.experimental-span-attributes", false); + private static final ElasticsearchTransportClientTracer TRACER = new ElasticsearchTransportClientTracer(); @@ -21,9 +28,11 @@ public class ElasticsearchTransportClientTracer } public void onRequest(Context context, Class action, Class request) { - Span span = Span.fromContext(context); - span.setAttribute("elasticsearch.action", action.getSimpleName()); - span.setAttribute("elasticsearch.request", request.getSimpleName()); + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + Span span = Span.fromContext(context); + span.setAttribute("elasticsearch.action", action.getSimpleName()); + span.setAttribute("elasticsearch.request", request.getSimpleName()); + } } @Override