Better span names for spring-scheduling (#244)
This commit is contained in:
parent
d759f846bb
commit
f88dabedee
|
@ -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;
|
||||
}
|
||||
span.setAttribute(MoreTags.RESOURCE_NAME, resourceName);
|
||||
}
|
||||
return span;
|
||||
return spanNameForClass(runnable.getClass()) + "/run";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
* 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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue