Better span names couchbase
MODIFY
instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/auto/instrumentation/couchbase/client/CouchbaseBucketInstrumentation.java
instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/auto/instrumentation/couchbase/client/CouchbaseBucketInstrumentation.java
@@ -88,7 +88,7 @@ public class CouchbaseBucketInstrumentation extends Instrumenter.Default {
return;
}
CallDepthThreadLocalMap.reset(CouchbaseCluster.class);
- result = Observable.create(new CouchbaseOnSubscribe(result, method, bucket, null));
+ result = Observable.create(CouchbaseOnSubscribe.create(result, bucket, method));
}
}
@@ -111,12 +111,15 @@ public class CouchbaseBucketInstrumentation extends Instrumenter.Default {
}
CallDepthThreadLocalMap.reset(CouchbaseCluster.class);
+ if (query != null) {
// A query can be of many different types. We could track the creation of them and try to
// rewind back to when they were created from a string, but for now we rely on toString()
// returning something useful. That seems to be the case. If we're starting to see strange
// query texts, this is the place to look!
- final String queryText = query != null ? query.toString() : null;
- result = Observable.create(new CouchbaseOnSubscribe(result, method, bucket, queryText));
+ result = Observable.create(CouchbaseOnSubscribe.create(result, bucket, query.toString()));
+ } else {
+ result = Observable.create(CouchbaseOnSubscribe.create(result, bucket, method));
+ }
}
}
}

MODIFY
instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/auto/instrumentation/couchbase/client/CouchbaseClusterInstrumentation.java
instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/auto/instrumentation/couchbase/client/CouchbaseClusterInstrumentation.java
@@ -83,7 +83,7 @@ public class CouchbaseClusterInstrumentation extends Instrumenter.Default {
}
CallDepthThreadLocalMap.reset(CouchbaseCluster.class);
- result = Observable.create(new CouchbaseOnSubscribe(result, method, null, null));
+ result = Observable.create(CouchbaseOnSubscribe.create(result, null, method));
}
}
}

MODIFY
instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/auto/instrumentation/couchbase/client/CouchbaseOnSubscribe.java
instrumentation/couchbase/couchbase-2.0/src/main/java/io/opentelemetry/auto/instrumentation/couchbase/client/CouchbaseOnSubscribe.java
@@ -18,7 +18,6 @@ package io.opentelemetry.auto.instrumentation.couchbase.client;
import static io.opentelemetry.auto.instrumentation.couchbase.client.CouchbaseClientDecorator.DECORATE;
import static io.opentelemetry.trace.Span.Kind.CLIENT;
-import io.opentelemetry.auto.instrumentation.api.MoreTags;
import io.opentelemetry.auto.instrumentation.api.Tags;
import io.opentelemetry.auto.instrumentation.rxjava.TracedOnSubscribe;
import io.opentelemetry.trace.Span;
@@ -26,21 +25,26 @@ import java.lang.reflect.Method;
import rx.Observable;
public class CouchbaseOnSubscribe extends TracedOnSubscribe {
- private final String resourceName;
private final String bucket;
private final String query;
- public CouchbaseOnSubscribe(
- final Observable originalObservable,
- final Method method,
- final String bucket,
- final String query) {
- super(originalObservable, "couchbase.call", DECORATE, CLIENT);
-
+ public static CouchbaseOnSubscribe create(
+ final Observable originalObservable, final String bucket, final Method method) {
final Class<?> declaringClass = method.getDeclaringClass();
final String className =
declaringClass.getSimpleName().replace("CouchbaseAsync", "").replace("DefaultAsync", "");
- resourceName = className + "." + method.getName();
+ return new CouchbaseOnSubscribe(originalObservable, bucket, className + "." + method.getName());
+ }
+
+ public static CouchbaseOnSubscribe create(
+ final Observable originalObservable, final String bucket, final String query) {
+ return new CouchbaseOnSubscribe(originalObservable, bucket, query);
+ }
+
+ private CouchbaseOnSubscribe(
+ final Observable originalObservable, final String bucket, final String query) {
+ super(originalObservable, query, DECORATE, CLIENT);
+
this.bucket = bucket;
this.query = query;
}
@@ -49,8 +53,6 @@ public class CouchbaseOnSubscribe extends TracedOnSubscribe {
protected void afterStart(final Span span) {
super.afterStart(span);
- span.setAttribute(MoreTags.RESOURCE_NAME, resourceName);
-
span.setAttribute(Tags.DB_INSTANCE, bucket);
span.setAttribute(Tags.DB_STATEMENT, query);
}

MODIFY
instrumentation/couchbase/couchbase-2.0/src/test/groovy/CouchbaseAsyncClientTest.groovy
instrumentation/couchbase/couchbase-2.0/src/test/groovy/CouchbaseAsyncClientTest.groovy
@@ -48,7 +48,7 @@ class CouchbaseAsyncClientTest extends AbstractCouchbaseTest {
assertTraces(1) {
trace(0, 2) {
assertCouchbaseCall(it, 0, "Cluster.openBucket", null)
- assertCouchbaseCall(it, 1, "ClusterManager.hasBucket", null, null, span(0))
+ assertCouchbaseCall(it, 1, "ClusterManager.hasBucket", null, span(0))
}
}
@@ -85,8 +85,8 @@ class CouchbaseAsyncClientTest extends AbstractCouchbaseTest {
trace(0, 3) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Cluster.openBucket", null, null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.upsert", bucketSettings.name(), null, span(1))
+ assertCouchbaseCall(it, 1, "Cluster.openBucket", null, span(0))
+ assertCouchbaseCall(it, 2, "Bucket.upsert", bucketSettings.name(), span(1))
}
}
@@ -130,9 +130,9 @@ class CouchbaseAsyncClientTest extends AbstractCouchbaseTest {
trace(0, 4) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Cluster.openBucket", null, null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.upsert", bucketSettings.name(), null, span(1))
- assertCouchbaseCall(it, 3, "Bucket.get", bucketSettings.name(), null, span(2))
+ assertCouchbaseCall(it, 1, "Cluster.openBucket", null, span(0))
+ assertCouchbaseCall(it, 2, "Bucket.upsert", bucketSettings.name(), span(1))
+ assertCouchbaseCall(it, 3, "Bucket.get", bucketSettings.name(), span(2))
}
}
@@ -175,8 +175,8 @@ class CouchbaseAsyncClientTest extends AbstractCouchbaseTest {
trace(0, 3) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Cluster.openBucket", null, null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.query", bucketCouchbase.name(), 'SimpleN1qlQuery{statement=SELECT mockrow}', span(1))
+ assertCouchbaseCall(it, 1, "Cluster.openBucket", null, span(0))
+ assertCouchbaseCall(it, 2, 'SimpleN1qlQuery{statement=SELECT mockrow}', bucketCouchbase.name(), span(1))
}
}

