Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Grails plugin #80

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
target/
.idea
*.iml
84 changes: 84 additions & 0 deletions agent-parent/plugins/grails-plugin/pom.xml
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glowroot</groupId>
<artifactId>glowroot-parent</artifactId>
<version>0.9-SNAPSHOT</version>
<relativePath>../../..</relativePath>
</parent>

<artifactId>glowroot-agent-grails-plugin</artifactId>

<name>Glowroot Agent Grails Plugin</name>
<description>Glowroot Agent Grails Plugin</description>

<dependencies>
<dependency>
<groupId>org.glowroot</groupId>
<artifactId>glowroot-agent-plugin-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<!-- don't need this dependency at runtime since only annotations -->
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glowroot</groupId>
<artifactId>glowroot-agent-it-harness</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,59 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.glowroot.agent.plugin.grails;

import org.glowroot.agent.plugin.api.*;
import org.glowroot.agent.plugin.api.ThreadContext.Priority;
import org.glowroot.agent.plugin.api.weaving.*;

public class GrailsControllerClassAspect {

@Shim("grails.core.GrailsControllerClass")
public interface GrailsControllerClass {
String getDefaultAction();

String getName();
}

@Pointcut(className = "grails.core.GrailsControllerClass",
methodName = "invoke",
methodParameterTypes = {"java.lang.Object", "java.lang.String"}, timerName = "grails controller")
public static class ControllerAdvice {
private static final TimerName timerName = Agent.getTimerName(ControllerAdvice.class);

@OnBefore
public static TraceEntry onBefore(ThreadContext context, @BindReceiver GrailsControllerClass grailsController,
@BindParameter Object controller, @BindParameter String action) {
String controllerName = grailsController.getName();
String actionName = action == null ? grailsController.getDefaultAction() : action;
context.setTransactionName(controllerName + "/" + actionName, Priority.CORE_PLUGIN);

return context.startTraceEntry(MessageSupplier.from("grails controller: {}.{}()",
controllerName,
actionName), timerName);
}

@OnReturn
public static void onReturn(@BindTraveler TraceEntry traceEntry) {
traceEntry.end();
}

@OnThrow
public static void onThrow(@BindThrowable Throwable throwable, @BindTraveler TraceEntry traceEntry) {
traceEntry.endWithError(throwable);
}
}
}
@@ -0,0 +1,7 @@
{
"name": "Grails Plugin",
"id": "grails",
"aspects": [
"org.glowroot.agent.plugin.grails.GrailsControllerClassAspect"
]
}
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<!-- unit tests do not log to console when running from maven in order to avoid logging expected
warnings and errors which can be confusing to new users building glowroot from source -->
<if condition='!property("glowroot.test.fileLoggingOnly").equals("true")'>
<then>
<appender name="CONSOLE" class="org.glowroot.agent.shaded.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root>
<appender-ref ref="CONSOLE" />
</root>
</then>
</if>
<appender name="FILE" class="org.glowroot.agent.shaded.qos.logback.core.FileAppender">
<file>target/glowroot.log</file>
<!-- prudent is needed since some tests are run in a separate JVM (using JavaagentContainer)
and these use the same logback configuration and log to the same file -->
<prudent>true</prudent>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="FILE" />
</root>
</configuration>
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<!-- unit tests do not log to console when running from maven in order to avoid logging expected
warnings and errors which can be confusing to new users building glowroot from source -->
<if condition='!property("glowroot.test.fileLoggingOnly").equals("true")'>
<then>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root>
<appender-ref ref="CONSOLE" />
</root>
</then>
</if>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/glowroot.log</file>
<!-- prudent is needed since some tests are run in a separate JVM (using JavaagentContainer)
and these use the same logback configuration and log to the same file -->
<prudent>true</prudent>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="FILE" />
</root>
</configuration>
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -60,6 +60,7 @@
<module>agent-parent/plugins/quartz-plugin</module>
<module>agent-parent/plugins/servlet-plugin</module>
<module>agent-parent/plugins/spring-plugin</module>
<module>agent-parent/plugins/grails-plugin</module>
<module>agent-parent/plugins/struts-plugin</module>
<module>agent-parent/benchmarks</module>
<module>agent-parent/webdriver-tests</module>
Expand Down