@servicetitan/docs-uikit 40.2.2 → 40.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/BREAKING_CHANGES.mdx +1 -1
- package/docs/ajax-handlers/ajax-handlers.mdx +5 -2
- package/docs/ajax-handlers/init-ajax-handlers-common.mdx +22 -0
- package/docs/ajax-handlers/init-ajax-handlers-csrf-token.mdx +24 -0
- package/docs/ajax-handlers/init-ajax-handlers-login-required.mdx +2 -2
- package/docs/ajax-handlers/init-ajax-handlers-parse-dates.mdx +2 -1
- package/docs/ajax-handlers/init-ajax-handlers.mdx +186 -0
- package/docs/ajax-handlers/silent-login.mdx +41 -0
- package/docs/datadog-rum/api/api.mdx +24 -0
- package/docs/datadog-rum/api/before-send.mdx +36 -0
- package/docs/datadog-rum/api/datadog-provider.mdx +106 -0
- package/docs/datadog-rum/api/init.mdx +129 -0
- package/docs/datadog-rum/api/set-user.mdx +15 -0
- package/docs/datadog-rum/api/use-rum-service.mdx +33 -0
- package/docs/datadog-rum/datadog-rum.mdx +156 -0
- package/docs/datadog-rum/dev-runtime-enable.mdx +25 -0
- package/docs/launchdarkly-service.mdx +6 -0
- package/docs/startup/build/build.mdx +25 -1
- package/docs/startup/mfe-publish.mdx +2 -0
- package/docs/web-components/use-prefetch.mdx +2 -0
- package/package.json +1 -1
- package/docs/ajax-handlers/cancelation-handling.mdx +0 -43
- package/docs/datadog-rum.mdx +0 -465
package/docs/datadog-rum.mdx
DELETED
|
@@ -1,465 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: DataDog RUM
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
import Tabs from '@theme/Tabs';
|
|
6
|
-
import TabItem from '@theme/TabItem';
|
|
7
|
-
|
|
8
|
-
#### [CHANGELOG (@servicetitan/datadog-rum)](https://github.com/servicetitan/uikit/blob/master/packages/datadog-rum/CHANGELOG.md)
|
|
9
|
-
|
|
10
|
-
[`@servicetitan/datadog-rum`](https://github.com/servicetitan/uikit/tree/master/packages/datadog-rum) configures DataDog RUM JS SDK and enriches its events for application and MFE monitoring and troubleshooting. It supports standalone applications and hosts that share a single RUM session with the MFEs they load.
|
|
11
|
-
|
|
12
|
-
When a host loads MFEs (for example, the Monolith loading Task Hub), each MFE can register its own enrichment, tracing URLs, and persistent context through `init`. This avoids the failure mode where calling `datadogRum.init()` from more than one place would leak duplicate sessions and silently drop the second call's setup.
|
|
13
|
-
|
|
14
|
-
RUM events go through three enrichment stages: built-in attribution (MFE name, version, Cloudflare Ray ID), application-level handler, and per-service handlers.
|
|
15
|
-
|
|
16
|
-
## End-to-end example
|
|
17
|
-
|
|
18
|
-
<Tabs
|
|
19
|
-
defaultValue="host"
|
|
20
|
-
values={[
|
|
21
|
-
{ label: 'Host', value: 'host' },
|
|
22
|
-
{ label: 'MFE', value: 'mfe' },
|
|
23
|
-
]}
|
|
24
|
-
>
|
|
25
|
-
<TabItem value="host">
|
|
26
|
-
|
|
27
|
-
```ts title="datadog-entry.ts"
|
|
28
|
-
import { init } from '@servicetitan/datadog-rum';
|
|
29
|
-
|
|
30
|
-
export const isEnabled = /(?:^|\.)go\d*\.servicetitan\.com\.?$/i.test(window.location.hostname);
|
|
31
|
-
|
|
32
|
-
const desktopRegistration = init({
|
|
33
|
-
service: {
|
|
34
|
-
name: 'desktop',
|
|
35
|
-
beforeSend: event => {
|
|
36
|
-
// enrich with 'desktop' service-specific context
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
application: {
|
|
40
|
-
applicationId: '<APPLICATION_ID>',
|
|
41
|
-
clientToken: '<CLIENT_TOKEN>',
|
|
42
|
-
env: '<ENV>', // see "env" under ApplicationConfig
|
|
43
|
-
version: '<APPLICATION_VERSION>',
|
|
44
|
-
// Host-wide noise suppression. Locked at init, applies app-wide.
|
|
45
|
-
excludedActivityUrls: [/fullstory\.com/, /pendo\.io/, /\/Log\/Send/],
|
|
46
|
-
beforeSend: event => {
|
|
47
|
-
// optional: drop or transform events application-wide
|
|
48
|
-
return true;
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
enabled: isEnabled,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Attach session-lifetime context to every 'desktop'-tagged event
|
|
55
|
-
desktopRegistration.setServiceContext({ logicalEnvironment: 'go5' });
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
```tsx title="root.tsx"
|
|
59
|
-
import { DatadogProvider } from '@servicetitan/datadog-rum';
|
|
60
|
-
import { isEnabled } from './datadog-entry';
|
|
61
|
-
|
|
62
|
-
const Root = () => {
|
|
63
|
-
const user = useCurrentUser(); // application-specific hook that identifies the user
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
// Identify the current user to Datadog RUM
|
|
67
|
-
<DatadogProvider isEnabled={isEnabled} user={user}>
|
|
68
|
-
<Application />
|
|
69
|
-
</DatadogProvider>
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
</TabItem>
|
|
75
|
-
<TabItem value="mfe">
|
|
76
|
-
|
|
77
|
-
```tsx title="task-hub.tsx"
|
|
78
|
-
import { useEffect } from 'react';
|
|
79
|
-
import { useRumService } from '@servicetitan/datadog-rum';
|
|
80
|
-
|
|
81
|
-
const BFF_PATTERNS = [/\/api\/task-hub\//, /\/bff\//];
|
|
82
|
-
|
|
83
|
-
export const TaskHub = () => {
|
|
84
|
-
// Registers on mount; disposes automatically on unmount.
|
|
85
|
-
const { setServiceContext } = useRumService({
|
|
86
|
-
name: 'task-hub',
|
|
87
|
-
allowedTracingUrls: {
|
|
88
|
-
tracecontext: [url => BFF_PATTERNS.some(regex => regex.test(url))],
|
|
89
|
-
},
|
|
90
|
-
beforeSend: (event, context) => {
|
|
91
|
-
// attach MFE-specific context (transform-only — return value is ignored)
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const orgId = useCurrentOrgId();
|
|
96
|
-
|
|
97
|
-
// Add persistent metadata to every event from this MFE
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
setServiceContext({ logicalEnvironment: 'go5', orgId });
|
|
100
|
-
}, [orgId, setServiceContext]);
|
|
101
|
-
|
|
102
|
-
return <TaskHubApp />;
|
|
103
|
-
};
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
For non-React entry points, use the imperative form:
|
|
107
|
-
|
|
108
|
-
```ts title="task-hub-bootstrap.ts"
|
|
109
|
-
import { init } from '@servicetitan/datadog-rum';
|
|
110
|
-
|
|
111
|
-
const { cleanup, setServiceContext } = init({
|
|
112
|
-
service: {
|
|
113
|
-
name: 'task-hub',
|
|
114
|
-
allowedTracingUrls: {
|
|
115
|
-
tracecontext: [url => /\/api\/task-hub\//.test(url)],
|
|
116
|
-
},
|
|
117
|
-
beforeSend: (event, context) => {
|
|
118
|
-
// attach MFE-specific context
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
application: {
|
|
122
|
-
// optional: ignored when a host offered or already started an application
|
|
123
|
-
applicationId: '<TASK_HUB_APPLICATION_ID>',
|
|
124
|
-
clientToken: '<TASK_HUB_CLIENT_TOKEN>',
|
|
125
|
-
env: '<ENV>', // see "env" under ApplicationConfig
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Add persistent metadata to every event from this MFE
|
|
130
|
-
setServiceContext({ logicalEnvironment: 'go5', orgId: '123' });
|
|
131
|
-
|
|
132
|
-
// Tear down on MFE unmount
|
|
133
|
-
cleanup();
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
</TabItem>
|
|
137
|
-
</Tabs>
|
|
138
|
-
|
|
139
|
-
## Service attribution {#attribution}
|
|
140
|
-
|
|
141
|
-
Every event is tagged with the service it came from. For MFEs loaded from unpkg, the built-in enrichment looks for the first `unpkg.servicetitan.com/@servicetitan/<name>@<version>` URL in the event and sets `service` and `version` from it. Events with no such URL keep the application's service, i.e. the host.
|
|
142
|
-
|
|
143
|
-
| Event | Service comes from |
|
|
144
|
-
| :---------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
145
|
-
| `error` | The error's own stack (where it was thrown), then its message. Errors with no stack of their own, such as `console.error('text')`, use the handling stack (where it was logged) instead. |
|
|
146
|
-
| `resource` | The handling stack (the code that started the request), then the resource URL. |
|
|
147
|
-
| `action` | For a custom action, the code that called `addAction`. For a click, the MFE that was clicked. A click inside a nested MFE goes to the nested MFE. |
|
|
148
|
-
| `long_task` | For a long animation frame, the MFE whose script ran longest. `@context.loafServices` lists every MFE that ran a script in the frame. |
|
|
149
|
-
| `view` | For a view started with `startView`, the MFE that started it. Requires `@datadog/browser-rum` 6.27.0 or later. |
|
|
150
|
-
| others | The handling stack, when the SDK provides one. |
|
|
151
|
-
|
|
152
|
-
## API
|
|
153
|
-
|
|
154
|
-
| Name | Description |
|
|
155
|
-
| :------------------------------------ | :---------------------------------------------------------- |
|
|
156
|
-
| [`init`](#init) | Registers a service and optionally initializes the SDK |
|
|
157
|
-
| [`useRumService`](#userumservice) | React hook that registers a service and disposes on unmount |
|
|
158
|
-
| [`DatadogProvider`](#datadogprovider) | Identifies the current user to RUM (React component) |
|
|
159
|
-
| [`setUser`](#setuser) | Sets the current session user |
|
|
160
|
-
| [`beforeSend`](#beforesend) | Legacy event-enrichment helper |
|
|
161
|
-
|
|
162
|
-
Each app or MFE has a **service name** used to attribute every RUM event to its source. For MFEs loaded from unpkg, this name is inferred at event time from the package slug (`'task-hub'` for `@servicetitan/task-hub`) and is the key for per-service `beforeSend`, `allowedTracingUrls`, and persistent context lookups. The name you pass to [`init`](#init) or [`useRumService`](#userumservice) must exactly match this slug — i.e. the unscoped name in the MFE's `package.json`. A mismatch silently prevents per-service handlers from running for that MFE's events. `setServiceContext` is exposed as a property of the registration returned by [`init`](#init) and [`useRumService`](#userumservice), so the name is captured once at registration time and cannot drift.
|
|
163
|
-
|
|
164
|
-
### `init`
|
|
165
|
-
|
|
166
|
-
Registers a service and, optionally, initializes the Datadog RUM SDK. Returns a [`RumServiceRegistration`](#rumserviceregistration) — `{ cleanup, setServiceContext }`, both bound to this service.
|
|
167
|
-
|
|
168
|
-
Any caller — host or MFE — may pass `application`. The first `application` passed wins, and a later caller's `application` config is ignored. The SDK starts on the first call that asks for a session, which is not always the call that supplied the winning `application`. Callers that omit `application` register their service without attempting SDK init.
|
|
169
|
-
|
|
170
|
-
```ts
|
|
171
|
-
import { init } from '@servicetitan/datadog-rum';
|
|
172
|
-
|
|
173
|
-
const isEnabled = /(?:^|\.)go\d*\.servicetitan\.com\.?$/i.test(window.location.hostname);
|
|
174
|
-
|
|
175
|
-
const { cleanup, setServiceContext } = init({
|
|
176
|
-
service: {
|
|
177
|
-
name: 'task-hub',
|
|
178
|
-
allowedTracingUrls: {
|
|
179
|
-
tracecontext: [url => /\/api\/task-hub\//.test(url)],
|
|
180
|
-
},
|
|
181
|
-
beforeSend: event => {
|
|
182
|
-
// transform-only (return value ignored)
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
application: {
|
|
186
|
-
applicationId: '<APPLICATION_ID>',
|
|
187
|
-
clientToken: '<CLIENT_TOKEN>',
|
|
188
|
-
env: '<ENV>', // see "env" under ApplicationConfig
|
|
189
|
-
version: '<APPLICATION_VERSION>',
|
|
190
|
-
excludedActivityUrls: [/fullstory\.com/, /pendo\.io/, /\/Log\/Send/],
|
|
191
|
-
beforeSend: event => {
|
|
192
|
-
return true; // return false to drop the event app-wide
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
enabled: isEnabled,
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// Attach session-lifetime context merged into every 'task-hub'-tagged event
|
|
199
|
-
setServiceContext({ logicalEnvironment: 'go5', orgId: '123' });
|
|
200
|
-
|
|
201
|
-
// On teardown (e.g. MFE unmount):
|
|
202
|
-
cleanup();
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
#### Parameters
|
|
206
|
-
|
|
207
|
-
`init` accepts an [`InitRumOptions`](#initrumoptions) object and returns a [`RumServiceRegistration`](#rumserviceregistration).
|
|
208
|
-
|
|
209
|
-
##### `InitRumOptions` {#initrumoptions}
|
|
210
|
-
|
|
211
|
-
| Name | Type | Description |
|
|
212
|
-
| :------------ | :---------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
213
|
-
| `service` | [`ServiceConfig`](#serviceconfig) | Per-service handlers and tracing URL matchers |
|
|
214
|
-
| `application` | [`ApplicationConfig`](#applicationconfig) | (optional) SDK initialization config. See [`init`](#init) for which caller starts the session |
|
|
215
|
-
| `enabled` | `boolean` | (optional) Controls whether Datadog RUM data collection is turned on. Defaults to `true`. Set this instead of gating the `init` call to allow [runtime enablement for development](#dev-runtime-enable). |
|
|
216
|
-
|
|
217
|
-
##### `RumServiceRegistration` {#rumserviceregistration}
|
|
218
|
-
|
|
219
|
-
| Name | Type | Description |
|
|
220
|
-
| :------------------ | :--------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
221
|
-
| `cleanup` | `() => void` | Removes this service's `beforeSend`, `allowedTracingUrls`, and persistent context. Idempotent. |
|
|
222
|
-
| `setServiceContext` | `(context: Context) => void` | Sets session-lifetime context merged into every event whose `event.service` matches this service's name. Replace semantics: a second call replaces the previous bag with no merge. |
|
|
223
|
-
|
|
224
|
-
##### `ServiceConfig` {#serviceconfig}
|
|
225
|
-
|
|
226
|
-
| Name | Type | Description |
|
|
227
|
-
| :------------------- | :------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
228
|
-
| `name` | `string` | Service name. For MFEs loaded from unpkg, must exactly match the unscoped `package.json` `name` (e.g. `'task-hub'` for `@servicetitan/task-hub`). |
|
|
229
|
-
| `beforeSend` | `ServiceBeforeSendHandler` | (optional) Transform-only per-service handler. Return value is **ignored** — services cannot drop events. |
|
|
230
|
-
| `allowedTracingUrls` | `Partial<Record<PropagatorType, TracingMatchOption[]>>` | (optional) URL matchers grouped by propagator type |
|
|
231
|
-
|
|
232
|
-
:::caution
|
|
233
|
-
A service's `beforeSend` cannot drop events. This is intentional: services share a session with the host and any other MFEs, so a bug in one service must not silently hide its own events from the host's monitoring. Use `application.beforeSend` for app-wide drop decisions.
|
|
234
|
-
:::
|
|
235
|
-
|
|
236
|
-
##### `ApplicationConfig` {#applicationconfig}
|
|
237
|
-
|
|
238
|
-
Same shape as `datadogRum.init` config, minus `allowedTracingUrls` (built from service registrations) and `service` (derived from `service.name`), plus:
|
|
239
|
-
|
|
240
|
-
| Name | Type | Description |
|
|
241
|
-
| :----------- | :----------------------------- | :---------------------------------------------------------------------------------------------------------------------------- |
|
|
242
|
-
| `beforeSend` | `ApplicationBeforeSendHandler` | (optional) Application-level handler; runs for all events before service handlers. Return `false` to drop the event app-wide. |
|
|
243
|
-
|
|
244
|
-
Opinionated defaults (overridable):
|
|
245
|
-
|
|
246
|
-
- `sessionSampleRate: 100`
|
|
247
|
-
- `sessionReplaySampleRate: 0`
|
|
248
|
-
- `defaultPrivacyLevel: 'mask-user-input'`
|
|
249
|
-
|
|
250
|
-
Where:
|
|
251
|
-
|
|
252
|
-
- `PropagatorType` is `'datadog' | 'tracecontext' | 'b3' | 'b3multi'`.
|
|
253
|
-
- `TracingMatchOption` is `string` (prefix match), `RegExp`, or `(url: string) => boolean`.
|
|
254
|
-
- `ApplicationBeforeSendHandler` is `(event: RumEvent, context: RumEventDomainContext) => boolean | void`.
|
|
255
|
-
- `ServiceBeforeSendHandler` is `(event: RumEvent, context: RumEventDomainContext) => void`.
|
|
256
|
-
|
|
257
|
-
:::caution
|
|
258
|
-
`excludedActivityUrls` tells RUM which URLs not to count toward view-loading time. The exclusion applies app-wide; the `application` config that starts the session locks the list, so the host should set the complete list there. If an MFE set it, its choices would distort view metrics for the host and any other MFEs sharing the session.
|
|
259
|
-
:::
|
|
260
|
-
|
|
261
|
-
##### `env` {#env}
|
|
262
|
-
|
|
263
|
-
Set `env` to the deployment stage: `go`, `stage`, `next`, `practice`, `integration`, `qa`, `dev`, or `test`.
|
|
264
|
-
|
|
265
|
-
:::caution
|
|
266
|
-
Do not use the hostname as `env`. Each tenant subdomain, such as `acme.eh.go.servicetitan.com`, then reports its own `env`, and dashboards and monitors that filter on `env:go` miss those tenants.
|
|
267
|
-
:::
|
|
268
|
-
|
|
269
|
-
Check the production host first, then use [`getValueForEnvironment`](./web-components/get-value-for-environment) for the other stages. `getValueForEnvironment` matches `<key>.servicetitan.com` as a substring, so a sharded production host such as `go2.servicetitan.com` falls through to the default.
|
|
270
|
-
|
|
271
|
-
```ts
|
|
272
|
-
import { getValueForEnvironment } from '@servicetitan/web-components';
|
|
273
|
-
|
|
274
|
-
const isProdHost = /(?:^|\.)go\d*\.servicetitan\.com\.?$/i.test(window.location.hostname);
|
|
275
|
-
|
|
276
|
-
const env = isProdHost
|
|
277
|
-
? 'go'
|
|
278
|
-
: getValueForEnvironment(
|
|
279
|
-
{
|
|
280
|
-
'stage': 'stage',
|
|
281
|
-
'next': 'next',
|
|
282
|
-
'practice': 'practice',
|
|
283
|
-
'integration': 'integration',
|
|
284
|
-
'qa': 'qa',
|
|
285
|
-
'qa.st.dev': 'qa',
|
|
286
|
-
'dev': 'dev',
|
|
287
|
-
'test': 'test',
|
|
288
|
-
},
|
|
289
|
-
'dev'
|
|
290
|
-
);
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### `useRumService`
|
|
294
|
-
|
|
295
|
-
React hook that wraps [`init`](#init) for service-only registration. The service is registered on mount and disposed on unmount; the config is captured on first render — changing it across renders does not re-register.
|
|
296
|
-
|
|
297
|
-
Returns a `RumService` — `{ setServiceContext }`, bound to this service. The handle is identity-stable across renders, so it can safely appear in dependency arrays.
|
|
298
|
-
|
|
299
|
-
On unmount the service's `beforeSend`, `allowedTracingUrls`, and any context previously set via `setServiceContext` are removed atomically. The SDK is **not** shut down — other services remain registered.
|
|
300
|
-
|
|
301
|
-
```tsx
|
|
302
|
-
import { useEffect } from 'react';
|
|
303
|
-
import { useRumService } from '@servicetitan/datadog-rum';
|
|
304
|
-
|
|
305
|
-
const TaskHub = () => {
|
|
306
|
-
const { setServiceContext } = useRumService({
|
|
307
|
-
name: 'task-hub',
|
|
308
|
-
allowedTracingUrls: { tracecontext: [/\/api\/task-hub\//] },
|
|
309
|
-
beforeSend: event => {
|
|
310
|
-
// transform-only
|
|
311
|
-
},
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
const orgId = useCurrentOrgId();
|
|
315
|
-
useEffect(() => {
|
|
316
|
-
setServiceContext({ logicalEnvironment: 'go5', orgId });
|
|
317
|
-
}, [orgId, setServiceContext]);
|
|
318
|
-
|
|
319
|
-
return <TaskHubApp />;
|
|
320
|
-
};
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
The hook accepts a [`ServiceConfig`](#serviceconfig) — the same shape used by `init`'s `service` field. It does **not** accept `application` config, since SDK initialization shouldn't be tied to a component's lifecycle.
|
|
324
|
-
|
|
325
|
-
### Enabling RUM at runtime for development {#dev-runtime-enable}
|
|
326
|
-
|
|
327
|
-
To exercise RUM-related changes in an environment where the application ships RUM but leaves it off (for example a local or QA build), you can turn RUM on for your own browser — no code change. It only ever turns RUM **on**; it has no effect where RUM is already enabled.
|
|
328
|
-
|
|
329
|
-
An application opts in once by always calling [`init`](#init) and passing its enablement decision as `enabled`, instead of gating the `init` call. The [end-to-end example](#end-to-end-example) shows this.
|
|
330
|
-
|
|
331
|
-
In any environment where the application ships RUM but leaves it disabled (`enabled` is `false`), the package exposes `datadogRumForDev` on the global scope. A developer controls it directly from the browser devtools console — no import, no code change:
|
|
332
|
-
|
|
333
|
-
```js
|
|
334
|
-
// In the browser devtools console:
|
|
335
|
-
datadogRumForDev.start(); // turn RUM on for the next 12 hours
|
|
336
|
-
datadogRumForDev.stop(); // clear the override; return to the shipped default
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
`start()` records the override in `localStorage` and reloads the page to apply. The override expires automatically after 12 hours; calling `start()` again refreshes the 12-hour window. `stop()` removes the override, ends the current Datadog session, and reloads — returning to the application's shipped `enabled` value. It does **not** disable RUM that the application itself enabled. Both methods log to the console, so the override is never silent.
|
|
340
|
-
|
|
341
|
-
Sessions enabled this way are tagged with a `datadogRumForDev` context attribute. Filter `@context.datadogRumForDev:true` in Datadog RUM to find them, or `-@context.datadogRumForDev:true` to exclude them from production dashboards.
|
|
342
|
-
|
|
343
|
-
**Set [`env`](#env) to the deployment stage before you rely on this.** The override turns RUM on in lower environments, and the deployment stage in `env` keeps their sessions apart from production data in dashboards and monitors.
|
|
344
|
-
|
|
345
|
-
#### Multiple tabs
|
|
346
|
-
|
|
347
|
-
Because the override lives in `localStorage`, it applies to every tab of the origin — useful for testing how a user navigates between pages and opens new tabs. Calling `start()` (or `stop()`) reloads the current tab and every other open tab of the application, so they all pick up the change. A tab opened afterward honors the override on its first load. All such tabs share a single Datadog RUM session, exactly as they would with normally-enabled RUM.
|
|
348
|
-
|
|
349
|
-
### `DatadogProvider`
|
|
350
|
-
|
|
351
|
-
`DatadogProvider` provides the RUM SDK with:
|
|
352
|
-
|
|
353
|
-
- Information about the user session
|
|
354
|
-
- Sanitized view event names (`@view.name`) for hash-based routing
|
|
355
|
-
|
|
356
|
-
:::note
|
|
357
|
-
`DatadogProvider` sets the user via [`setUser`](#setuser), so the same gating rules apply.
|
|
358
|
-
:::
|
|
359
|
-
|
|
360
|
-
#### Usage
|
|
361
|
-
|
|
362
|
-
Wrap your application with `DatadogProvider` close to the root. For example,
|
|
363
|
-
|
|
364
|
-
```tsx
|
|
365
|
-
import { DatadogProvider } from '@servicetitan/datadog-rum';
|
|
366
|
-
|
|
367
|
-
const Root = () => {
|
|
368
|
-
return (
|
|
369
|
-
<DatadogProvider isEnabled={isEnabled} user={user}>
|
|
370
|
-
...
|
|
371
|
-
</DatadogProvider>
|
|
372
|
-
);
|
|
373
|
-
};
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
If your application uses hash-based routing, place `DatadogProvider` inside `HashRouter`. For example,
|
|
377
|
-
|
|
378
|
-
```tsx
|
|
379
|
-
import { HashRouter } from 'react-router-dom';
|
|
380
|
-
import { DatadogProvider } from '@servicetitan/datadog-rum';
|
|
381
|
-
|
|
382
|
-
const Root = () => {
|
|
383
|
-
return (
|
|
384
|
-
<HashRouter>
|
|
385
|
-
<DatadogProvider isEnabled={isEnabled} user={user} options={{ hashRouting: true }}>
|
|
386
|
-
...
|
|
387
|
-
</DatadogProvider>
|
|
388
|
-
</HashRouter>
|
|
389
|
-
);
|
|
390
|
-
};
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
#### Parameters
|
|
394
|
-
|
|
395
|
-
| Name | Type | Description |
|
|
396
|
-
| :---------- | :-------------------- | :------------------------------------------ |
|
|
397
|
-
| `isEnabled` | `boolean` | Activates the provider's instrumentation |
|
|
398
|
-
| `user` | [`RumUser`](#rumuser) | (optional) User session information |
|
|
399
|
-
| `options` | [`Options`](#options) | (optional) Additional configuration options |
|
|
400
|
-
|
|
401
|
-
##### `RumUser` {#rumuser}
|
|
402
|
-
|
|
403
|
-
```ts
|
|
404
|
-
import type { RumUser } from '@servicetitan/datadog-rum';
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
| Name | Type | Description |
|
|
408
|
-
| :-------------- | :----------------------------- | :-------------------------------------- |
|
|
409
|
-
| `id` | `string` | User ID |
|
|
410
|
-
| `[key: string]` | `string \| number \| string[]` | (optional) Session-wide user attributes |
|
|
411
|
-
|
|
412
|
-
##### `Options`
|
|
413
|
-
|
|
414
|
-
| Name | Type | Description |
|
|
415
|
-
| :------------ | :-------- | :----------------------------------------------------------- |
|
|
416
|
-
| `hashRouting` | `boolean` | Tracks hash-based routes as RUM views (with sanitized names) |
|
|
417
|
-
|
|
418
|
-
### `setUser`
|
|
419
|
-
|
|
420
|
-
Sets the session user (see [`RumUser`](#rumuser) for the accepted shape). Behavior depends on initialization state:
|
|
421
|
-
|
|
422
|
-
- **SDK initialized via `init`**: only the bundle whose `init` call initialized the SDK may set the user. That bundle can re-set freely (for example, login, logout, identity switch). Calls from any other bundle are silent no-ops.
|
|
423
|
-
- **SDK initialized directly via `datadogRum.init`**: `setUser` delegates straight to `datadogRum.setUser` without gating.
|
|
424
|
-
- **Neither initialized**: no-op.
|
|
425
|
-
|
|
426
|
-
```ts
|
|
427
|
-
import { setUser } from '@servicetitan/datadog-rum';
|
|
428
|
-
|
|
429
|
-
setUser({ id: '7', email: 'user@example.com' });
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
### `beforeSend`
|
|
433
|
-
|
|
434
|
-
:::caution
|
|
435
|
-
This is the legacy API, kept for backward compatibility. New applications should use [`init`](#init), which lets MFEs share a host's RUM session.
|
|
436
|
-
:::
|
|
437
|
-
|
|
438
|
-
`beforeSend` is a callback that enriches RUM events:
|
|
439
|
-
|
|
440
|
-
- Adds MFE name and version for error and resource events coming from MFEs (`@error.service`, `@resource.service`, `@error.version`, and `@resource.version`)
|
|
441
|
-
- Adds Cloudflare Ray ID for resource events (`@resource.cfRay`)
|
|
442
|
-
|
|
443
|
-
#### Usage
|
|
444
|
-
|
|
445
|
-
```ts
|
|
446
|
-
import { beforeSend } from '@servicetitan/datadog-rum';
|
|
447
|
-
import { datadogRum } from '@datadog/browser-rum';
|
|
448
|
-
|
|
449
|
-
const isEnabled = /(?:^|\.)go\d*\.servicetitan\.com\.?$/i.test(window.location.hostname);
|
|
450
|
-
|
|
451
|
-
if (isEnabled) {
|
|
452
|
-
datadogRum.init({
|
|
453
|
-
applicationId: '<APPLICATION_ID>',
|
|
454
|
-
clientToken: '<CLIENT_TOKEN>',
|
|
455
|
-
site: 'datadoghq.com',
|
|
456
|
-
service: '<SERVICE_NAME>',
|
|
457
|
-
env: '<ENV>', // see "env" under ApplicationConfig
|
|
458
|
-
version: '<APPLICATION_VERSION>',
|
|
459
|
-
sessionSampleRate: 100,
|
|
460
|
-
sessionReplaySampleRate: 0,
|
|
461
|
-
defaultPrivacyLevel: 'mask-user-input',
|
|
462
|
-
beforeSend: beforeSend(), // beforeSend() returns a handler that enriches events
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
```
|