MODIFY
instrumentation/couchbase/couchbase-2.0/src/test/groovy/CouchbaseClientTest.groovy
instrumentation/couchbase/couchbase-2.0/src/test/groovy/CouchbaseClientTest.groovy
@@ -81,8 +81,8 @@ class CouchbaseClientTest extends AbstractCouchbaseTest {
}
trace(1, 3) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Bucket.upsert", bucketSettings.name(), null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.get", bucketSettings.name(), null, span(0))
+ assertCouchbaseCall(it, 1, "Bucket.upsert", bucketSettings.name(), span(0))
+ assertCouchbaseCall(it, 2, "Bucket.get", bucketSettings.name(), span(0))
}
}
@@ -121,7 +121,7 @@ class CouchbaseClientTest extends AbstractCouchbaseTest {
assertCouchbaseCall(it, 0, "Cluster.openBucket")
}
trace(1, 1) {
- assertCouchbaseCall(it, 0, "Bucket.query", bucketCouchbase.name(), 'SimpleN1qlQuery{statement=SELECT mockrow}')
+ assertCouchbaseCall(it, 0, 'SimpleN1qlQuery{statement=SELECT mockrow}', bucketCouchbase.name())
}
}

MODIFY
instrumentation/couchbase/couchbase-2.0/src/test/groovy/springdata/CouchbaseSpringRepositoryTest.groovy
instrumentation/couchbase/couchbase-2.0/src/test/groovy/springdata/CouchbaseSpringRepositoryTest.groovy
@@ -92,7 +92,7 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
and:
assertTraces(1) {
trace(0, 1) {
- assertCouchbaseCall(it, 0, "Bucket.query", bucketCouchbase.name(), ~/^ViewQuery\(doc\/all\).*/)
+ assertCouchbaseCall(it, 0, ~/^ViewQuery\(doc\/all\).*/, bucketCouchbase.name())
}
}
}
@@ -134,8 +134,8 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
assertTraces(1) {
trace(0, 3) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Bucket.upsert", bucketCouchbase.name(), null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.get", bucketCouchbase.name(), null, span(0))
+ assertCouchbaseCall(it, 1, "Bucket.upsert", bucketCouchbase.name(), span(0))
+ assertCouchbaseCall(it, 2, "Bucket.get", bucketCouchbase.name(), span(0))
}
}
@@ -161,8 +161,8 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
assertTraces(1) {
trace(0, 3) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Bucket.upsert", bucketCouchbase.name(), null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.upsert", bucketCouchbase.name(), null, span(0))
+ assertCouchbaseCall(it, 1, "Bucket.upsert", bucketCouchbase.name(), span(0))
+ assertCouchbaseCall(it, 2, "Bucket.upsert", bucketCouchbase.name(), span(0))
}
}
@@ -189,9 +189,9 @@ class CouchbaseSpringRepositoryTest extends AbstractCouchbaseTest {
assertTraces(1) {
trace(0, 4) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Bucket.upsert", bucketCouchbase.name(), null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.remove", bucketCouchbase.name(), null, span(0))
- assertCouchbaseCall(it, 3, "Bucket.query", bucketCouchbase.name(), ~/^ViewQuery\(doc\/all\).*/, span(0))
+ assertCouchbaseCall(it, 1, "Bucket.upsert", bucketCouchbase.name(), span(0))
+ assertCouchbaseCall(it, 2, "Bucket.remove", bucketCouchbase.name(), span(0))
+ assertCouchbaseCall(it, 3, ~/^ViewQuery\(doc\/all\).*/, bucketCouchbase.name(), span(0))
}
}
}

