Skip to content
Permalink
Browse files
adding server.filter.request.operationName.usePath option
  • Loading branch information
rmannibucau committed May 22, 2018
1 parent 5f606e8 commit 1e3ee3f3ae0bbf4288fdbff8f3137642b15985ca
Showing 2 changed files with 30 additions and 8 deletions.
@@ -20,6 +20,7 @@ NOTE: if you are using Microprofile Config it is used, otherwise it uses system
|geronimo.opentracing.server.filter.request.skip.<endpoint class>_<endpoint method>|Should server instrumentation be ignored|false
|geronimo.opentracing.server.filter.request.skip|Should server instrumentation be ignored (if previous is not set)|false
|geronimo.opentracing.server.filter.request.skipDefaultTags|Should `HTTP_METHOD`, `HTTP_URL` not be added to tags|false
|geronimo.opentracing.server.filter.request.operationName.usePath|Should the operationName use the `@Path` annotations instead of class names.|false
|geronimo.opentracing.client.filter.request.skip|Should client instrumentation be ignored|false
|geronimo.opentracing.client.filter.request.skipDefaultTags|Should `HTTP_METHOD`, `HTTP_URL` not be added to tags|false
|geronimo.opentracing.client.filter.request.skipPeerTags|Should `PEER_HOSTNAME`, `PEER_PORT` not be added to tags|false
@@ -25,6 +25,7 @@
import javax.enterprise.inject.spi.CDI;
import javax.inject.Inject;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.Path;
import javax.ws.rs.container.DynamicFeature;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.FeatureContext;
@@ -59,15 +60,35 @@ public void configure(final ResourceInfo resourceInfo, final FeatureContext cont
return;
}

final String operationName = traced.map(Traced::operationName).filter(v -> !v.trim().isEmpty())
.orElseGet(() -> Stream.of(resourceInfo.getResourceMethod().getAnnotations())
.filter(a -> a.annotationType().isAnnotationPresent(HttpMethod.class)).findFirst()
.map(a -> a.annotationType().getAnnotation(HttpMethod.class).value()).orElse("") + ':'
+ resourceInfo.getResourceClass().getName() + "." + resourceInfo.getResourceMethod().getName());
final String operationName = traced.map(Traced::operationName).filter(v -> !v.trim().isEmpty()).orElseGet(() -> {
final boolean usePath = Boolean.parseBoolean(config.read("server.filter.request.operationName.usePath", "false"));
if (usePath) {
final String classPath = ofNullable(resourceInfo.getResourceClass().getAnnotation(Path.class)).map(Path::value)
.orElse("");
final String methodPath = ofNullable(resourceInfo.getResourceMethod().getAnnotation(Path.class)).map(Path::value)
.orElse("");
return getHttpMethod(resourceInfo) + ':' + classPath
+ (!classPath.isEmpty() && !methodPath.isEmpty() && !classPath.endsWith("/") ? "/" : "") + methodPath;
}
return buildDefaultName(resourceInfo);
});
context.register(new OpenTracingServerResponseFilter())
.register(new OpenTracingServerRequestFilter(
operationName, tracer,
Boolean.parseBoolean(config.read("server.filter.request.skip." + resourceInfo.getResourceClass().getName() + "_" + resourceInfo.getResourceMethod().getName(), config.read("server.filter.request.skip", "false"))),
.register(new OpenTracingServerRequestFilter(operationName, tracer,
Boolean.parseBoolean(config.read(
"server.filter.request.skip." + resourceInfo.getResourceClass().getName() + "_"
+ resourceInfo.getResourceMethod().getName(),
config.read("server.filter.request.skip", "false"))),
Boolean.parseBoolean(config.read("server.filter.request.skipDefaultTags", "false"))));
}

private String buildDefaultName(final ResourceInfo resourceInfo) {
return getHttpMethod(resourceInfo) + ':' + resourceInfo.getResourceClass().getName() + "."
+ resourceInfo.getResourceMethod().getName();
}

private String getHttpMethod(final ResourceInfo resourceInfo) {
return Stream.of(resourceInfo.getResourceMethod().getAnnotations())
.filter(a -> a.annotationType().isAnnotationPresent(HttpMethod.class)).findFirst()
.map(a -> a.annotationType().getAnnotation(HttpMethod.class).value()).orElse("");
}
}

0 comments on commit 1e3ee3f

Please sign in to comment.