Tuesday, August 27, 2013

Spring Insight on Tomcat failing to start

Spring Insight is a powerful tool to record timing data for web applications deployed on a Spring server, but can also be used on Tomcat.
However, it does require a large amount of configuration before it will run correctly on a Tomcat deployment.
One exception that caused me a large amount of grief was the descriptive java.lang.NullPointerException at java.io.File.(File.java:222) at com.springsource.insight.collection.tcserver.ltw.TomcatWeavingInsightClassLoader.readInsightConfig(TomcatWeavingInsightClassLoader.java:67) at com.springsource.insight.collection.tcserver.ltw.TomcatWeavingInsightClassLoader.start(TomcatWeavingInsightClassLoader.java:50)
  Fortunately the source code for all Spring products is available to download at http://maven.springframework.org/release/com/springsource/ I am using Insight 1.5.1.SR2, and the source for the TomcatWeavingInsightClassLoader class is in the insight-collection project at http://maven.springframework.org/release/com/springsource/insight/insight-collection-tcserver/1.5.1.SR2/insight-collection-tcserver-1.5.1.SR2-sources.jar Examining the class, on line 67 we can see the following File insightDir = new File(System.getProperty("insight.base")); So Insight is looking for the insight root directory in your deployment, which can be set at run time. To resolve the problem, add the system parameter "insight.base" to your tomcat startup with the value of the insight directory in the deployment, e.g. "-Dinsight.base=C:\tomcat\insight"

Monday, August 12, 2013

Persist timing data from Spring Insight

Spring Insight is a powerful tool for tracing time spent in various methods during the progress of a web application call. While you can export traces from the Insight UI, the resultant file is in binary format, and can only be opened with the Insight UI itself. Fortunately, there is a workaround if you want to persist the data recorded during a call.
Insight adds extra headers to the repsonse object from a call - X-TraceId and X-TraceUrl. The traceId is (unsurprisingly) the id of the compelted trace and the trace url is a link to the trace on the Insight server that is in the form "/insight/services/traces/?type=[json|xml] with json as the default.
If you enter this url into your browser, the Insight server will return the data from the call in the selected format.
If you can access the response headers programattically (e.g. in a headerless browser, or using a proxy) you will be able to access the X-TraceId and X-TraceUrl values and from there can request and persist the Insight data.