Setting Up RUM with Java
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Setting Up RUM with Java

  • Dark
    Light
  • PDF

Article Summary

This document details how to enable RUM for the APM Profiler in your Java application running on Linux or Windows.

Prerequisites

1. Install the Latest Version of the Agent and Profiler

Required Agent Versions
  • Windows Agent v4.32+
  • Linux Agent v2.31+
  • Java Profiler 1.33.6+

2. Enable RUM

Follow the RUM Getting Started guide to Enable RUM on your account

3. Setup APM for your Application

Follow the Java Getting Started Guide to configure the profiler for your specific setup. The profiler will need to be properly configured for RUM to function.

4. Configure the RUM Key

In order to identify the data coming from your application pages is tied to your account, you need to make your RUM Key available to your application. This setting is passed to your application via an environment variable, RETRACE_RUM_KEY.

Windows
Add the RETRACE_RUM_KEY to the machine Environment Variables. Its value is the RUM Key available in the Retrace RUM configuration screen.

Linux
Set the RETRACE_RUM_KEY environment variable so that it is available to the application when it launches. This will vary based on how the application is launched (e.g. via systemd or command line).

5. Add Script Injection to Your Application

The RUM implementation for Java requires a method call in the Stackify Java API library to be added to the pages that you want to report RUM data to Retrace.
JSP page script insertion
JSP pages require adding a call to com.stackify.apm.Stackify.getRUMJavaScriptBlock to the <head> section of each page that you would like tracked.

<html>
  <head>
	<%= com.stackify.apm.Stackify.getRUMJavaScriptBlock() %>
	<title>JSP Sample Page</title>
  </head>
...

Spring with ThymeLeaf script insertion

<html>
  <head>
	<th:block th:utext="${T(com.stackify.apm.Stackify).getRUMJavaScriptBlock()}">
	<title>JSP Sample Page</title>
  </head>
...

JSF Facelets
In order to use the RUM injection with Facelets, you will need to expose our static method as a function taglib. To do that you will need to create a retrace.taglib.xml file in the WEB-INF folder of your application with these contents:

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
    	xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    	version="2.0">
	<namespace>http://stackify.com/functions</namespace>
 
	<function>
    	<function-name>getRUMJavaScriptBlock</function-name>
    	<function-class>com.stackify.apm.Stackify</function-class>
    	<function-signature>java.lang.String getRUMJavaScriptBlock()</function-signature>
	</function>
 
</facelet-taglib>

Then you will need to reference this taglib in your web.xml file by adding the following:
<context-param> <param-name>javax.faces.FACELETS_LIBRARIES</param-name> <param-value>/WEB-INF/retrace.taglib.xml</param-value> </context-param>
Finally, in the pages that contain the <head> tag for the page that you want to report RUM data, you will need to add the namespace and insert the call as shown here:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:retrace="http://stackify.com/functions">
    <f:view contentType="text/html" encoding="UTF-8">
        <ui:insert name="metadata"></ui:insert>
        <h:head>
            <title>JakartaEE Faces Sample</title>
            <!-- Required meta tags -->
            <meta charset="utf-8"></meta>
            <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"></meta>
            <!-- Retrace RUM output Text -->
            <h:outputText escape="false" value="#{retrace:getRUMJavaScriptBlock()}"/>
...

6. Redeploy your App

Once the previous steps to enable RUM for your account and add the code snippet to your app(s) have been completed, the last step is to deploy the changes to your application.

Viewing RUM Data

Once the following steps have been taken to set up RUM for your apps, data will be reported in the corresponding App Dashboard. To see more information related to what RUM data is presented in the App Dashboard, see the Viewing RUM Data in Retrace help doc.


Was this article helpful?