Search in sources :

Example 1 with WeaveWithAnnotation

use of com.newrelic.api.agent.weaver.WeaveWithAnnotation in project newrelic-java-agent by newrelic.

the class JavaxWsRsApi_Instrumentation method instrumentation.

@WeaveWithAnnotation(annotationClasses = { "javax.ws.rs.PUT", "javax.ws.rs.POST", "javax.ws.rs.GET", "javax.ws.rs.DELETE", "javax.ws.rs.HEAD", "javax.ws.rs.OPTIONS", "javax.ws.rs.PATCH" })
@WeaveIntoAllMethods
@Trace(dispatcher = true)
private static void instrumentation() {
    Transaction transaction = AgentBridge.getAgent().getWeakRefTransaction(false);
    if (transaction != null) {
        JavaxWsRsApiHelper.ResourcePath resourcePath = JavaxWsRsApiHelper.subresourcePath.get();
        if (!transaction.equals(resourcePath.transaction)) {
            resourcePath.pathQueue.clear();
            resourcePath.transaction = transaction;
        }
        String rootPath = null;
        Path rootPathAnnotation = Weaver.getClassAnnotation(Path.class);
        if (rootPathAnnotation != null) {
            rootPath = rootPathAnnotation.value();
        }
        String methodPath = null;
        Path methodPathAnnotation = Weaver.getMethodAnnotation(Path.class);
        if (methodPathAnnotation != null) {
            methodPath = methodPathAnnotation.value();
        }
        String httpMethod = null;
        /* Unfortunately we have to do this in a big if/else block because we can't currently support variables passed
             into the Weaver.getMethodAnnotation method. We might be able to make an improvement to handle this in the future */
        if (Weaver.getMethodAnnotation(PUT.class) != null) {
            httpMethod = PUT.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(POST.class) != null) {
            httpMethod = POST.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(GET.class) != null) {
            httpMethod = GET.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(DELETE.class) != null) {
            httpMethod = DELETE.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(HEAD.class) != null) {
            httpMethod = HEAD.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(OPTIONS.class) != null) {
            httpMethod = OPTIONS.class.getSimpleName();
        } else {
            // PATCH annotation was added later so may not be available
            try {
                if (Weaver.getMethodAnnotation(PATCH.class) != null) {
                    httpMethod = PATCH.class.getSimpleName();
                }
            } catch (NoClassDefFoundError e) {
            }
        }
        if (httpMethod != null) {
            Queue<String> subresourcePath = resourcePath.pathQueue;
            String fullPath = JavaxWsRsApiHelper.getPath(rootPath, methodPath, httpMethod);
            subresourcePath.offer(fullPath);
            StringBuilder txNameBuilder = new StringBuilder();
            String pathPart;
            while ((pathPart = subresourcePath.poll()) != null) {
                txNameBuilder.append(pathPart);
            }
            transaction.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, false, "RestWebService", txNameBuilder.toString());
        } else {
            String fullPath = JavaxWsRsApiHelper.getPath(rootPath, methodPath, null);
            if (!resourcePath.pathQueue.offer(fullPath)) {
                AgentBridge.getAgent().getLogger().log(Level.FINE, "JAX-RS Subresource naming queue is full.");
                resourcePath.pathQueue.clear();
            }
        }
    }
}
Also used : Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) Transaction(com.newrelic.agent.bridge.Transaction) GET(javax.ws.rs.GET) PUT(javax.ws.rs.PUT) WeaveIntoAllMethods(com.newrelic.api.agent.weaver.WeaveIntoAllMethods) Trace(com.newrelic.api.agent.Trace) WeaveWithAnnotation(com.newrelic.api.agent.weaver.WeaveWithAnnotation)

Example 2 with WeaveWithAnnotation

use of com.newrelic.api.agent.weaver.WeaveWithAnnotation in project newrelic-java-agent by newrelic.

the class JavaxWsRsApi_Subresource_Instrumentation method instrumentation.

