Skip to content

Commit

Permalink
[docs] RUM JS documentation restructure (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorelli25 authored Dec 5, 2019
1 parent 777078a commit fd2fe83
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 179 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a placeholder file. Release notes are published in CHANGELOG.md
6 changes: 3 additions & 3 deletions docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ A list of instrumentations which can be disabled. Valid options are `xmlhttprequ

Environment where the service being monitored is deployed, e.g. "production", "development", "test", etc.

Environments allow you to easily filter data on a global level in the APM UI.
Environments allow you to easily filter data on a global level in the APM app.
It's important to be consistent when naming environments across agents.
See {kibana-ref}/filters.html#environment-selector[environment selector] in the Kibana UI for more information.
See {apm-app-ref}/filters.html#environment-selector[environment selector] in the APM app for more information.

NOTE: This feature is fully supported in the APM UI in Kibana versions >= 7.2.
NOTE: This feature is fully supported in the APM app in Kibana versions >= 7.2.
You must use the query bar to filter for a specific environment in versions prior to 7.2.

[float]
Expand Down
4 changes: 2 additions & 2 deletions docs/custom-transaction-name.asciidoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[custom-transaction-name]]
=== Custom initial page load transaction names

Correctly setting initial page load transaction names is vital to ensuring the best experience when viewing application performance metrics in the Kibana UI.
Correctly setting initial page load transaction names is vital to ensuring the best experience when viewing application performance metrics in the APM app.

Let's look at an example to understand why. Here are a few URLs you might find on elastic.co:

Expand All @@ -19,7 +19,7 @@ https://www.elastic.co/guide/en/infrastructure/guide/current/index.html
----

By default, <<transaction-name,`transaction.name`>> is set to `Unknown`.
This means that when viewing transactions in the Kibana UI,
This means that when viewing transactions in the APM app,
all transactions will be grouped under the common transaction name of `Unknown`.
Grouping every transaction (especially unrelated ones) into one group doesn't make much sense.
To fix this, you can use the API to change the default initial page load transaction name with the <<page-load-transaction-name,`pageLoadTransactionName`>> configuration option.
Expand Down
17 changes: 8 additions & 9 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
:branch: current
:server-branch: 6.5
include::{asciidoc-dir}/../../shared/versions/stack/current.asciidoc[]
include::{asciidoc-dir}/../../shared/attributes.asciidoc[]

ifdef::env-github[]
Expand All @@ -13,22 +12,22 @@ include::./intro.asciidoc[]

include::./supported-technologies.asciidoc[]

include::./sourcemap.asciidoc[]
include::./configuration.asciidoc[]

include::./api.asciidoc[]

include::./configuration.asciidoc[]
include::./sourcemap.asciidoc[]

include::./framework-integrations.asciidoc[]

include::./advanced-topics.asciidoc[]

include::./troubleshooting.asciidoc[]

include::./distributed-tracing-guide.asciidoc[]

include::./breakdown-metrics.asciidoc[]

include::./opentracing.asciidoc[]

include::./breakdown-metrics.asciidoc[]
include::./advanced-topics.asciidoc[]

include::./troubleshooting.asciidoc[]

include::./release-notes.asciidoc[]
165 changes: 21 additions & 144 deletions docs/intro.asciidoc
Original file line number Diff line number Diff line change
@@ -1,159 +1,36 @@
[[intro]]
== Introduction

Welcome to the APM Real User Monitoring (RUM) JavaScript Agent documentation.
The Elastic APM Real User Monitoring (RUM) JavaScript Agent provides detailed performance metrics and error tracking of your web applications.
It has built-in support for popular platforms and frameworks, and an API for custom instrumentation.

The Elastic APM RUM JavaScript agent sends performance metrics and errors to the APM Server.

NOTE: The APM JavaScript agent is compatible with APM Server v6.5+.

[float]
[[additional-components]]
=== Additional Components

APM Agents work in conjunction with the {apm-server-ref-v}/index.html[APM Server], {ref}/index.html[Elasticsearch], and {kibana-ref}/index.html[Kibana].
Please view the {apm-overview-ref-v}/index.html[APM Overview] for details on how these components work together.

You will also need to {apm-server-ref-v}/rum.html[enable frontend endpoints in the `apm-server` configuration].

[[getting-started]]
== Getting started

* <<using-package-managers>>
* <<using-script-tags>>
* <<using-production-build>>
* <<configuring-cors>>

[float]
[[using-package-managers]]
=== Using Package Managers

Install the APM agent for JavaScript as a dependency to your application:

[source,bash]
----
npm install @elastic/apm-rum --save
----

Configure the agent:

[source,js]
----
import { init as initApm } from '@elastic/apm-rum'
const apm = initApm({
// Set required service name (allowed characters: a-z, A-Z, 0-9, -, _, and space)
serviceName: '',
// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: 'http://localhost:8200',
// Set service version (required for sourcemap feature)
serviceVersion: ''
})
----

[float]
[[using-script-tags]]
=== Using Script Tags

Add a <script> tag to the HTML page and use the `elasticApm` global object to load and initialize the agent:

NOTE: Please download the latest version of JavaScript agent from https://github.com/elastic/apm-agent-rum-js/releases/latest[GitHub] or
https://unpkg.com/@elastic/apm-rum/dist/bundles/elastic-apm-rum.umd.min.js[UNPKG] and host the file in your Server/CDN before deploying to production.

[source,html]
----
<script src="https://your-cdn-host.com/path/to/elastic-apm-rum.umd.min.js" crossorigin></script>
<script>
elasticApm.init({
serviceName: '',
serverUrl: 'http://localhost:8200',
})
</script>
----

NOTE: Currently the optimized(minified + gzipped) JavaScript bundle size is about 16KiB.


[float]
[[using-production-build]]
=== Using Production Build

By default, RUM agent logs all the debug messages to the browser console. These logs are very useful in development. However, they make the RUM agent bundle size larger so you should make sure to use the optimized production version when deploying your application.

You can find instructions for building optimized code below for different bundlers

[float]
==== Webpack
For optimized webpack production build, include the Environment/Define plugin in the webpack configuration.

[source, js]
----
const { EnvironmentPlugin } = require('webpack')
plugins: [
new EnvironmentPlugin({
NODE_ENV: 'production'
})
]
----

You can learn more about this in https://webpack.js.org/plugins/environment-plugin[Webpack documentation].
The Agent also supports <<distributed-tracing-guide,distributed tracing>> for all outgoing requests.
This enables you to analyze performance throughout your microservice architecture -- all in one view.

[float]
==== Rollup

For optimized rollup production build, include the replace plugin which ensures the right build environment is used.
[[how-it-works]]
=== How does the Agent work?

[source, js]
----
const replace = require('rollup-plugin-replace')
The RUM Agent automatically instruments the following:

plugins: [
replace({
'process.env.NODE_ENV': 'production'
})
]
----
* Page load metrics
* Load time of Static Assets
* API requests (XMLHttpRequest and Fetch)

[float]
[[configuring-cors]]
=== Configuring CORS
The agent uses the https://developer.mozilla.org/en-US/docs/Web/API/Navigation_timing_API[Navigation Timing API]
and https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API[Resource Timing API]
available in the browser to instrument the page load performance and static assets load times.

If APM Server is deployed in an origin different than the page's origin,
you will need to configure Cross-Origin Resource Sharing (CORS).
To configure CORS, simply:
The agent automatically captures all outgoing http requests,
by instrumenting both XHR and Fetch API requests from the webpage to backend servers.

1. {apm-server-ref-v}/configuration-rum.html[Enable RUM support] in APM Server.
2. Adjust the {apm-server-ref-v}/configuration-rum.html#rum-allow-origins[`apm-server.rum.allow_origins`] configuration.
By default, APM Server allows all origins.
For all transactions, the agent automatically captures <<breakdown-metrics-docs, breakdown metrics>>.

[float]
==== How CORS works

When the RUM agent makes it's initial `POST` request, the browser will check to see if it is a cross-origin request.
If it is, the browser automatically makes a preflight `OPTIONS` request to the server to ensure the original `POST` request is allowed.
If this `OPTIONS` check passes, then the original `POST` request is allowed.
This request will fail if RUM support is not configured in the APM Server.

If you use a proxy, the preflight request headers may be necessary for your configuration:

[source,js]
----
Access-Control-Request-Headers: Content-Type
Access-Control-Request-Method: POST
Origin: [request-origin]
----

The response should include these headers:
[[additional-components]]
=== Additional Components

[source,js]
----
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST, OPTIONS
Access-Control-Allow-Origin: [request-origin]
----
APM Agents work in conjunction with the {apm-server-ref-v}/index.html[APM Server], {ref}/index.html[Elasticsearch], and {kibana-ref}/index.html[Kibana].
Please view the {apm-overview-ref-v}/index.html[APM Overview] for details on how these components work together.

TIP: To learn more about CORS, see the MDN page on
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS[Cross-Origin Resource Sharing].
include::./set-up.asciidoc[]
2 changes: 1 addition & 1 deletion docs/opentracing.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ but are relevant in the context of Elastic APM.

The following tags are relevant only to the root spans, which are
translated to Elastic APM transactions.
These tags appear in the "User" tab on the transaction details page in the Elastic APM UI.
These tags appear in the "User" tab on the transaction details page in the Elastic APM app.

- `user.id` - sets the user id
- `user.email` - sets the user email
Expand Down
Loading

0 comments on commit fd2fe83

Please sign in to comment.