|
| 1 | +# Monitoring |
| 2 | +## Table of contents |
| 3 | +* [Frontend monitoring](#introduction) |
| 4 | + 1. [Getting your APM Server URL](#1-getting-your-apm-server-url) |
| 5 | + 2. [Using the /public/init-js script](#2-using-the-publicinit-js-script) |
| 6 | + 3. [References](#3-references) |
| 7 | + |
| 8 | + |
| 9 | +## Frontend monitoring <a name="introduction"></a> |
| 10 | +This section suggests an approach for using Elastic's Real User Monitoring (RUM) in order to capture user interactions with our client-side application CoMPAS-OpenSCD. The following instructions assume you/your organization already count on a hosted Elasticsearch Service deployment or an Elastic Cloud organization account with Kibana as the frontend of your monitoring stack and a URL to access it. Also it is assumed that you deploy `compas-open-scd` by using Kubernetes (and [the compas-open-scd docker public docker image](https://hub.docker.com/r/lfenergy/compas-open-scd) or your own generated image). |
| 11 | + |
| 12 | +### 1. Getting your APM Server URL <a name="server-url"></a> |
| 13 | +Navigate to your Kibana URL and select the space that you would like to associate with your frontend app (default if you don't have several spaces in Kibana). Then open the drawer menu and navigate to `APM`: |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +In the top right corner of this page click on `Add data`: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +Then scroll down to APM Agents and select `RUM (JS)`: |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +There are two suggested code blocks for setting up the RUM Agent, find in any of them the `serverUrl` param and copy/paste it somewhere in your notes, we will use this URL later in a posterior step. |
| 26 | + |
| 27 | +*Note: You have two options for getting your init script, you either install the `@elastic/apm-rum` dependency in your project or you set up the agent with `<script>` tags. In this document we will describe an approach for the latter.* |
| 28 | + |
| 29 | +### 2. Using the /public/init-js script <a name="init-js"></a> |
| 30 | + |
| 31 | +The __compas-open-scd__ project features a reference to an "empty" javascript resource at `index.html` (line:42) |
| 32 | +```html |
| 33 | + <script src="./public/init-js/init.js"></script> |
| 34 | +``` |
| 35 | + |
| 36 | +This init javascript file has the purpose to allow for dynamic configuration of each compas-open-scd deployment. |
| 37 | + |
| 38 | +Make sure to include in your `init.js` file the following code: |
| 39 | + |
| 40 | +```js |
| 41 | +const script = document.createElement('script'); |
| 42 | +script.type = 'text/javascript'; |
| 43 | +// download and host your preffered RUM Agent version minified from https://github.com/elastic/apm-agent-rum-js/releases |
| 44 | +script.src = 'https://your-cdn-host.com/path/to/elastic-apm-rum.umd.min.js'; |
| 45 | +script.async = true; |
| 46 | +script.crossorigin = "anonymous"; // provides support for CORS |
| 47 | +script.onload = function () { |
| 48 | + elasticApm.init({ |
| 49 | + serviceName: 'compas-open-scd', // or preferred name, this will be used to filter out results in Kibana |
| 50 | + serverUrl: 'https://your-own-serverUrl.with.a.specific:port', // replace with serverUrl found in Step 1 |
| 51 | + environment: 'test', // The environment where the service being monitored is deployed, e.g. 'production', 'development', 'test', etc. Default: '' |
| 52 | + }); |
| 53 | +} |
| 54 | +document.querySelector('head').appendChild(script); |
| 55 | +``` |
| 56 | + |
| 57 | +### 3. References <a name="references"></a> |
| 58 | + |
| 59 | +* [Full documentation about APM Real User Monitoring JavaScript Agent](https://www.elastic.co/guide/en/apm/agent/rum-js/5.x/intro.html) |
| 60 | + |
| 61 | +* [Full APM Guide](https://www.elastic.co/guide/en/apm/guide/8.6/apm-quick-start.html) |
| 62 | + |
| 63 | +* [@stefvnf's medium blog post about cloning git repos using Kubernetes initContainers and Secrets](https://stefvnf.medium.com/cloning-git-repos-using-kubernetes-initcontainers-and-secrets-8609e3b2d238) |
0 commit comments