@WeaveWithAnnotation(annotationClasses = { "javax.ws.rs.PUT", "javax.ws.rs.POST", "javax.ws.rs.GET", "javax.ws.rs.DELETE", "javax.ws.rs.HEAD", "javax.ws.rs.OPTIONS", "javax.ws.rs.Path", "javax.ws.rs.PATCH" })
@WeaveIntoAllMethods
@Trace(dispatcher = true)
private static void instrumentation() {
    Transaction transaction = AgentBridge.getAgent().getWeakRefTransaction(false);
    if (transaction != null) {
        JavaxWsRsApiHelper.ResourcePath resourcePath = JavaxWsRsApiHelper.subresourcePath.get();
        if (!transaction.equals(resourcePath.transaction)) {
            resourcePath.pathQueue.clear();
            resourcePath.transaction = transaction;
        }
        String rootPath = null;
        Path rootPathAnnotation = Weaver.getClassAnnotation(Path.class);
        if (rootPathAnnotation != null) {
            rootPath = rootPathAnnotation.value();
        }
        String methodPath = null;
        Path methodPathAnnotation = Weaver.getMethodAnnotation(Path.class);
        if (methodPathAnnotation != null) {
            methodPath = methodPathAnnotation.value();
        }
        String httpMethod = null;
        /* Unfortunately we have to do this in a big if/else block because we can't currently support variables passed
             into the Weaver.getMethodAnnotation method. We might be able to make an improvement to handle this in the future */
        if (Weaver.getMethodAnnotation(PUT.class) != null) {
            httpMethod = PUT.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(POST.class) != null) {
            httpMethod = POST.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(GET.class) != null) {
            httpMethod = GET.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(DELETE.class) != null) {
            httpMethod = DELETE.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(HEAD.class) != null) {
            httpMethod = HEAD.class.getSimpleName();
        } else if (Weaver.getMethodAnnotation(OPTIONS.class) != null) {
            httpMethod = OPTIONS.class.getSimpleName();
        } else {
            // PATCH annotation was added later so may not be available
            try {
                if (Weaver.getMethodAnnotation(PATCH.class) != null) {
                    httpMethod = PATCH.class.getSimpleName();
                }
            } catch (NoClassDefFoundError e) {
            }
        }
        if (httpMethod != null) {
            Queue<String> subresourcePath = resourcePath.pathQueue;
            String fullPath = JavaxWsRsApiHelper.getPath(rootPath, methodPath, httpMethod);
            subresourcePath.offer(fullPath);
            StringBuilder txNameBuilder = new StringBuilder();
            String pathPart;
            while ((pathPart = subresourcePath.poll()) != null) {
                txNameBuilder.append(pathPart);
            }
            transaction.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, false, "RestWebService", txNameBuilder.toString());
        } else {
            String fullPath = JavaxWsRsApiHelper.getPath(rootPath, methodPath, null);
            if (!resourcePath.pathQueue.offer(fullPath)) {
                AgentBridge.getAgent().getLogger().log(Level.FINE, "JAX-RS Subresource naming queue is full.");
                resourcePath.pathQueue.clear();
            }
        }
    }
}
Also used : Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) Transaction(com.newrelic.agent.bridge.Transaction) GET(javax.ws.rs.GET) PUT(javax.ws.rs.PUT) WeaveIntoAllMethods(com.newrelic.api.agent.weaver.WeaveIntoAllMethods) Trace(com.newrelic.api.agent.Trace) WeaveWithAnnotation(com.newrelic.api.agent.weaver.WeaveWithAnnotation)

Example 3 with WeaveWithAnnotation

use of com.newrelic.api.agent.weaver.WeaveWithAnnotation in project newrelic-java-agent by newrelic.

the class SpringController_Instrumentation method requestMapping.

