API reference for Splunk RUM browser agent
Use the following methods to configure the Splunk RUM browser agent for manual instrumentation.
This is the reference page for the Splunk RUM browser agent manual instrumentation methods. It contains a description, syntax, and an example for each method. For more examples targeted at specific use cases, see Manually instrument browser-based web applications.
try ... catch blocks can prevent your application from crashing.addEventListener
- Description
Registers an event listener. Event listeners take an object in the form
{ payload: { /* Depending on event */ }}as the first parameter.- Syntax
SplunkRum.addEventListener(type: string, listener: Function): void SplunkRum.removeEventListener(type: string, listener: Function): voidEvent
Payload
Description
'session-changed'sessionId: string (New session ID)Emitted when the session ID changes.
'global-attributes-changed'attributes: object (New global attributes)Emitted when
setGlobalAttributesis called.- Example
Add an event listener to track changes of session ID:
SplunkRum.addEventListener('session-changed', (event) => { LiveChat.setMetadata('splunk.sessionId', event.payload.sessionId); });
getGlobalAttributes
- Description
Gets all current global attributes in an
Attributesobject. It doesn't take arguments.- Syntax
SplunkRum.getGlobalAttributes(): Attributes;- Example
The following example shows how to use
getGlobalAttributesafter usingsetGlobalAttributes:SplunkRum.setGlobalAttributes({ 'enduser.id': 'Test User', }); SplunkRum.setGlobalAttributes({ 'dark_mode.enabled': darkModeToggle.status, }); const attrs = SplunkRum.getGlobalAttributes(); /* console.log(attrs) { 'enduser.id': 'Test User', 'dark_mode.enabled': true } */
getSessionId
- Description
Gets the current session ID. It doesn't take arguments.
- Syntax
SplunkRum.getSessionId(): string;- Example
The following example shows how to retrieve the session ID and add it to the application metadata:
LiveChat.onChatStarted(() => { LiveChat.setMetadata('splunk.sessionId', SplunkRum.getSessionId()); });
setGlobalAttributes
- Description
Adds a list of attributes to every new span. Use this method to add user metadata to spans. See Add user metadata using global attributes.
SplunkRum.setGlobalAttributes(attributes?: Attributes): void;Argument
Description
attributesObject of attributes added to all spans. If undefined, all current global attributes are deleted and no longer added to new spans.
- Syntax
SplunkRum.setGlobalAttributes(attributes?: Attributes): void;Argument
Description
attributesObject of attributes added to all spans. If undefined, all current global attributes are deleted and no longer added to new spans.
- Example
The following example sets different attributes to all new spans:
SplunkRum.setGlobalAttributes({ 'enduser.id': 'Test User', }); // All new spans now include enduser.id SplunkRum.setGlobalAttributes({ 'dark_mode.enabled': darkModeToggle.status, }); // All new spans now include enduser.id and dark_mode.enabled SplunkRum.setGlobalAttributes() // New spans no longer include those attributes
removeEventListener
- Description
Removes an event listener. See also:
addEventListener.- Syntax
SplunkRum.removeEventListener(type: string, listener: Function): void
Migrate to OpenTelemetry
If you have some existing manual instrumentation of your app you can translate the code to use OpenTelemetry conventions. See how in GitHub’s Migrating Manual Instrumentation .