Package Exports
- @splunk/otel-web
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@splunk/otel-web) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Splunk distribution of OpenTelemetry JavaScript Browser
The Splunk distribution of OpenTelemetry JavaScript Browser provides a JavaScript file that can be added into a page that automatically captures:
- Document load information, including resource fetching
- User interactions (clicks)
- XmlHttpRequest (XHR) and fetch calls, including the full URL but not including any body/payload
- WebSocket activity
- Errors
By default, the following error sources are captured:
addEventListener('error')which reports unhandled errors (e.g., from setInterval callbacks)addEventListener('unhandledrejection')which reports unhandled Promise rejections- instrumenting usage of
console.error document.documentElement.addEventListener('error', ... {capture:true});which reports errors on DOM elements (e.g., image loading issue)
All data and errors captured are reported to Splunk RUM.
🚧 This project is currently in BETA.
Getting Started
To get started, download the JS file from the latest release and add its path to your page.
For example:
<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script>
<script>
SplunkRum.init({
beaconUrl: 'https://rum-ingest.<REALM>.signalfx.com/v1/rum',
rumAuth: '<RUM_ACCESS_TOKEN>',
app: '<YOUR_APPLICATION_NAME>'
});
</script>Please read INSTALLING.md for more advanced installation scenarios.
Supported browsers
Not all supported browsers support all features/attributes, but the following browsers are generally supported. We are actively working on expanding this list.
- Chrome 52+
- Safari 11+
- Firefox 57+
- Edge 79+
- IE not currently supported
Known issues
Auto-instrumentation doesn't currently capture events handled on document
level, ie. document.addEventListener(...).
Web Workers and Service Workers are not supported. Code loaded within them will not be auto-instrumented, and currently there is no version of the code which can be used within either Web or Service Workers for manual instrumentation.
Open Telemetry version
| @splunk/otel-web | @opentelemetry/api |
|---|---|
| 0.4.x | 0.18.x |
| 0.3.x | 0.18.x |
| 0.2.x | 0.18.x |
| 0.1.x | 0.15.x |
All configuration options
SplunkRum.init({ })
| Option | Type | Notes | Default |
|---|---|---|---|
| allowInsecureBeacon | boolean | Allows http beacon urls | false |
| app | string | Application name | 'unknown-browser-app' |
| beaconUrl | string (required) | Destination for the captured data | (No default) |
| cookieDomain | string | Sets session cookie to this domain | If unspecified, it defaults to the same host that set the cookie, excluding subdomains |
| debug | boolean | Turns on/off internal debug logging | false |
| environment | string | Sets a value for the environment attribute (persists through calls to setGlobalAttributes()) |
(No default) |
| exporter.onAttributesSerializing | (a: SpanAttributes, s: Span): SpanAttributes | Described in its own section | (s) => s.attributes |
| globalAttributes | object | Extra attributes to add to each reported span. See also setGlobalAttributes |
{} |
| ignoreUrls | array | Applies for XHR, Fetch and Websocket URLs. URLs that partially match any regex in ignoreUrls will not be traced. In addition, URLs that are exact matches of strings in ignoreUrls will also not be traced. | [] |
| instrumentations | { [moduleName]?: boolean or object } | Configuration for instrumentation modules. See following section for details. | |
| rumAuth | string (required) | Publicly-visible rumAuth value. Please do not paste any other access token or auth value into here, as this will be visible to every user of your app |
(No default) |
Capturing modules
Capturing modules can be configured by passing following values to instrumentations object in config:
false- disables this moduletrue- enables this module with default optionsobject- enables with additional options, which are described in the types definition
| Option | Default | Description |
|---|---|---|
| instrumentations.document | true | Capturing spans related to document loading |
| instrumentations.errors | true | Capturing errors |
| instrumentations.fetch | true | Capturing fetch requests |
| instrumentations.interactions | true | Capturing interactions |
| instrumentations.longtask | true | Capturing long task spans |
| instrumentations.websockets | false | Capturing websockets |
| instrumentations.webvitals | true | Capturing webvitals |
| instrumentations.xhr | true | Capturing XHR requests |
Additional configuration options are available for following modules:
User interactions
| Option | Type | Notes | Default |
|---|---|---|---|
| instrumentations.interactions.events | { [DOM Event Name]?: boolean } | Set keys to false to disable events handled by default. Set additional keys to true to auto-instrument addEventListener handlers. |
Please check window.SplunkRum.DEFAULT_AUTO_INSTRUMENTED_EVENTS |
SplunkRum.setGlobalAttributes(attributes)
You can (re)set globalAttributes at any time with this
method. Using it will overwrite specified properties and leave others unchanged.
Any spans reported from this point on will have your new attributes set.
You can pass undefined to clear your global attributes.
Redacting Personally Identifiable Information (PII)
In certain situations, metadata collected by our instrumentation may include PII. We'd advise that you review these cases in particular:
- any network operation, where a secret piece of information might be present in the URL (e.g. an authentication token); please note that we do not capture or report any data from the payload of the request (i.e. the POST body), apart from its size;
- any user interaction (e.g. a click), where a target element might contain a secret piece of information in its
id - error messages produced by your app (e.g., usage of
console.erroror strings passed to anErrorconstructor).
To redact PII you can pass an option when initializing.
SplunkRum.init({
...otherOptions,
exporter: {
onAttributesSerializing: (attributes, span) => ({
...attributes,
'http.url': /secret\=/.test(attributes['http.url']) ? '[redacted]' : attributes['http.url'],
}),
},
});For a working example see this integration test. Span is provided a second argument for your convenience.
Manual OpenTelemetry instrumentation
Tracing Provider
If you would like to manually instrument your application (for example, to
report timings for key events), you can use the
OpenTelemetry
API. Our TracingProvider is in SplunkRum.provider.
Example on how to manually instrument:
const provider = SplunkRum.provider;
const span = provider.getTracer('searchbox').startSpan('search');
span.setAttribute('searchLength', searchString.length);
// time passes
span.end();Errors
While many errors are captured by default, manual errors can be reported by using:
SplunkRum.error(errorObjectOrMessageString);Building and contributing
Please read CONTRIBUTING.md for instructions on building, running tests, and so forth.
License and versioning
The Splunk distribution of OpenTelemetry JavaScript Browser is a distribution of the OpenTelemetry JavaScript Browser project. It is released under the terms of the Apache Software License version 2.0. See the license file for more details.