Merge pull request #500 from DataDog/tyler/jax-paths
Add slashes if missing from annotation values
This commit is contained in:
commit
152a3619c9
|
@ -61,16 +61,19 @@ public final class JaxRsAnnotationsInstrumentation extends Instrumenter.Default
|
||||||
public static Scope nameSpan(@Advice.Origin final Method method) {
|
public static Scope nameSpan(@Advice.Origin final Method method) {
|
||||||
|
|
||||||
// TODO: do we need caching for this?
|
// TODO: do we need caching for this?
|
||||||
final LinkedList<Path> classPaths = new LinkedList<>();
|
final LinkedList<Path> paths = new LinkedList<>();
|
||||||
Class<?> target = method.getDeclaringClass();
|
Class<?> target = method.getDeclaringClass();
|
||||||
while (target != Object.class) {
|
while (target != Object.class) {
|
||||||
final Path annotation = target.getAnnotation(Path.class);
|
final Path annotation = target.getAnnotation(Path.class);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
classPaths.push(annotation);
|
paths.push(annotation);
|
||||||
}
|
}
|
||||||
target = target.getSuperclass();
|
target = target.getSuperclass();
|
||||||
}
|
}
|
||||||
final Path methodPath = method.getAnnotation(Path.class);
|
final Path methodPath = method.getAnnotation(Path.class);
|
||||||
|
if (methodPath != null) {
|
||||||
|
paths.add(methodPath);
|
||||||
|
}
|
||||||
String httpMethod = null;
|
String httpMethod = null;
|
||||||
for (final Annotation ann : method.getDeclaredAnnotations()) {
|
for (final Annotation ann : method.getDeclaredAnnotations()) {
|
||||||
if (ann.annotationType().getAnnotation(HttpMethod.class) != null) {
|
if (ann.annotationType().getAnnotation(HttpMethod.class) != null) {
|
||||||
|
@ -83,11 +86,15 @@ public final class JaxRsAnnotationsInstrumentation extends Instrumenter.Default
|
||||||
resourceNameBuilder.append(httpMethod);
|
resourceNameBuilder.append(httpMethod);
|
||||||
resourceNameBuilder.append(" ");
|
resourceNameBuilder.append(" ");
|
||||||
}
|
}
|
||||||
for (final Path classPath : classPaths) {
|
Path last = null;
|
||||||
resourceNameBuilder.append(classPath.value());
|
for (final Path path : paths) {
|
||||||
|
if (path.value().startsWith("/") || (last != null && last.value().endsWith("/"))) {
|
||||||
|
resourceNameBuilder.append(path.value());
|
||||||
|
} else {
|
||||||
|
resourceNameBuilder.append("/");
|
||||||
|
resourceNameBuilder.append(path.value());
|
||||||
}
|
}
|
||||||
if (methodPath != null) {
|
last = path;
|
||||||
resourceNameBuilder.append(methodPath.value());
|
|
||||||
}
|
}
|
||||||
final String resourceName = resourceNameBuilder.toString().trim();
|
final String resourceName = resourceNameBuilder.toString().trim();
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ class JaxRsAnnotationsInstrumentationTest extends AgentTestRunner {
|
||||||
@DELETE
|
@DELETE
|
||||||
void call() {}
|
void call() {}
|
||||||
}
|
}
|
||||||
"POST /abstract/child" | new ChildClassWithPath()
|
"POST /abstract/child/call" | new ChildClassWithPath()
|
||||||
|
|
||||||
className = getName(obj.class)
|
className = getName(obj.class)
|
||||||
}
|
}
|
||||||
|
@ -138,8 +138,9 @@ class JaxRsAnnotationsInstrumentationTest extends AgentTestRunner {
|
||||||
abstract void call()
|
abstract void call()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("/child")
|
@Path("child")
|
||||||
class ChildClassWithPath extends AbstractClassWithPath {
|
class ChildClassWithPath extends AbstractClassWithPath {
|
||||||
|
@Path("call")
|
||||||
@POST
|
@POST
|
||||||
void call() {}
|
void call() {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue