Jax-rs user METHOD PATH as resource only when root span
This commit is contained in:
parent
0b71c6bbe5
commit
0b0d75bcf2
|
@ -37,27 +37,45 @@ public class JaxRsAnnotationsDecorator extends BaseDecorator {
|
|||
return "jax-rs-controller";
|
||||
}
|
||||
|
||||
public void updateParent(final Scope scope, final Method method) {
|
||||
public void updateScope(final Scope scope, final Scope parent, final Method method) {
|
||||
String resourceName = getResourceName(method);
|
||||
updateParent(parent, resourceName);
|
||||
|
||||
final Span span = scope.span();
|
||||
span.setTag(DDTags.SPAN_TYPE, DDSpanTypes.HTTP_SERVER);
|
||||
|
||||
// When jax-rs is the root scope, then we
|
||||
boolean isRootScope = parent == null;
|
||||
if (isRootScope && !resourceName.isEmpty()) {
|
||||
span.setTag(DDTags.RESOURCE_NAME, resourceName);
|
||||
} else {
|
||||
span.setTag(DDTags.RESOURCE_NAME, DECORATE.spanNameForMethod(method));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateParent(final Scope scope, final String resourceName) {
|
||||
if (scope == null) {
|
||||
return;
|
||||
}
|
||||
final Span span = scope.span();
|
||||
Tags.COMPONENT.set(span, "jax-rs");
|
||||
|
||||
String resourceName = getResourceName(method);
|
||||
if (!resourceName.isEmpty()) {
|
||||
span.setTag(DDTags.RESOURCE_NAME, resourceName);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCurrentScope(final Scope scope, final Method method) {
|
||||
public void updateCurrentScope(final Scope scope, final Method method, boolean isRootScope) {
|
||||
final Span span = scope.span();
|
||||
span.setTag(DDTags.SPAN_TYPE, DDSpanTypes.HTTP_SERVER);
|
||||
|
||||
if (isRootScope) {
|
||||
String resourceName = getResourceName(method);
|
||||
if (!resourceName.isEmpty()) {
|
||||
span.setTag(DDTags.RESOURCE_NAME, resourceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource name given a JaxRS annotated method. Results are cached so this method can
|
||||
|
|
|
@ -64,8 +64,7 @@ public final class JaxRsAnnotationsInstrumentation extends Instrumenter.Default
|
|||
// Rename the parent span according to the path represented by these annotations.
|
||||
final Scope parent = tracer.scopeManager().active();
|
||||
Scope scope = tracer.buildSpan(JAX_ENDPOINT_OPERATION_NAME).startActive(true);
|
||||
DECORATE.updateParent(parent, method);
|
||||
DECORATE.updateCurrentScope(scope, method);
|
||||
DECORATE.updateScope(scope, parent, method);
|
||||
return DECORATE.afterStart(scope);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import static datadog.trace.instrumentation.jaxrs.JaxRsAnnotationsDecorator.DECO
|
|||
|
||||
class JaxRsAnnotationsInstrumentationTest extends AgentTestRunner {
|
||||
|
||||
def "instrumentation can be used as root span and relevant tags are set"() {
|
||||
def "instrumentation can be used as root span and resource is set to METHOD PATH"() {
|
||||
setup:
|
||||
new Jax() {
|
||||
@POST
|
||||
|
@ -38,7 +38,7 @@ class JaxRsAnnotationsInstrumentationTest extends AgentTestRunner {
|
|||
}
|
||||
}
|
||||
|
||||
def "span named '#name' from annotations on class"() {
|
||||
def "span named '#name' from annotations on class when is not root span"() {
|
||||
setup:
|
||||
def startingCacheSize = DECORATE.resourceNames.size()
|
||||
runUnderTrace("test") {
|
||||
|
@ -59,7 +59,7 @@ class JaxRsAnnotationsInstrumentationTest extends AgentTestRunner {
|
|||
}
|
||||
span(1) {
|
||||
operationName "jax-rs.request"
|
||||
resourceName name
|
||||
resourceName "${className}.call"
|
||||
spanType "web"
|
||||
childOf span(0)
|
||||
tags {
|
||||
|
|
Loading…
Reference in New Issue