API reference for Browser RUM instrumentation ๐
Use the following API methods when creating manual instrumentation for Splunk RUM for Browser. For manual instrumentation examples, see Manually instrument browser-based web applications.
Note
try ... catch
blocks can prevent your app from crashing when using the CDN version of Browser RUM.
Methods ๐
setGlobalAttributes ๐
The setGlobalAttributes
method adds a list of attributes to every new span. For example, you can use this method to add user metadata to spans. See Add user metadata using global attributes.
SplunkRum.setGlobalAttributes(attributes?: Attributes): void;
Argument |
Description |
---|---|
|
Object of attributes added to all spans. If undefined, all current global attributes are deleted and no longer added to new spans. |
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
getGlobalAttributes ๐
The getGlobalAttributes
method retrieves all current global attributes and returns an Attributes
object with attributes. It doesnโt take arguments.
SplunkRum.getGlobalAttributes(): Attributes;
The following example shows how to use getGlobalAttributes
after using setGlobalAttributes
:
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 ๐
The getSessionId
method retrieves the current session ID. It doesnโt take arguments.
SplunkRum.getSessionId(): string;
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());
});
addEventListener and removeEventListener ๐
You can register event listeners with addEventListener
and remove them using removeEventListener
.
Event listeners take an object in the form { payload: { /* Depending on event */ }}
as the first parameter.
SplunkRum.addEventListener(type: string, listener: Function): void
SplunkRum.removeEventListener(type: string, listener: Function): void
Event |
Payload |
Description |
---|---|---|
|
|
Emitted when the session ID changes. |
|
|
Emitted when |
The following example shows how to add an event listener to track changes of session ID:
SplunkRum.addEventListener('session-changed', (event) => {
LiveChat.setMetadata('splunk.sessionId', event.payload.sessionId);
});
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 .