3. Real User Monitoring
For the Real User Monitoring (RUM) instrumentation, we will add the Open Telemetry Javascript https://github.com/signalfx/splunk-otel-js-web snippet in the pages, we will use the wizard again Data Management → Add Integration → RUM Instrumentation → Browser Instrumentation.
Your instructor will inform you which token to use from the dropdown, click Next. Enter App name and Environment using the following syntax:
<INSTANCE>-petclinic-service
- replacing<INSTANCE>
with the value you noted down earlier.<INSTANCE>-petclinic-env
- replacing<INSTANCE>
with the value you noted down earlier.
The wizard will then show a snippet of HTML code that needs to be placed at the top of the pages in the <head>
section. The following is an example of the (do not use this snippet, use the one generated by the wizard):
/*
IMPORTANT: Replace the <version> placeholder in the src URL with a
version from https://github.com/signalfx/splunk-otel-js-web/releases
*/
<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script>
<script>
SplunkRum.init({
realm: "eu0",
rumAccessToken: "<redacted>",
applicationName: "petclinic-1be0-petclinic-service",
deploymentEnvironment: "petclinic-1be0-petclinic-env"
});
</script>
The Spring PetClinic application uses a single HTML page as the “layout” page, that is reused across all pages of the application. This is the perfect location to insert the Splunk RUM Instrumentation Library as it will be loaded in all pages automatically.
Let’s then edit the layout page:
vi src/main/resources/templates/fragments/layout.html
Next, insert the snippet we generated above in the <head>
section of the page. Make sure you don’t include the comment and replace <version>
in the source URL to latest
e.g.
<!doctype html>
<html th:fragment="layout (template, menu)">
<head>
<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script>
<script>
SplunkRum.init({
realm: "eu0",
rumAccessToken: "<redacted>",
applicationName: "petclinic-1be0-petclinic-service",
deploymentEnvironment: "petclinic-1be0-petclinic-env"
});
</script>
...
With the code changes complete, we need to rebuild the application and run it again. Run the maven
command to compile/build/package PetClinic:
./mvnw package -Dmaven.test.skip=true
java \
-Dserver.port=8083 \
-Dotel.service.name=$INSTANCE-petclinic-service \
-Dotel.resource.attributes=deployment.environment=$INSTANCE-petclinic-env,version=0.314 \
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
Then let’s visit the application using a browser to generate real-user traffic http://<IP_ADDRESS>:8083
.
In RUM, filter down into the environment as defined in the RUM snippet above and click through to the dashboard.
When you drill down into a RUM trace you will see a link to APM in the spans. Clicking on the trace ID will take you to the corresponding APM trace for the current RUM trace.