@WeaveWithAnnotation(annotationClasses = { "org.springframework.web.bind.annotation.RequestMapping", "org.springframework.web.bind.annotation.PatchMapping", "org.springframework.web.bind.annotation.PutMapping", "org.springframework.web.bind.annotation.GetMapping", "org.springframework.web.bind.annotation.PostMapping", "org.springframework.web.bind.annotation.DeleteMapping" })
@WeaveIntoAllMethods
@Trace
private static void requestMapping() {
    Transaction transaction = AgentBridge.getAgent().getTransaction(false);
    if (transaction != null) {
        RequestMapping rootPathMapping = Weaver.getClassAnnotation(RequestMapping.class);
        String rootPath = null;
        if (rootPathMapping != null) {
            rootPath = SpringControllerUtility.getPathValue(rootPathMapping.value(), rootPathMapping.path());
        }
        // PUT, DELETE, POST, GET
        if (Weaver.getMethodAnnotation(RequestMapping.class) != null) {
            RequestMapping methodPathMapping = Weaver.getMethodAnnotation(RequestMapping.class);
            String methodPath = SpringControllerUtility.getPathValue(methodPathMapping.value(), methodPathMapping.path());
            processAnnotations(transaction, methodPathMapping.method(), rootPath, methodPath, MethodHandles.lookup().lookupClass());
        } else if (Weaver.getMethodAnnotation(PutMapping.class) != null) {
            PutMapping methodPathMapping = Weaver.getMethodAnnotation(PutMapping.class);
            String methodPath = SpringControllerUtility.getPathValue(methodPathMapping.value(), methodPathMapping.path());
            processAnnotations(transaction, new RequestMethod[] { RequestMethod.PUT }, rootPath, methodPath, MethodHandles.lookup().lookupClass());
        } else if (Weaver.getMethodAnnotation(DeleteMapping.class) != null) {
            DeleteMapping methodPathMapping = Weaver.getMethodAnnotation(DeleteMapping.class);
            String methodPath = SpringControllerUtility.getPathValue(methodPathMapping.value(), methodPathMapping.path());
            processAnnotations(transaction, new RequestMethod[] { RequestMethod.DELETE }, rootPath, methodPath, MethodHandles.lookup().lookupClass());
        } else if (Weaver.getMethodAnnotation(PostMapping.class) != null) {
            PostMapping methodPathMapping = Weaver.getMethodAnnotation(PostMapping.class);
            String methodPath = SpringControllerUtility.getPathValue(methodPathMapping.value(), methodPathMapping.path());
            processAnnotations(transaction, new RequestMethod[] { RequestMethod.POST }, rootPath, methodPath, MethodHandles.lookup().lookupClass());
        } else if (Weaver.getMethodAnnotation(PatchMapping.class) != null) {
            PatchMapping methodPathMapping = Weaver.getMethodAnnotation(PatchMapping.class);
            String methodPath = SpringControllerUtility.getPathValue(methodPathMapping.value(), methodPathMapping.path());
            processAnnotations(transaction, new RequestMethod[] { RequestMethod.PATCH }, rootPath, methodPath, MethodHandles.lookup().lookupClass());
        } else if (Weaver.getMethodAnnotation(GetMapping.class) != null) {
            GetMapping methodPathMapping = Weaver.getMethodAnnotation(GetMapping.class);
            String methodPath = SpringControllerUtility.getPathValue(methodPathMapping.value(), methodPathMapping.path());
            processAnnotations(transaction, new RequestMethod[] { RequestMethod.GET }, rootPath, methodPath, MethodHandles.lookup().lookupClass());
        }
    }
}
Also used : GetMapping(org.springframework.web.bind.annotation.GetMapping) Transaction(com.newrelic.agent.bridge.Transaction) PostMapping(org.springframework.web.bind.annotation.PostMapping) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) PutMapping(org.springframework.web.bind.annotation.PutMapping) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) WeaveIntoAllMethods(com.newrelic.api.agent.weaver.WeaveIntoAllMethods) Trace(com.newrelic.api.agent.Trace) WeaveWithAnnotation(com.newrelic.api.agent.weaver.WeaveWithAnnotation)

Example 4 with WeaveWithAnnotation

use of com.newrelic.api.agent.weaver.WeaveWithAnnotation in project newrelic-java-agent by newrelic.

the class SpringController_Instrumentation method instrumentation.

@WeaveWithAnnotation(annotationClasses = { "org.springframework.web.bind.annotation.RequestMapping" })
@WeaveIntoAllMethods
@Trace
private static void instrumentation() {
    Transaction transaction = AgentBridge.getAgent().getTransaction(false);
    if (transaction != null) {
        RequestMapping rootPathMapping = Weaver.getClassAnnotation(RequestMapping.class);
        RequestMapping methodPathMapping = Weaver.getMethodAnnotation(RequestMapping.class);
        String rootPath = SpringControllerUtility.getPathValue(rootPathMapping);
        String methodPath = SpringControllerUtility.getPathValue(methodPathMapping);
        RequestMethod httpMethod = RequestMethod.GET;
        RequestMethod[] methods = methodPathMapping.method();
        if (methods.length > 0) {
            httpMethod = methods[0];
        }
        if (rootPath == null && methodPath == null) {
            AgentBridge.getAgent().getLogger().log(Level.FINE, "No path was specified for SpringController {0}", MethodHandles.lookup().lookupClass().getName());
        } else {
            String fullPath = SpringControllerUtility.getPath(rootPath, methodPath, httpMethod);
            transaction.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, "SpringController", fullPath);
        }
    }
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) WeaveIntoAllMethods(com.newrelic.api.agent.weaver.WeaveIntoAllMethods) Trace(com.newrelic.api.agent.Trace) WeaveWithAnnotation(com.newrelic.api.agent.weaver.WeaveWithAnnotation)

Aggregations

Transaction (com.newrelic.agent.bridge.Transaction)4 Trace (com.newrelic.api.agent.Trace)4 WeaveIntoAllMethods (com.newrelic.api.agent.weaver.WeaveIntoAllMethods)4 WeaveWithAnnotation (com.newrelic.api.agent.weaver.WeaveWithAnnotation)4 GET (javax.ws.rs.GET)2 HEAD (javax.ws.rs.HEAD)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1