MODIFY
instrumentation/couchbase/couchbase-2.0/src/test/groovy/springdata/CouchbaseSpringTemplateTest.groovy
instrumentation/couchbase/couchbase-2.0/src/test/groovy/springdata/CouchbaseSpringTemplateTest.groovy
@@ -90,8 +90,8 @@ class CouchbaseSpringTemplateTest extends AbstractCouchbaseTest {
assertTraces(1) {
trace(0, 3) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Bucket.upsert", name, null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.get", name, null, span(0))
+ assertCouchbaseCall(it, 1, "Bucket.upsert", name, span(0))
+ assertCouchbaseCall(it, 2, "Bucket.get", name, span(0))
}
}
@@ -115,8 +115,8 @@ class CouchbaseSpringTemplateTest extends AbstractCouchbaseTest {
assertTraces(1) {
trace(0, 3) {
basicSpan(it, 0, "someTrace")
- assertCouchbaseCall(it, 1, "Bucket.upsert", name, null, span(0))
- assertCouchbaseCall(it, 2, "Bucket.remove", name, null, span(0))
+ assertCouchbaseCall(it, 1, "Bucket.upsert", name, span(0))
+ assertCouchbaseCall(it, 2, "Bucket.remove", name, span(0))
}
}

MODIFY
instrumentation/couchbase/couchbase-2.0/src/test/groovy/util/AbstractCouchbaseTest.groovy
instrumentation/couchbase/couchbase-2.0/src/test/groovy/util/AbstractCouchbaseTest.groovy
@@ -121,9 +121,9 @@ abstract class AbstractCouchbaseTest extends AgentTestRunner {
.socketConnectTimeout(timeout.intValue())
}
- void assertCouchbaseCall(TraceAssert trace, int index, String name, String bucketName = null, Object dbStatement = null, Object parentSpan = null) {
+ void assertCouchbaseCall(TraceAssert trace, int index, Object name, String bucketName = null, Object parentSpan = null) {
trace.span(index) {
- operationName "couchbase.call"
+ operationName name
spanKind CLIENT
errored false
if (parentSpan == null) {
@@ -133,15 +133,12 @@ abstract class AbstractCouchbaseTest extends AgentTestRunner {
}
tags {
"$MoreTags.SERVICE_NAME" "couchbase"
- "$MoreTags.RESOURCE_NAME" name
"$Tags.COMPONENT" "couchbase-client"
"$Tags.DB_TYPE" "couchbase"
if (bucketName != null) {
"$Tags.DB_INSTANCE" bucketName
}
- if (dbStatement != null) {
- "$Tags.DB_STATEMENT" dbStatement
- }
+ "$Tags.DB_STATEMENT" name
}
}
}

MODIFY
instrumentation/couchbase/couchbase-2.6/src/test/groovy/CouchbaseAsyncClient26Test.groovy
instrumentation/couchbase/couchbase-2.6/src/test/groovy/CouchbaseAsyncClient26Test.groovy
@@ -18,7 +18,7 @@ import io.opentelemetry.auto.test.asserts.TraceAssert
class CouchbaseAsyncClient26Test extends CouchbaseAsyncClientTest {
@Override
- void assertCouchbaseCall(TraceAssert trace, int index, String name, String bucketName = null, Object dbStatement = null, Object parentSpan = null) {
- CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, dbStatement, parentSpan)
+ void assertCouchbaseCall(TraceAssert trace, int index, Object name, String bucketName = null, Object parentSpan = null) {
+ CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, parentSpan)
}
}

MODIFY
instrumentation/couchbase/couchbase-2.6/src/test/groovy/CouchbaseClient26Test.groovy
instrumentation/couchbase/couchbase-2.6/src/test/groovy/CouchbaseClient26Test.groovy
@@ -17,7 +17,7 @@ import io.opentelemetry.auto.test.asserts.TraceAssert
class CouchbaseClient26Test extends CouchbaseClientTest {
@Override
- void assertCouchbaseCall(TraceAssert trace, int index, String name, String bucketName = null, Object dbStatement = null, Object parentSpan = null) {
- CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, dbStatement, parentSpan)
+ void assertCouchbaseCall(TraceAssert trace, int index, Object name, String bucketName = null, Object parentSpan = null) {
+ CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, parentSpan)
}
}

MODIFY
instrumentation/couchbase/couchbase-2.6/src/test/groovy/CouchbaseSpanUtil.groovy
instrumentation/couchbase/couchbase-2.6/src/test/groovy/CouchbaseSpanUtil.groovy
@@ -23,9 +23,9 @@ import static io.opentelemetry.trace.Span.Kind.CLIENT
class CouchbaseSpanUtil {
// Reusable span assertion method. Cannot directly override AbstractCouchbaseTest.assertCouchbaseSpan because
// Of the class hierarchy of these tests
- static void assertCouchbaseCall(TraceAssert trace, int index, String name, String bucketName = null, Object dbStatement = null, Object parentSpan = null) {
+ static void assertCouchbaseCall(TraceAssert trace, int index, Object name, String bucketName = null, Object parentSpan = null) {
trace.span(index) {
- operationName "couchbase.call"
+ operationName name
spanKind CLIENT
errored false
if (parentSpan == null) {
@@ -35,7 +35,6 @@ class CouchbaseSpanUtil {
}
tags {
"$MoreTags.SERVICE_NAME" "couchbase"
- "$MoreTags.RESOURCE_NAME" name
"$Tags.COMPONENT" "couchbase-client"
// Because of caching, not all requests hit the server so these tags may be absent
@@ -55,9 +54,7 @@ class CouchbaseSpanUtil {
// that do have operation ids
"couchbase.operation_id" { it == null || String }
- if (dbStatement != null) {
- "$Tags.DB_STATEMENT" dbStatement
- }
+ "$Tags.DB_STATEMENT" name
}
}
}

MODIFY
instrumentation/couchbase/couchbase-2.6/src/test/groovy/springdata/CouchbaseSpringRepository26Test.groovy
instrumentation/couchbase/couchbase-2.6/src/test/groovy/springdata/CouchbaseSpringRepository26Test.groovy
@@ -20,7 +20,7 @@ import io.opentelemetry.auto.test.asserts.TraceAssert
class CouchbaseSpringRepository26Test extends CouchbaseSpringRepositoryTest {
@Override
- void assertCouchbaseCall(TraceAssert trace, int index, String name, String bucketName = null, Object dbStatement = null, Object parentSpan = null) {
- CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, dbStatement, parentSpan)
+ void assertCouchbaseCall(TraceAssert trace, int index, Object name, String bucketName = null, Object parentSpan = null) {
+ CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, parentSpan)
}
}

MODIFY
instrumentation/couchbase/couchbase-2.6/src/test/groovy/springdata/CouchbaseSpringTemplate26Test.groovy
instrumentation/couchbase/couchbase-2.6/src/test/groovy/springdata/CouchbaseSpringTemplate26Test.groovy
@@ -19,7 +19,7 @@ import io.opentelemetry.auto.test.asserts.TraceAssert
class CouchbaseSpringTemplate26Test extends CouchbaseSpringTemplateTest {
@Override
- void assertCouchbaseCall(TraceAssert trace, int index, String name, String bucketName = null, Object dbStatement = null, Object parentSpan = null) {
- CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, dbStatement, parentSpan)
+ void assertCouchbaseCall(TraceAssert trace, int index, Object name, String bucketName = null, Object parentSpan = null) {
+ CouchbaseSpanUtil.assertCouchbaseCall(trace, index, name, bucketName, parentSpan)
}
}

Better span names couchbase (#270)