Better span names for twilio
MODIFY
instrumentation/twilio-6.6/src/main/java/io/opentelemetry/auto/instrumentation/twilio/TwilioAsyncInstrumentation.java
instrumentation/twilio-6.6/src/main/java/io/opentelemetry/auto/instrumentation/twilio/TwilioAsyncInstrumentation.java
@@ -119,10 +119,13 @@ public class TwilioAsyncInstrumentation extends Instrumenter.Default {
}
// Don't automatically close the span with the scope if we're executing an async method
- final Span span = TRACER.spanBuilder("twilio.sdk").setSpanKind(CLIENT).startSpan();
+ final Span span =
+ TRACER
+ .spanBuilder(DECORATE.spanNameOnServiceExecution(that, methodName))
+ .setSpanKind(CLIENT)
+ .startSpan();
DECORATE.afterStart(span);
- DECORATE.onServiceExecution(span, that, methodName);
return new SpanWithScope(span, TRACER.withSpan(span));
}

MODIFY
instrumentation/twilio-6.6/src/main/java/io/opentelemetry/auto/instrumentation/twilio/TwilioClientDecorator.java
instrumentation/twilio-6.6/src/main/java/io/opentelemetry/auto/instrumentation/twilio/TwilioClientDecorator.java
@@ -20,7 +20,6 @@ import com.twilio.rest.api.v2010.account.Call;
import com.twilio.rest.api.v2010.account.Message;
import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.auto.bootstrap.instrumentation.decorator.ClientDecorator;
-import io.opentelemetry.auto.instrumentation.api.MoreTags;
import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Tracer;
import java.lang.reflect.Method;
@@ -49,16 +48,8 @@ public class TwilioClientDecorator extends ClientDecorator {
}
/** Decorate trace based on service execution metadata. */
- public Span onServiceExecution(
- final Span span, final Object serviceExecutor, final String methodName) {
-
- // Drop common package prefix (com.twilio.rest)
- final String simpleClassName =
- serviceExecutor.getClass().getCanonicalName().replaceFirst("^com\\.twilio\\.rest\\.", "");
-
- span.setAttribute(MoreTags.RESOURCE_NAME, String.format("%s.%s", simpleClassName, methodName));
-
- return span;
+ public String spanNameOnServiceExecution(final Object serviceExecutor, final String methodName) {
+ return spanNameForClass(serviceExecutor.getClass()) + "." + methodName;
}
/** Annotate the span with the results of the operation. */

MODIFY
instrumentation/twilio-6.6/src/main/java/io/opentelemetry/auto/instrumentation/twilio/TwilioSyncInstrumentation.java
instrumentation/twilio-6.6/src/main/java/io/opentelemetry/auto/instrumentation/twilio/TwilioSyncInstrumentation.java
@@ -114,9 +114,12 @@ public class TwilioSyncInstrumentation extends Instrumenter.Default {
return null;
}
- final Span span = TRACER.spanBuilder("twilio.sdk").setSpanKind(CLIENT).startSpan();
+ final Span span =
+ TRACER
+ .spanBuilder(DECORATE.spanNameOnServiceExecution(that, methodName))
+ .setSpanKind(CLIENT)
+ .startSpan();
DECORATE.afterStart(span);
- DECORATE.onServiceExecution(span, that, methodName);
return new SpanWithScope(span, TRACER.withSpan(span));
}

MODIFY
instrumentation/twilio-6.6/src/test/groovy/test/TwilioClientTest.groovy
instrumentation/twilio-6.6/src/test/groovy/test/TwilioClientTest.groovy
@@ -149,12 +149,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -196,12 +195,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "CallCreator.create"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.CallCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Call"
"twilio.account" "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@@ -265,12 +263,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -362,12 +359,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -479,12 +475,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.createAsync"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.createAsync"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -493,12 +488,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(2) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -574,12 +568,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
errored true
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
errorTags(ApiException, "Testing Failure")
}
@@ -607,13 +600,12 @@ class TwilioClientTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 1) {
span(0) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
parent()
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -664,12 +656,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.createAsync"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.createAsync"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -678,12 +669,11 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(2) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
errored false
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
"twilio.type" "com.twilio.rest.api.v2010.account.Message"
"twilio.account" "AC14984e09e497506cf0d5eb59b1f6ace7"
@@ -747,23 +737,21 @@ class TwilioClientTest extends AgentTestRunner {
}
}
span(1) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.createAsync"
spanKind CLIENT
errored true
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.createAsync"
"$Tags.COMPONENT" "twilio-sdk"
errorTags(ApiException, "Testing Failure")
}
}
span(2) {
- operationName "twilio.sdk"
+ operationName "MessageCreator.create"
spanKind CLIENT
errored true
tags {
"$MoreTags.SERVICE_NAME" "twilio-sdk"
- "$MoreTags.RESOURCE_NAME" "api.v2010.account.MessageCreator.create"
"$Tags.COMPONENT" "twilio-sdk"
errorTags(ApiException, "Testing Failure")
}

Better span names for twilio (#259)