diff --git a/README.md b/README.md index c7dc57fb7..0daa72217 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ To interact with Datadog directly from your builds. - [Error Tracking](#error-tracking-----) - [Metrics](#metrics-----) - [Output](#output-----) + - [RUM](#rum-----) - [Contributing](#contributing) - [License](#license) @@ -137,6 +138,14 @@ Follow the specific documentation for each bundler: warnings?: boolean | string; }; }; + rum?: { + enable?: boolean; + sdk?: { + applicationId: string; + clientToken?: string; + // [...] See https://docs.datadoghq.com/real_user_monitoring/browser/setup/client?tab=rum#configuration for all options. + }; + }; } ``` @@ -372,6 +381,34 @@ datadogWebpackPlugin({ }); ``` + + +### RUM ESBuild Rollup Rspack Vite Webpack + +> [!NOTE] +> This feature is in **beta** and may misbehave in edgiest cases. +>
+> Interact with Real User Monitoring (RUM) directly from your build system. + +#### [📝 Full documentation ➡️](/packages/plugins/rum#readme) + +
+ +Configuration + +```typescript +datadogWebpackPlugin({ + rum?: { + enable?: boolean, + sdk?: { + applicationId: string, + clientToken?: string, + // [...] See https://docs.datadoghq.com/real_user_monitoring/browser/setup/client?tab=rum#configuration for all options. + }, + } +}); +``` +
diff --git a/packages/plugins/rum/README.md b/packages/plugins/rum/README.md new file mode 100644 index 000000000..dc141d9c9 --- /dev/null +++ b/packages/plugins/rum/README.md @@ -0,0 +1,100 @@ +# RUM Plugin + +> [!NOTE] +> This feature is in **beta** and may misbehave in edgiest cases. + +Interact with Real User Monitoring (RUM) directly from your build system. + + + +## Table of content + + + + +- [Configuration](#configuration) +- [Browser SDK Injection](#browser-sdk-injection) + - [Using global `DD_RUM`](#using-global-ddrum) + - [rum.sdk.applicationId](#rumsdkapplicationid) + - [rum.sdk.clientToken](#rumsdkclienttoken) + + +## Configuration + +
+Full configuration + +```ts +rum?: { + enable?: boolean; + sdk?: { + applicationId: string; + clientToken?: string; + // [...] See https://docs.datadoghq.com/real_user_monitoring/browser/setup/client?tab=rum#configuration for all options. + }; +} +``` + +
+ +**Minimal configuration**: + +```ts +rum: { + sdk: { + applicationId: 'your_application_id', + } +} +``` + +## Browser SDK Injection + +Automatically inject the RUM SDK v6 into your application and initialize it. + +Full documentation can be found in the [Datadog documentation](https://docs.datadoghq.com/real_user_monitoring/browser/setup/client?tab=rum#configuration). + +### Using global `DD_RUM` + +You can use [the global `DD_RUM` object](https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=cdnasync) to interact with the RUM SDK. + +> [!NOTE] +> You don't need to use `DD_RUM.onReady()` to wrap your code, +> the plugin makes sure the SDK is loaded before executing your code. + +For TypeScript projects, you can declare the global type using the types bundled with the plugin: + +```ts +import type { RumTypes } from '@datadog/webpack-plugin'; // or rollup-plugin, vite-plugin, etc. + +declare global { + interface Window { + DD_RUM?: RumTypes['RumPublicApi']; + } +} +``` + +You can also configure `eslint` to recognize the global `DD_RUM` object: + +```json +{ + "globals": { + "DD_RUM": "readonly" + } +} +``` + +### rum.sdk.applicationId + +> required + +The RUM application ID. [Create a new application if necessary](https://app.datadoghq.com/rum/list/create). + +### rum.sdk.clientToken + +> optional, will be fetched if missing + +A [Datadog client token](https://docs.datadoghq.com/account_management/api-app-keys/#client-tokens). + +> [!NOTE] +> If not provided, the plugin will attempt to fetch the client token using the API. +> You need to provide both `auth.apiKey` and `auth.appKey` with the `rum_apps_read` permission. diff --git a/packages/plugins/rum/package.json b/packages/plugins/rum/package.json index 21937f9f8..6f95f5a87 100644 --- a/packages/plugins/rum/package.json +++ b/packages/plugins/rum/package.json @@ -12,7 +12,6 @@ "directory": "packages/plugins/rum" }, "buildPlugin": { - "hideFromRootReadme": true, "inlinedLibraries": [ "@datadog/browser-core", "@datadog/browser-rum-core" diff --git a/packages/plugins/rum/src/index.ts b/packages/plugins/rum/src/index.ts index e33bbca0b..249aadca7 100644 --- a/packages/plugins/rum/src/index.ts +++ b/packages/plugins/rum/src/index.ts @@ -21,7 +21,6 @@ export const helpers = { }; export type types = { - // Add the types you'd like to expose here. RumOptions: RumOptions; RumPublicApi: RumPublicApi; RumInitConfiguration: RumInitConfiguration; diff --git a/packages/plugins/rum/src/validate.ts b/packages/plugins/rum/src/validate.ts index ccaa994d5..8241be69c 100644 --- a/packages/plugins/rum/src/validate.ts +++ b/packages/plugins/rum/src/validate.ts @@ -2,7 +2,6 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2019-Present Datadog, Inc. -import type { Site } from '@datadog/browser-rum'; import type { Logger, Options, OptionsWithDefaults } from '@dd/core/types'; import chalk from 'chalk'; @@ -108,7 +107,7 @@ export const validateSDKOptions = ( sessionReplaySampleRate: 0, sessionSampleRate: 100, silentMultipleInit: false, - site: (options.auth.site as Site) || 'datadoghq.com', + site: options.auth.site || 'datadoghq.com', startSessionReplayRecordingManually: false, storeContextsAcrossPages: false, telemetrySampleRate: 20,