Skip to content
Closed
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
Expand Up @@ -28,6 +28,12 @@ public static AgentScope onEnter(@Advice.Origin final Method method) {
resourceName = DECORATE.spanNameForMethod(method);
}
span.setResourceName(resourceName);

String serviceName = traceAnnotation == null ? null : traceAnnotation.serviceName();
if (serviceName != null && serviceName.length() > 0) {
span.setServiceName(serviceName);
}

DECORATE.afterStart(span);

final AgentScope scope = activateSpan(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ class TraceAnnotationsTest extends AgentTestRunner {
}
}

def "test simple case with only service name set"() {
setup:
// Test single span in new trace
SayTracedHello.sayHelloWithServiceName()

expect:
assertTraces(1) {
trace(1) {
span {
serviceName "testServiceName"
resourceName "SayTracedHello.sayHelloWithServiceName"
operationName "trace.annotation"
parent()
errored false
tags {
"$Tags.COMPONENT" "trace"
defaultTags()
}
}
}
}
}

def "test simple case with both resource and operation name set"() {
setup:
// Test single span in new trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public static String sayHAWithResource() {
return "HA EARTH!!";
}

@Trace(serviceName = "testServiceName")
public static String sayHelloWithServiceName() {
return "hello!";
}

@Trace(operationName = "NEW_TRACE")
public static String sayHELLOsayHA() {
activeSpan().setTag(DDTags.SERVICE_NAME, "test2");
Expand Down
3 changes: 3 additions & 0 deletions dd-trace-api/src/main/java/datadog/trace/api/Trace.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@

/** The resource name. By default it uses the same value as the operation name */
String resourceName() default "";

/** The service name. By default it will inherit the default service name */
String serviceName() default "";
}