Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@datadog/browser-rum
Advanced tools
The @datadog/browser-rum package is a Real User Monitoring (RUM) solution provided by Datadog. It allows developers to collect and analyze performance and user behavior data from their web applications in real-time. This data can be used to identify and troubleshoot issues, improve user experience, and monitor application performance.
Real User Monitoring
Initializes the RUM SDK to start collecting data from the user's browser, including session replay recording.
import { datadogRum } from '@datadog/browser-rum';
datadogRum.init({
applicationId: 'YOUR_APPLICATION_ID',
clientToken: 'YOUR_CLIENT_TOKEN',
site: 'datadoghq.com',
service:'your-service-name',
// Specify a version number to identify the deployed version of your application in Datadog
version: '1.0.0',
sampleRate: 100,
trackInteractions: true,
});
datadogRum.startSessionReplayRecording();
Custom User Actions
Records custom user actions, such as button clicks, with additional context.
datadogRum.addAction('button_click', { buttonId: 'my-button' });
Logging Errors
Logs errors manually with additional context to help with debugging.
datadogRum.addError(new Error('Something went wrong'), {
context: {
productId: 123
}
});
User Tracking
Sets user information to track user-specific data and associate it with the collected RUM data.
datadogRum.setUser({
id: '1234',
name: 'John Doe',
email: 'john.doe@example.com',
// User-defined attributes
plan_type: 'premium',
});
Raygun4js is a JavaScript SDK for Raygun, providing error tracking and real user monitoring. It captures errors and performance data from the browser, offering a feature set that competes with @datadog/browser-rum, with a focus on error diagnosis and resolution.
Datadog Real User Monitoring (RUM) enables you to visualize and analyze the real-time performance and user journeys of your application's individual users. To collect events, add the RUM Browser SDK to your browser application and configure what data is collected using initialization parameters.
The RUM Browser SDK supports all modern desktop and mobile browsers including IE11. For more information, see the Browser Support table.
To set up RUM Browser Monitoring, create a RUM application:
clientToken
and an applicationId
for your application.Until Datadog starts receiving data, your application appears as pending
on the RUM Applications page.
npm (node package manager) : This method is recommended for modern web applications. The RUM Browser SDK is packaged with the rest of your front-end JavaScript code. It has no impact on page load performance. However, the SDK may miss errors, resources, and user actions triggered before the SDK is initialized. Datadog recommends using a matching version with the Browser Logs SDK.
CDN async : This method is recommended for web applications with performance targets. The RUM Browser SDK loads from our CDN asynchronously, ensuring the SDK download does not impact page load performance. However, the SDK may miss errors, resources, and user actions triggered before the SDK is initialized.
CDN sync : This method is recommended for collecting all RUM events. The RUM Browser SDK loads from our CDN synchronously, ensuring the SDK loads first and collects all errors, resources, and user actions. This method may impact page load performance.
Add @datadog/browser-rum
to your package.json
file, then initialize it with:
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
applicationId: '<DATADOG_APPLICATION_ID>',
clientToken: '<DATADOG_CLIENT_TOKEN>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sessionSampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
trackUserInteractions: true,
})
v4.30.0
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
applicationId: '<DATADOG_APPLICATION_ID>',
clientToken: '<DATADOG_CLIENT_TOKEN>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
trackInteractions: true,
})
v4.20.0
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
applicationId: '<DATADOG_APPLICATION_ID>',
clientToken: '<DATADOG_CLIENT_TOKEN>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
premiumSampleRate: 100, // if not included, the default is 100
trackInteractions: true,
})
v4.10.2
import { datadogRum } from '@datadog/browser-rum'
datadogRum.init({
applicationId: '<DATADOG_APPLICATION_ID>',
clientToken: '<DATADOG_CLIENT_TOKEN>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
replaySampleRate: 100, // if not included, the default is 100
trackInteractions: true,
})
The trackUserInteractions
and trackFrustrations
parameters enable the automatic collection of user clicks in your application. Sensitive and private data contained in your pages may be included to identify the elements interacted with.
Add the generated code snippet to the head tag of every HTML page you want to monitor in your application.
<script>
(function(h,o,u,n,d) {
h=h[d]=h[d]||{q:[],onReady:function(c){h.q.push(c)}}
d=o.createElement(u);d.async=1;d.src=n
n=o.getElementsByTagName(u)[0];n.parentNode.insertBefore(d,n)
})(window,document,'script','https://www.datadoghq-browser-agent.com/datadog-rum-v4.js','DD_RUM')
DD_RUM.onReady(function() {
DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sessionSampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
trackUserInteractions: true,
})
})
</script>
v4.30.0
<script>
(function(h,o,u,n,d) {
h=h[d]=h[d]||{q:[],onReady:function(c){h.q.push(c)}}
d=o.createElement(u);d.async=1;d.src=n
n=o.getElementsByTagName(u)[0];n.parentNode.insertBefore(d,n)
})(window,document,'script','https://www.datadoghq-browser-agent.com/datadog-rum-v4.js','DD_RUM')
DD_RUM.onReady(function() {
DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
trackInteractions: true,
})
})
</script>
v4.20.0
<script>
(function(h,o,u,n,d) {
h=h[d]=h[d]||{q:[],onReady:function(c){h.q.push(c)}}
d=o.createElement(u);d.async=1;d.src=n
n=o.getElementsByTagName(u)[0];n.parentNode.insertBefore(d,n)
})(window,document,'script','https://www.datadoghq-browser-agent.com/datadog-rum-v4.js','DD_RUM')
DD_RUM.onReady(function() {
DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
premiumSampleRate: 100, // if not included, the default is 100
trackInteractions: true,
})
})
</script>
v4.10.2
<script>
(function(h,o,u,n,d) {
h=h[d]=h[d]||{q:[],onReady:function(c){h.q.push(c)}}
d=o.createElement(u);d.async=1;d.src=n
n=o.getElementsByTagName(u)[0];n.parentNode.insertBefore(d,n)
})(window,document,'script','https://www.datadoghq-browser-agent.com/datadog-rum-v4.js','DD_RUM')
DD_RUM.onReady(function() {
DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
replaySampleRate: 100, // if not included, the default is 100
trackInteractions: true,
})
})
</script>
The trackUserInteractions
and trackFrustrations
parameters enable the automatic collection of user clicks in your application. Sensitive and private data contained in your pages may be included to identify the elements interacted with.
Early RUM API calls must be wrapped in the DD_RUM.onReady()
callback. This ensures the code only gets executed once the SDK is properly loaded.
Add the generated code snippet to the head tag (in front of any other script tags) of every HTML page you want to monitor in your application. Including the script tag higher and synchronized ensures Datadog RUM can collect all performance data and errors.
<script src="https://www.datadoghq-browser-agent.com/datadog-rum-v4.js" type="text/javascript"></script>
<script>
window.DD_RUM &&
window.DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sessionSampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
trackUserInteractions: true,
})
</script>
v4.30.0
<script src="https://www.datadoghq-browser-agent.com/datadog-rum-v4.js" type="text/javascript"></script>
<script>
window.DD_RUM &&
window.DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
trackInteractions: true,
})
</script>
v4.20.0
<script src="https://www.datadoghq-browser-agent.com/datadog-rum-v4.js" type="text/javascript"></script>
<script>
window.DD_RUM &&
window.DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
premiumSampleRate: 100, // if not included, the default is 100
trackInteractions: true,
})
</script>
v4.10.2
<script src="https://www.datadoghq-browser-agent.com/datadog-rum-v4.js" type="text/javascript"></script>
<script>
window.DD_RUM &&
window.DD_RUM.init({
clientToken: '<CLIENT_TOKEN>',
applicationId: '<APPLICATION_ID>',
site: '<DATADOG_SITE>',
// service: 'my-web-application',
// env: 'production',
// version: '1.0.0',
sampleRate: 100,
replaySampleRate: 100, // if not included, the default is 100
trackInteractions: true,
})
</script>
The trackUserInteractions
and trackFrustrations
parameters enable the automatic collection of user clicks in your application. Sensitive and private data contained in your pages may be included to identify the elements interacted with.
The window.DD_RUM
check is used to prevent issues if a loading failure occurs with the RUM Browser SDK.
Types are compatible with TypeScript >= 3.8.2. For earlier versions, import JavaScript sources and use global variables to avoid any compilation issues:
import '@datadog/browser-rum/bundle/datadog-rum'
window.DD_RUM.init({
applicationId: 'XXX',
clientToken: 'XXX',
site: 'datadoghq.com',
sessionSampleRate: 100,
sessionReplaySampleRate: 100, // if not included, the default is 100
trackResources: true,
trackLongTasks: true,
})
Call the initialization command to start tracking. The following parameters are available:
applicationId
: Required
Type: String
The RUM application ID.
clientToken
: Required
Type: String
A Datadog client token.
site
: Required
Type: String
Default: datadoghq.com
The Datadog site parameter of your organization.
service
: Optional
Type: String
The service name for your application. Follows the tag syntax requirements.
env
: Optional
Type: String
The application’s environment, for example: prod, pre-prod, and staging. Follows the tag syntax requirements.
version
: Optional
Type: String
The application’s version, for example: 1.2.3, 6c44da20, and 2020.02.13. Follows the tag syntax requirements.
trackViewsManually
: Optional
Type: Boolean
Default: false
Allows you to control RUM views creation. See override default RUM view names.
trackInteractions
: Optional - Deprecated
Type: Boolean
Default: false
See trackUserInteractions
.
trackUserInteractions
: Optional
Type: Boolean
Default: false
Enables automatic collection of users actions.
trackFrustrations
: Optional
Type: Boolean
Default: false
Enables automatic collection of user frustrations. Implies trackUserInteractions: true
.
trackResources
: Optional
Type: Boolean
Default: false
Enables collection of resource events.
trackLongTasks
: Optional
Type: Boolean
Default: false
Enables collection of long task events.
defaultPrivacyLevel
: Optional
Type: String
Default: mask-user-input
See Session Replay Privacy Options.
actionNameAttribute
: Optional
Type: String
Specify your own attribute to be used to name actions.
sampleRate
: Optional - Deprecated
Type: Number
Default: 100
See ``sessionSampleRate`.
sessionSampleRate
: Optional
Type: Number
Default: 100
The percentage of sessions to track: 100
for all, 0
for none. Only tracked sessions send RUM events. For more details about sessionSampleRate
, see the sampling configuration.
replaySampleRate
: Optional - Deprecated
Type: Number
Default: 100
See sessionReplaySampleRate
.
premiumSampleRate
: Optional - Deprecated
Type: Number
Default: 100
See sessionReplaySampleRate
.
sessionReplaySampleRate
: Optional
Type: Number
Default: 100
The percentage of tracked sessions with Browser RUM & Session Replay pricing features: 100
for all, 0
for none. For more details about sessionReplaySampleRate
, see the sampling configuration.
silentMultipleInit
: Optional
Type: Boolean
Default: false
Initialization fails silently if the RUM Browser SDK is already initialized on the page.
proxyUrl
: Optional
Type: String
Optional proxy URL, for example: https://www.proxy.com/path. For more information, see the full proxy setup guide.
allowedTracingOrigins
: Optional - Deprecated
Type: List
A list of request origins used to inject tracing headers. For more information, see Connect RUM and Traces.
allowedTracingUrls
: Optional
Type: List
A list of request URLs used to inject tracing headers. For more information, see Connect RUM and Traces.
tracingSampleRate
: Optional - Deprecated
Type: Number
Default: 100
See traceSampleRate
.
traceSampleRate
: Optional
Type: Number
Default: 100
The percentage of requests to trace: 100
for all, 0
for none. For more information, see Connect RUM and Traces.
telemetrySampleRate
: Optional
Type: Number
Default: 20
Telemetry data (such as errors and debug logs) about SDK execution is sent to Datadog in order to detect and solve potential issues. Set this option to 0
to opt out from telemetry collection.
excludedActivityUrls
: Optional
Type: List
A list of request origins ignored when computing the page activity. See How page activity is calculated.
Options that must have matching configuration when you are using the Logs Browser SDK:
trackSessionAcrossSubdomains
: Optional
Type: Boolean
Default: false
Preserve the session across subdomains for the same site.
useSecureSessionCookie
: Optional
Type: Boolean
Default: false
Use a secure session cookie. This disables RUM events sent on insecure (non-HTTPS) connections.
useCrossSiteSessionCookie
: Optional
Type: Boolean
Default:false
Use a secure cross-site session cookie. This allows the RUM Browser SDK to run when the site is loaded from another one (iframe). Implies useSecureSessionCookie
.
A service is an independent, deployable code repository that maps to a set of pages.
After the Datadog browser RUM SDK is initialized, you can access the internal context of the SDK.
You can explore the following attributes:
Attribute | Description |
---|---|
application_id | ID of the application. |
session_id | ID of the session. |
user_action | Object containing action ID (or undefined if no action is found). |
view | Object containing details about the current view event. |
For more information, see RUM Browser Data Collected.
{
application_id : "xxx",
session_id : "xxx",
user_action: { id: "xxx" },
view : {
id : "xxx",
referrer : "",
url: "http://localhost:8080/",
name: "homepage"
}
}
You can optionally use startTime
parameter to get the context of a specific time. If the parameter is omitted, the current context is returned.
getInternalContext (startTime?: 'number' | undefined)
For NPM, use:
import { datadogRum } from '@datadog/browser-rum'
datadogRum.getInternalContext() // { session_id: "xxxx", application_id: "xxxx" ... }
For CDN async, use:
DD_RUM.onReady(function () {
DD_RUM.getInternalContext() // { session_id: "xxxx", application_id: "xxxx" ... }
})
For CDN sync, use:
window.DD_RUM && window.DD_RUM.getInternalContext() // { session_id: "xxxx", application_id: "xxxx" ... }
{{< partial name="whats-next/whats-next.html" >}}
FAQs
Unknown package
We found that @datadog/browser-rum demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.