Skip to content

Commit c8c36f8

Browse files
Merge pull request #60 from com-pas/58-contributing-frontend-monitoring
docs: implementing monitoring in compas-open-scd
2 parents ed53b4f + c5703b6 commit c8c36f8

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

docs/MONITORING.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
![Navigation instructions to APM in Kibana](/docs/public/kibana-screenshot-1.png)
16+
17+
In the top right corner of this page click on `Add data`:
18+
19+
![Navigation instructions to the Add data button in APM](/docs/public/kibana-screenshot-2.png)
20+
21+
Then scroll down to APM Agents and select `RUM (JS)`:
22+
23+
![Navigation instructions to the RUM Agent](/docs/public/kibana-screenshot-3.png)
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)

docs/_includes/sidebar.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ <h2>
4242
<li class="nav-list-item">
4343
<a class="sidebar-nav-item{% if page.url == '/ACCESS_TOKENS.html' %} active{% endif %}" href="{{ site.baseurl }}/ACCESS_TOKENS.html">Access Tokens</a>
4444
</li>
45+
<li class="nav-list-item">
46+
<a class="sidebar-nav-item{% if page.url == '/MONITORING.html' %} active{% endif %}" href="{{ site.baseurl }}/MONITORING.html">Monitoring</a>
47+
</li>
4548
</ul>
4649
</nav>
4750

870 KB
Loading
716 KB
Loading
1.32 MB
Loading

0 commit comments

Comments
 (0)