|
2 | 2 | title: Real User Monitoring |
3 | 3 | linkTitle: 8. Real User Monitoring |
4 | 4 | weight: 9 |
5 | | -hidden: true |
| 5 | +hidden: false |
6 | 6 | --- |
7 | 7 |
|
8 | 8 | ## 1. Enable RUM |
9 | 9 |
|
10 | | -For the Real User Monitoring (RUM) instrumentation, we will add the Open Telemetry Javascript [**https://github.com/signalfx/splunk-otel-js-web**](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**. |
| 10 | +To enable Real User Monitoring (RUM) instrumentation for your application, you need to add the Open Telemetry Javascript [**https://github.com/signalfx/splunk-otel-js-web**](https://github.com/signalfx/splunk-otel-js-web) snippet in the web pages. |
11 | 11 |
|
12 | | -Your instructor will inform you which token to use from the dropdown, click **Next**. Enter **App name** and **Environment** using the following syntax: |
| 12 | +The Spring PetClinic application uses a single HTML page as the "index" 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. |
| 13 | +For our workshop we will use the following snippet to the **HEAD** section of the index.html page to achieve the desired integration |
13 | 14 |
|
14 | | -- `<INSTANCE>-petclinic-service` - replacing `<INSTANCE>` with the value you noted down earlier. |
15 | | -- `<INSTANCE>-petclinic-env` - replacing `<INSTANCE>` with the value you noted down earlier. |
| 15 | +``` html |
| 16 | +<script src="env.js"></script> |
| 17 | + <script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script> |
| 18 | + <script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web-session-recorder.js" crossorigin="anonymous"></script> |
| 19 | + <script> |
| 20 | + var realm = env.RUM_REALM; |
| 21 | + console.log('Realm:', realm); |
| 22 | + var auth = env.RUM_AUTH; |
| 23 | + var appName = env.RUM_APP_NAME; |
| 24 | + var environmentName = env.RUM_ENVIRONMENT |
| 25 | + if (realm && auth) { |
| 26 | + window.SplunkRum && window.SplunkRum.init({ |
| 27 | + beaconUrl: 'https://rum-ingest.' + realm + '.signalfx.com/v1/rum', |
| 28 | + rumAuth: auth, |
| 29 | + app: appName, |
| 30 | + version: '1', |
| 31 | + environment: environmentName |
| 32 | +
|
| 33 | + }); |
| 34 | + SplunkSessionRecorder.init({ |
| 35 | + beaconUrl: 'https://rum-ingest.' + realm + '.signalfx.com/v1/rumreplay', |
| 36 | + rumAuth: auth |
| 37 | + }); |
| 38 | + const Provider = SplunkRum.provider; |
| 39 | + var tracer=Provider.getTracer('appModuleLoader'); |
| 40 | + } else { |
| 41 | + // Realm or auth is empty, provide default values or skip initialization |
| 42 | + console.log("Realm or auth is empty. Skipping SplunkRum initialization."); |
| 43 | + } |
| 44 | + </script> |
| 45 | +``` |
16 | 46 |
|
17 | | -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): |
| 47 | +To speed up the workshop we already added the snippet to the code in the Repo you have downloaded earlier, and you already have a build that includes this snippet when rebuild all the services in the previous exercise |
18 | 48 |
|
19 | | -``` html |
20 | | -/* |
21 | | - |
22 | | -IMPORTANT: Replace the <version> placeholder in the src URL with a |
23 | | -version from https://github.com/signalfx/splunk-otel-js-web/releases |
24 | | - |
25 | | -*/ |
26 | | -<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script> |
27 | | -<script> |
28 | | - SplunkRum.init({ |
29 | | - realm: "eu0", |
30 | | - rumAccessToken: "<redacted>", |
31 | | - applicationName: "petclinic-1be0-petclinic-service", |
32 | | - deploymentEnvironment: "petclinic-1be0-petclinic-env" |
33 | | - }); |
34 | | -</script> |
| 49 | +If you want you can verify the snippet we added to the index.html by viewing the file: |
| 50 | + |
| 51 | +{{< tabs >}} |
| 52 | +{{% tab title="view index.html [esc q to quit]" %}} |
| 53 | + |
| 54 | +``` bash |
| 55 | + view ~/spring-petclinic-microservices/spring-petclinic-api-gateway/src/main/resources/static/index.html |
35 | 56 | ``` |
36 | 57 |
|
37 | | -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. |
| 58 | +{{% /tab %}} |
| 59 | +{{< /tabs >}} |
| 60 | + |
| 61 | +Note, that we also include a env.js file, this contains/sets the variables used by the integration to the desired values, right now they are empty so the integration isn't loaded. and no Rum traces are sent to splunk.. |
| 62 | + |
| 63 | +Lets set the |
| 64 | + |
| 65 | +So, let's run the script that will update variables to the right value so we will see RUM traces in the Splunk Observability Suite RUM UI: |
38 | 66 |
|
39 | | -Let's then edit the layout page: |
| 67 | +{{< tabs >}} |
| 68 | +{{% tab title="Update env.js for RUM" %}} |
40 | 69 |
|
41 | | -```bash |
42 | | -vi src/main/resources/templates/fragments/layout.html |
| 70 | +``` bash |
| 71 | +. ~/workshop/petclinic/scripts/push_env.sh |
43 | 72 | ``` |
44 | 73 |
|
45 | | -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. |
46 | | - |
47 | | -```html |
48 | | -<!doctype html> |
49 | | -<html th:fragment="layout (template, menu)"> |
50 | | - |
51 | | -<head> |
52 | | -<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script> |
53 | | -<script> |
54 | | - SplunkRum.init({ |
55 | | - realm: "eu0", |
56 | | - rumAccessToken: "<redacted>", |
57 | | - applicationName: "petclinic-1be0-petclinic-service", |
58 | | - deploymentEnvironment: "petclinic-1be0-petclinic-env" |
59 | | - }); |
60 | | -</script> |
61 | | -... |
| 74 | +{{% /tab %}} |
| 75 | +{{% tab title=" Output" %}} |
| 76 | + |
| 77 | +```text |
| 78 | +Repository directory exists. |
| 79 | +JavaScript file generated at: /home/splunk/spring-petclinic-microservices/spring-petclinic-api-gateway/src/main/resources/static/scripts/env.js |
62 | 80 | ``` |
63 | 81 |
|
64 | | -## 2. Rebuild PetClinic |
| 82 | +{{% /tab %}} |
| 83 | +{{< /tabs >}} |
65 | 84 |
|
66 | | -With the code changes complete, we need to rebuild the application and run it again. Run the `maven` command to compile/build/package PetClinic: |
| 85 | +now to verify if the env.js has been created correctly lets review the file |
| 86 | +{{< tabs >}} |
| 87 | +{{% tab title="cat env.js" %}} |
67 | 88 |
|
68 | | -```bash |
69 | | -./mvnw package -Dmaven.test.skip=true |
| 89 | +``` bash |
| 90 | +cat ~/spring-petclinic-microservices/spring-petclinic-api-gateway/src/main/resources/static/scripts/env.js |
70 | 91 | ``` |
71 | 92 |
|
72 | | -```bash |
73 | | -java \ |
74 | | --Dserver.port=8083 \ |
75 | | --Dotel.service.name=$INSTANCE-petclinic-service \ |
76 | | --Dotel.resource.attributes=deployment.environment=$INSTANCE-petclinic-env,version=0.314 \ |
77 | | --jar target/spring-petclinic-*.jar --spring.profiles.active=mysql |
| 93 | +{{% /tab %}} |
| 94 | +{{% tab title=" Output" %}} |
| 95 | + |
| 96 | + |
| 97 | + env = { |
| 98 | + RUM_REALM: 'eu0', |
| 99 | + RUM_AUTH: '[redacted]', |
| 100 | + RUM_APP_NAME: 'ph-zeroconf-dev-eu0-1-1-store', |
| 101 | + RUM_ENVIRONMENT: 'ph-zeroconf-dev-eu0-1-1-workshop' |
| 102 | +} |
78 | 103 | ``` |
79 | 104 |
|
80 | | -Then let's visit the application using a browser to generate real-user traffic `http://<IP_ADDRESS>:8083`. |
| 105 | +{{% /tab %}} |
| 106 | +{{< /tabs >}} |
| 107 | +
|
| 108 | +
|
| 109 | +Now restart the api-serveic |
| 110 | +
|
| 111 | +```text |
| 112 | + kubctl whatever to restart the container.. |
| 113 | +``` |
81 | 114 |
|
82 | 115 | In RUM, filter down into the environment as defined in the RUM snippet above and click through to the dashboard. |
83 | 116 |
|
|
0 commit comments