Better span names for spring-scheduling
MODIFY
instrumentation/spring-scheduling-3.1/src/main/java/io/opentelemetry/auto/instrumentation/springscheduling/SpringSchedulingDecorator.java
instrumentation/spring-scheduling-3.1/src/main/java/io/opentelemetry/auto/instrumentation/springscheduling/SpringSchedulingDecorator.java
@@ -17,8 +17,6 @@ package io.opentelemetry.auto.instrumentation.springscheduling;
import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.auto.bootstrap.instrumentation.decorator.BaseDecorator;
-import io.opentelemetry.auto.instrumentation.api.MoreTags;
-import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Tracer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.support.ScheduledMethodRunnable;
@@ -42,19 +40,12 @@ public class SpringSchedulingDecorator extends BaseDecorator {
return "spring-scheduling";
}
- public Span onRun(final Span span, final Runnable runnable) {
- if (runnable != null) {
- String resourceName = "";
+ public String spanNameOnRun(final Runnable runnable) {
if (runnable instanceof ScheduledMethodRunnable) {
final ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
- resourceName = spanNameForMethod(scheduledMethodRunnable.getMethod());
+ return spanNameForMethod(scheduledMethodRunnable.getMethod());
} else {
- final String className = spanNameForClass(runnable.getClass());
- final String methodName = "run";
- resourceName = className + "." + methodName;
+ return spanNameForClass(runnable.getClass()) + "/run";
}
- span.setAttribute(MoreTags.RESOURCE_NAME, resourceName);
- }
- return span;
}
}

MODIFY
instrumentation/spring-scheduling-3.1/src/main/java/io/opentelemetry/auto/instrumentation/springscheduling/SpringSchedulingInstrumentation.java
instrumentation/spring-scheduling-3.1/src/main/java/io/opentelemetry/auto/instrumentation/springscheduling/SpringSchedulingInstrumentation.java
@@ -75,18 +75,17 @@ public final class SpringSchedulingInstrumentation extends Instrumenter.Default
@Override
public void run() {
- final Span span = TRACER.spanBuilder("scheduled.call").startSpan();
+ if (runnable == null) {
+ return;
+ }
+ final Span span = TRACER.spanBuilder(DECORATE.spanNameOnRun(runnable)).startSpan();
DECORATE.afterStart(span);
try (final Scope scope = TRACER.withSpan(span)) {
- DECORATE.onRun(span, runnable);
-
- try {
runnable.run();
} catch (final Throwable throwable) {
DECORATE.onError(span, throwable);
throw throwable;
- }
} finally {
DECORATE.beforeFinish(span);
span.end();

MODIFY
instrumentation/spring-scheduling-3.1/src/test/groovy/SpringSchedulingTest.groovy
instrumentation/spring-scheduling-3.1/src/test/groovy/SpringSchedulingTest.groovy
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import org.springframework.context.annotation.AnnotationConfigApplicationContext
@@ -32,11 +31,10 @@ class SpringSchedulingTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 1) {
span(0) {
- operationName "scheduled.call"
+ operationName "TriggerTask.run"
parent()
errored false
tags {
- "$MoreTags.RESOURCE_NAME" "TriggerTask.run"
"$Tags.COMPONENT" "spring-scheduling"
}
}
@@ -56,11 +54,10 @@ class SpringSchedulingTest extends AgentTestRunner {
assertTraces(1) {
trace(0, 1) {
span(0) {
- operationName "scheduled.call"
+ operationName "IntervalTask.run"
parent()
errored false
tags {
- "$MoreTags.RESOURCE_NAME" "IntervalTask.run"
"$Tags.COMPONENT" "spring-scheduling"
}
}

Better span names for spring-scheduling (#244)