@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.
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: useRumService
3
+ ---
4
+
5
+ React hook that wraps [`init`](./init.mdx) 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.
6
+
7
+ Returns a `RumService` — `{ setServiceContext }`, bound to this service. The handle is identity-stable across renders, so it can safely appear in dependency arrays.
8
+
9
+ 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.
10
+
11
+ ```tsx
12
+ import { useEffect } from 'react';
13
+ import { useRumService } from '@servicetitan/datadog-rum';
14
+
15
+ const TaskHub = () => {
16
+ const { setServiceContext } = useRumService({
17
+ name: 'task-hub',
18
+ allowedTracingUrls: { tracecontext: [/\/api\/task-hub\//] },
19
+ beforeSend: event => {
20
+ // transform-only
21
+ },
22
+ });
23
+
24
+ const orgId = useCurrentOrgId();
25
+ useEffect(() => {
26
+ setServiceContext({ logicalEnvironment: 'go5', orgId });
27
+ }, [orgId, setServiceContext]);
28
+
29
+ return <TaskHubApp />;
30
+ };
31
+ ```
32
+
33
+ The hook accepts a [`ServiceConfig`](./init.mdx#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.
@@ -0,0 +1,156 @@
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
+ version: '<APPLICATION_VERSION>',
43
+ // Host-wide noise suppression. Locked at init, applies app-wide.
44
+ excludedActivityUrls: [/fullstory\.com/, /pendo\.io/, /\/Log\/Send/],
45
+ beforeSend: event => {
46
+ // optional: drop or transform events application-wide
47
+ return true;
48
+ },
49
+ },
50
+ enabled: isEnabled,
51
+ });
52
+
53
+ // Attach session-lifetime context to every 'desktop'-tagged event
54
+ desktopRegistration.setServiceContext({ logicalEnvironment: 'go5' });
55
+ ```
56
+
57
+ ```tsx title="root.tsx"
58
+ import { DatadogProvider } from '@servicetitan/datadog-rum';
59
+ import { isEnabled } from './datadog-entry';
60
+
61
+ const Root = () => {
62
+ const user = useCurrentUser(); // application-specific hook that identifies the user
63
+
64
+ return (
65
+ // Identify the current user to Datadog RUM
66
+ <DatadogProvider isEnabled={isEnabled} user={user}>
67
+ <Application />
68
+ </DatadogProvider>
69
+ );
70
+ };
71
+ ```
72
+
73
+ </TabItem>
74
+ <TabItem value="mfe">
75
+
76
+ ```tsx title="task-hub.tsx"
77
+ import { useEffect } from 'react';
78
+ import { useRumService } from '@servicetitan/datadog-rum';
79
+
80
+ const BFF_PATTERNS = [/\/api\/task-hub\//, /\/bff\//];
81
+
82
+ export const TaskHub = () => {
83
+ // Registers on mount; disposes automatically on unmount.
84
+ const { setServiceContext } = useRumService({
85
+ name: 'task-hub',
86
+ allowedTracingUrls: {
87
+ tracecontext: [url => BFF_PATTERNS.some(regex => regex.test(url))],
88
+ },
89
+ beforeSend: (event, context) => {
90
+ // attach MFE-specific context (transform-only — return value is ignored)
91
+ },
92
+ });
93
+
94
+ const orgId = useCurrentOrgId();
95
+
96
+ // Add persistent metadata to every event from this MFE
97
+ useEffect(() => {
98
+ setServiceContext({ logicalEnvironment: 'go5', orgId });
99
+ }, [orgId, setServiceContext]);
100
+
101
+ return <TaskHubApp />;
102
+ };
103
+ ```
104
+
105
+ For non-React entry points, use the imperative form:
106
+
107
+ ```ts title="task-hub-bootstrap.ts"
108
+ import { init } from '@servicetitan/datadog-rum';
109
+
110
+ const { cleanup, setServiceContext } = init({
111
+ service: {
112
+ name: 'task-hub',
113
+ allowedTracingUrls: {
114
+ tracecontext: [url => /\/api\/task-hub\//.test(url)],
115
+ },
116
+ beforeSend: (event, context) => {
117
+ // attach MFE-specific context
118
+ },
119
+ },
120
+ application: {
121
+ // optional: ignored when a host offered or already started an application
122
+ applicationId: '<TASK_HUB_APPLICATION_ID>',
123
+ clientToken: '<TASK_HUB_CLIENT_TOKEN>',
124
+ },
125
+ });
126
+
127
+ // Add persistent metadata to every event from this MFE
128
+ setServiceContext({ logicalEnvironment: 'go5', orgId: '123' });
129
+
130
+ // Tear down on MFE unmount
131
+ cleanup();
132
+ ```
133
+
134
+ </TabItem>
135
+ </Tabs>
136
+
137
+ ## Service attribution {#attribution}
138
+
139
+ 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.
140
+
141
+ | Event | Service comes from |
142
+ | :---------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
143
+ | `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. |
144
+ | `resource` | The handling stack (the code that started the request), then the resource URL. |
145
+ | `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. |
146
+ | `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. |
147
+ | `view` | For a view started with `startView`, the MFE that started it. Requires `@datadog/browser-rum` 6.27.0 or later. |
148
+ | others | The handling stack, when the SDK provides one. |
149
+
150
+ ## Development
151
+
152
+ See [Enabling RUM at runtime for development](./dev-runtime-enable.mdx) to turn RUM on in your own browser where an application ships it disabled.
153
+
154
+ ## API
155
+
156
+ See [API](./api/api.mdx) for the functions, hooks and components this package exports.
@@ -0,0 +1,25 @@
1
+ ---
2
+ title: Enabling RUM at runtime for development
3
+ ---
4
+
5
+ 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.
6
+
7
+ An application opts in once by always calling [`init`](./api/init.mdx) and passing its enablement decision as `enabled`, instead of gating the `init` call. The [end-to-end example](./datadog-rum.mdx#end-to-end-example) shows this.
8
+
9
+ 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:
10
+
11
+ ```js
12
+ // In the browser devtools console:
13
+ datadogRumForDev.start(); // turn RUM on for the next 12 hours
14
+ datadogRumForDev.stop(); // clear the override; return to the shipped default
15
+ ```
16
+
17
+ `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.
18
+
19
+ 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.
20
+
21
+ **Leave [`env`](./api/init.mdx#env) unset, or set it 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.
22
+
23
+ ## Multiple tabs
24
+
25
+ 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.
@@ -55,6 +55,12 @@ When `waitForInitialization` is set to false, `LDProvider` renders children imme
55
55
  then automatically re-renders when the flags become available.
56
56
  :::
57
57
 
58
+ :::note
59
+ If the LaunchDarkly client can't be created, `LDProvider` logs the error and renders children without a client.
60
+ `useLDClient` returns `undefined`, and both `useFlags` and the [MobX store](#use-flags-in-mobx-store) hold the defaults passed in `flags`.
61
+ Every other flag reads as `undefined`.
62
+ :::
63
+
58
64
  #### Examples
59
65
 
60
66
  For example, to provide feature flags for the TitanAdvisor project, create a `TitanAdvisorLDProvider` component that wraps its children with the appropriate `LDProvider`:
@@ -30,7 +30,7 @@ The `build` command executes these steps:
30
30
  1. Activate Kendo UI license.
31
31
  1. Run package **precompile** scripts, if any.
32
32
  1. Compile Typescript.
33
- 1. Generate TypeScript definitions from CSS, LESS, and SASS modules, and copy assets and style files to the output folder.
33
+ 1. Generate TypeScript definitions from CSS, LESS, and SASS modules, and copy assets and style files to the output folder. Files in `__tests__` and `__mocks__` folders are not copied.
34
34
  1. Run type check via [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html).
35
35
  1. Bundle application and MFE packages.
36
36
 
@@ -279,6 +279,30 @@ Names are matched case-sensitively, so use the conventional `ALL_CAPS` form.
279
279
  This is a convenient, package.json-only way to forward variables straight from the environment. It does not replace webpack's `DefinePlugin` or Vite's `define`, which map a name to a value you specify (not necessarily the live environment value). Use those when you need to control the value and use `expose-process-env` when you just want to pass an environment value through as-is.
280
280
  :::
281
281
 
282
+ ### Uploading Source Maps to Datadog
283
+
284
+ Host applications can upload source maps to Datadog, so Datadog Error Tracking shows original source in stack traces. `startup` doesn't upload them for hosts. Instead, run [`datadog-ci`](https://github.com/DataDog/datadog-ci/blob/master/packages/base/src/commands/sourcemaps/README.md) on the production build's output directory (`dist/bundle` by default), before deploying. Pin `datadog-ci` to a specific version, for example:
285
+
286
+ ```sh
287
+ npx --yes @datadog/datadog-ci@5.26.1 sourcemaps inject dist/bundle
288
+ npx --yes @datadog/datadog-ci@5.26.1 sourcemaps upload dist/bundle --debug-id
289
+ ```
290
+
291
+ `inject` adds a debug ID to each bundle and its source map, so the upload doesn't need a service, version, or path prefix. This requires:
292
+
293
+ - `@datadog/browser-rum` 7.6.0 or later, which attaches debug IDs to RUM events.
294
+ - ServiceTitan's Datadog API key in the `DATADOG_API_KEY` environment variable, for the upload. The key is available as the `DATADOG_API_KEY` organization secret in GitHub (`secrets.DATADOG_API_KEY`) and TeamCity (`env.DATADOG_API_KEY`). Set it only in builds that deploy to production, to avoid uploading source maps for builds that never reach users.
295
+
296
+ `inject` doesn't need the API key. Run it in every production build, including builds that skip the upload, so each file name always has the same contents.
297
+
298
+ :::caution
299
+ `inject` rewrites the bundles in place. Generate anything computed from their contents, such as integrity hashes or precompressed files, after it runs.
300
+ :::
301
+
302
+ :::note
303
+ MFEs upload source maps when they're published. See [`mfe-publish`](../mfe-publish#sourcemaps).
304
+ :::
305
+
282
306
  ### Bundler-Specific Configuration
283
307
 
284
308
  See [Webpack](./webpack) or [Vite](./vite) for bundler-specific configuration options, including minimization, custom config files, and plugin overrides.
@@ -118,6 +118,8 @@ If `DATADOG_API_KEY` is not provided, `mfe-publish` logs a warning and skips upl
118
118
  Use `--no-upload-sourcemaps` to prevent `mfe-publish` from attempting to upload sourcemaps, for example, for pre-release versions. See [Publishing options](#publishing-options).
119
119
  :::
120
120
 
121
+ To upload source maps for a host application, see [Uploading Source Maps to Datadog](./build/build#uploading-source-maps-to-datadog).
122
+
121
123
  ## Cache Purging
122
124
 
123
125
  ✨ New in **v35.0.0** ✨
@@ -20,6 +20,8 @@ You are encouraged to use prefetching broadly, for example to prefetch all signi
20
20
  | :--------- | :--------------------------------------------------------------- |
21
21
  | `prefetch` | A function that takes an MFE's URL and prefetches its resources. |
22
22
 
23
+ The returned object and `prefetch` function keep the same reference across re-renders, so you can list either one as an effect dependency.
24
+
23
25
  ### Prefetch Parameters
24
26
 
25
27
  The `prefetch` function returned by `usePrefetch` takes the following arguments:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/docs-uikit",
3
- "version": "40.2.2",
3
+ "version": "40.3.0",
4
4
  "description": "Documentation content for Uikit packages published at docs.st.dev",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,43 +0,0 @@
1
- ---
2
- title: Cancelation handling
3
- ---
4
-
5
- When a request is canceled via `CancelToken` or `AbortController`, `initAjaxHandlers` rejects the promise with the cancelation error. Code that makes cancelable requests must handle this error to avoid unhandled promise rejections and spurious error UI.
6
-
7
- Use `axios.isCancel` to distinguish cancelations from real errors:
8
-
9
- ```ts
10
- import axios from 'axios';
11
-
12
- async loadData() {
13
- this.cancelToken?.cancel();
14
- this.cancelToken = axios.CancelToken.source();
15
-
16
- try {
17
- const res = await this.api.getData(this.cancelToken.token);
18
- runInAction(() => { this.data = res.data; });
19
- } catch (e) {
20
- if (!axios.isCancel(e)) {
21
- throw e;
22
- }
23
- }
24
- }
25
- ```
26
-
27
- If loading state is set before the `await`, reset it in a `finally` block so it clears even when the request is canceled:
28
-
29
- ```ts
30
- this.isLoading = true;
31
- try {
32
- const res = await this.api.getData(this.cancelToken.token);
33
- runInAction(() => {
34
- this.data = res.data;
35
- });
36
- } catch (e) {
37
- if (!axios.isCancel(e)) {
38
- throw e;
39
- }
40
- } finally {
41
- this.isLoading = false;
42
- }
43
- ```