Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code attributes to spring-scheduling spans #5306

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.spring.scheduling;

import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesExtractor;
import javax.annotation.Nullable;
import org.springframework.scheduling.support.ScheduledMethodRunnable;

public class SpringSchedulingCodeAttributesExtractor
extends CodeAttributesExtractor<Runnable, Void> {

@Override
protected Class<?> codeClass(Runnable runnable) {
if (runnable instanceof ScheduledMethodRunnable) {
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
return scheduledMethodRunnable.getTarget().getClass();
} else {
return runnable.getClass();
}
}

@Override
protected String methodName(Runnable runnable) {
if (runnable instanceof ScheduledMethodRunnable) {
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) runnable;
return scheduledMethodRunnable.getMethod().getName();
} else {
return "run";
}
}

@Override
@Nullable
protected String filePath(Runnable runnable) {
return null;
}

@Override
@Nullable
protected Long lineNumber(Runnable runnable) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class SpringSchedulingSingletons {
GlobalOpenTelemetry.get(),
"io.opentelemetry.spring-scheduling-3.1",
SpringSchedulingSingletons::extractSpanName)
.addAttributesExtractor(new SpringSchedulingCodeAttributesExtractor())
.newInstrumenter();

private static String extractSpanName(Runnable runnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SpringSchedulingTest extends AgentInstrumentationSpecification {
name "TriggerTask.run"
hasNoParent()
attributes {
"code.namespace" "TriggerTask"
"code.function" "run"
}
}
}
Expand All @@ -46,6 +48,8 @@ class SpringSchedulingTest extends AgentInstrumentationSpecification {
name "IntervalTask.run"
hasNoParent()
attributes {
"code.namespace" "IntervalTask"
"code.function" "run"
}
}
}
Expand All @@ -67,6 +71,8 @@ class SpringSchedulingTest extends AgentInstrumentationSpecification {
nameContains "LambdaTaskConfigurer\$\$Lambda\$"
hasNoParent()
attributes {
"code.namespace" { it.contains("LambdaTaskConfigurer\$\$Lambda\$") }
"code.function" "run"
}
}
}
Expand Down