@descope/debug-logs 0.1.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/LICENSE +21 -0
- package/README.md +248 -0
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/types/index.d.ts +5 -0
- package/dist/cjs/types/plugins/consolePlugin.d.ts +23 -0
- package/dist/cjs/types/plugins/domMutationPlugin.d.ts +53 -0
- package/dist/cjs/types/plugins/navigationPlugin.d.ts +19 -0
- package/dist/cjs/types/plugins/networkPlugin/NetworkPlugin.d.ts +29 -0
- package/dist/cjs/types/plugins/networkPlugin/helpers.d.ts +54 -0
- package/dist/cjs/types/plugins/networkPlugin/index.d.ts +4 -0
- package/dist/cjs/types/plugins/networkPlugin/types.d.ts +11 -0
- package/dist/cjs/types/telemetryManager.d.ts +59 -0
- package/dist/cjs/types/types.d.ts +32 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/plugins/consolePlugin.d.ts +23 -0
- package/dist/types/plugins/domMutationPlugin.d.ts +53 -0
- package/dist/types/plugins/navigationPlugin.d.ts +19 -0
- package/dist/types/plugins/networkPlugin/NetworkPlugin.d.ts +29 -0
- package/dist/types/plugins/networkPlugin/helpers.d.ts +54 -0
- package/dist/types/plugins/networkPlugin/index.d.ts +4 -0
- package/dist/types/plugins/networkPlugin/types.d.ts +11 -0
- package/dist/types/telemetryManager.d.ts +59 -0
- package/dist/types/types.d.ts +32 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Descope <help@descope.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
|
|
3
|
+
`@descope/debug-logs` is a CloudWatch RUM helper that bootstraps Descope SDKs
|
|
4
|
+
with consistent telemetry. It wraps AWS RUM initialization, wires multiple
|
|
5
|
+
custom plugins (console, navigation, DOM mutation), and exposes a single
|
|
6
|
+
`TelemetryManager` class so apps can enable, disable, or fully shut down
|
|
7
|
+
telemetry with predictable lifecycle hooks.
|
|
8
|
+
|
|
9
|
+
## When to Use
|
|
10
|
+
|
|
11
|
+
- Add observability to sample apps, SDK playgrounds, or QA harnesses without
|
|
12
|
+
duplicating event plumbing.
|
|
13
|
+
- Validate new instrumentation before promoting it into the production SDKs.
|
|
14
|
+
- Run high-fidelity manual or automated tests against AWS CloudWatch RUM using
|
|
15
|
+
the included standalone test page.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @descope/debug-logs
|
|
21
|
+
# or
|
|
22
|
+
npm install @descope/debug-logs
|
|
23
|
+
# or
|
|
24
|
+
yarn add @descope/debug-logs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This package ships dual ESM and CJS bundles. Type definitions live in
|
|
28
|
+
`dist/index.d.ts` and are referenced automatically through the `exports` map.
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import TelemetryManager from '@descope/debug-logs';
|
|
34
|
+
|
|
35
|
+
const manager = new TelemetryManager(
|
|
36
|
+
{
|
|
37
|
+
enabled: true,
|
|
38
|
+
rumConfig: {
|
|
39
|
+
applicationId: 'YOUR_APP_ID',
|
|
40
|
+
identityPoolId: 'YOUR_ID_POOL',
|
|
41
|
+
region: 'us-west-2',
|
|
42
|
+
sessionSampleRate: 1,
|
|
43
|
+
// guestRoleArn and endpoint are optional
|
|
44
|
+
},
|
|
45
|
+
capture: {
|
|
46
|
+
console: { levels: ['log', 'error'] },
|
|
47
|
+
network: { urlFilter: [/^https:\/\/api\./] },
|
|
48
|
+
navigation: true,
|
|
49
|
+
dom: { rootElement: '#app', throttleMs: 250 },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
projectId: 'sample-app',
|
|
54
|
+
flowId: 'playground',
|
|
55
|
+
version: '1.2.3',
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
console.log('Telemetry on');
|
|
60
|
+
|
|
61
|
+
// Later
|
|
62
|
+
manager.disable(); // stop recording but keep client alive
|
|
63
|
+
manager.enable(); // resume
|
|
64
|
+
manager.shutdown(); // tear down permanently
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configuration Reference
|
|
68
|
+
|
|
69
|
+
| Key | Description |
|
|
70
|
+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
71
|
+
| `enabled` | Gatekeeper. If `false`, nothing initializes. |
|
|
72
|
+
| `rumConfig.applicationId` | CloudWatch RUM application ID. |
|
|
73
|
+
| `rumConfig.identityPoolId` | Cognito identity pool used by RUM. |
|
|
74
|
+
| `rumConfig.sessionSampleRate` | 0-1 float controlling sampling. |
|
|
75
|
+
| `rumConfig.endpoint` | Optional custom ingestion endpoint. |
|
|
76
|
+
| `capture.console` | `false`, `true`, or `{ levels: ConsoleLevel[] }`. |
|
|
77
|
+
| `capture.network` | `false`, `true`, or `{ urlFilter, maxHeaderLength }`. |
|
|
78
|
+
| `capture.navigation` | Toggle SPA navigation plugin. |
|
|
79
|
+
| `capture.dom` | `false`, `true`, or `{ rootElement, throttleMs, maxHtmlLength, includeText }`. `includeText` defaults to `false` — snapshots record tag structure only, no text nodes. See _DOM mutation plugin_ below. |
|
|
80
|
+
| `context.projectId` | Injected into session attributes. |
|
|
81
|
+
| `context.flowId` | Additional session dimension. |
|
|
82
|
+
| `context.version` | Overrides SDK version sent to RUM (defaults to 1.0.0). |
|
|
83
|
+
|
|
84
|
+
## Built-in Plugins
|
|
85
|
+
|
|
86
|
+
### Console plugin
|
|
87
|
+
|
|
88
|
+
- Wraps `log`, `info`, `warn`, `error`, and `debug` while preserving original
|
|
89
|
+
console behavior.
|
|
90
|
+
- Enforces level filtering per the `capture.console.levels` array.
|
|
91
|
+
- Serializes complex payloads (objects, arrays) with truncation safeguards.
|
|
92
|
+
|
|
93
|
+
### Navigation plugin
|
|
94
|
+
|
|
95
|
+
- Monkey patches `history.pushState` and `history.replaceState`, and listens to
|
|
96
|
+
`popstate` and `hashchange`.
|
|
97
|
+
- Records `{ type, from, to, timestamp }` events and automatically restores
|
|
98
|
+
original methods during `disable()` or `shutdown()`.
|
|
99
|
+
|
|
100
|
+
### DOM mutation plugin
|
|
101
|
+
|
|
102
|
+
- Observes either `document.body` or a scoped `rootElement` selector.
|
|
103
|
+
- Aggregates `MutationRecord`s with throttling (default 100 ms) to avoid noisy
|
|
104
|
+
payloads.
|
|
105
|
+
- Captures truncated HTML snapshots so investigators can see the exact DOM
|
|
106
|
+
fragment involved.
|
|
107
|
+
|
|
108
|
+
#### Structure-only capture (default)
|
|
109
|
+
|
|
110
|
+
By default the DOM snapshot **strips all text nodes** — only tag hierarchy and
|
|
111
|
+
attributes are recorded. This prevents rendered content from leaking into RUM
|
|
112
|
+
in an auth flow that may show:
|
|
113
|
+
|
|
114
|
+
- an error screen echoing an email address (`"No such account for user@…"`)
|
|
115
|
+
- one-time recovery codes displayed after MFA setup
|
|
116
|
+
- OTP flow copy or magic-link "check your inbox at foo@bar.com" text
|
|
117
|
+
|
|
118
|
+
Structure alone is enough to debug most UI issues (which element changed,
|
|
119
|
+
class toggles, layout shape). If you need the rendered text for a specific
|
|
120
|
+
support session — and you've confirmed no sensitive text lives in the
|
|
121
|
+
observed root at that time — set `capture.dom.includeText: true` explicitly.
|
|
122
|
+
Leave it off in production.
|
|
123
|
+
|
|
124
|
+
### Network plugin
|
|
125
|
+
|
|
126
|
+
- AWS RUM's built-in HTTP telemetry (latency/error/X-Ray) remains enabled.
|
|
127
|
+
- A custom network plugin intercepts `fetch` and `XMLHttpRequest` to record
|
|
128
|
+
request/response metadata, including all headers.
|
|
129
|
+
- `capture.network.urlFilter` acts as a whitelist so only approved hosts have
|
|
130
|
+
headers captured.
|
|
131
|
+
- `capture.network.maxHeaderLength` (default 2KB per header value) prevents
|
|
132
|
+
oversized payloads.
|
|
133
|
+
|
|
134
|
+
#### Network Plugin Architecture
|
|
135
|
+
|
|
136
|
+
The network plugin is organized into modular files for better maintainability:
|
|
137
|
+
|
|
138
|
+
- **`types.ts`**: Core type definitions (`HeadersMap`, `XhrMetadata`, `XhrWithMeta`) and constants (`XHR_METADATA` symbol)
|
|
139
|
+
- **`helpers.ts`**: 15+ pure utility functions for URL normalization, header extraction, filtering, and data transformation
|
|
140
|
+
- **`NetworkPlugin.ts`**: Main plugin class that patches browser APIs and orchestrates request/response capture
|
|
141
|
+
- **`index.ts`**: Public exports for plugin and helper functions
|
|
142
|
+
|
|
143
|
+
**Key optimizations:**
|
|
144
|
+
|
|
145
|
+
- Unified recording methods reduce code duplication between fetch and XHR paths
|
|
146
|
+
- Truncation function is created once and reused, not recreated per request
|
|
147
|
+
- Helper functions are extracted for independent testing and reusability
|
|
148
|
+
- Strong TypeScript types throughout with minimal use of `any`
|
|
149
|
+
|
|
150
|
+
## Lifecycle Helpers
|
|
151
|
+
|
|
152
|
+
| Method | Purpose |
|
|
153
|
+
| ---------------- | ----------------------------------------------------------------------------- |
|
|
154
|
+
| `enable()` | Re-enables all plugins after a temporary pause. |
|
|
155
|
+
| `disable()` | Disables plugins without disposing of the RUM client. |
|
|
156
|
+
| `shutdown()` | Disconnects plugins, disables the RUM client, and marks the manager unusable. |
|
|
157
|
+
| `isReady()` | Returns `true` when telemetry is initialized and not shut down. |
|
|
158
|
+
| `getRumClient()` | Gives access to the underlying AWS RUM instance for advanced scenarios. |
|
|
159
|
+
|
|
160
|
+
`shutdown()` is idempotent and guarded. Subsequent calls log a debug message
|
|
161
|
+
without throwing.
|
|
162
|
+
|
|
163
|
+
## Development Workflow
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
cd packages/libs/debug-logs
|
|
167
|
+
pnpm install # one-time
|
|
168
|
+
pnpm dev # watch mode + local test page on :5555
|
|
169
|
+
pnpm build # production bundle
|
|
170
|
+
pnpm test # full Jest suite (unit + integration)
|
|
171
|
+
pnpm lint # eslint over src and test
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- `rollup.config.dev.mjs` serves `test-standalone.html`, a local harness for
|
|
175
|
+
manual QA.
|
|
176
|
+
|
|
177
|
+
## Manual Playground (HTML)
|
|
178
|
+
|
|
179
|
+
The package ships with `test-standalone.html` — a one-page harness that
|
|
180
|
+
instantiates `TelemetryManager` directly and exposes buttons for every event
|
|
181
|
+
type (console, network, navigation, DOM mutations).
|
|
182
|
+
|
|
183
|
+
### Configure AWS CloudWatch RUM credentials
|
|
184
|
+
|
|
185
|
+
The form on the page is pre-populated from a `.env` file in this package
|
|
186
|
+
(`packages/libs/debug-logs/.env`). The file is gitignored. To set it up:
|
|
187
|
+
|
|
188
|
+
```env
|
|
189
|
+
DESCOPE_TELEMETRY_APPLICATION_ID=<cloudwatch-rum-app-monitor-id>
|
|
190
|
+
DESCOPE_TELEMETRY_IDENTITY_POOL_ID=<aws-cognito-identity-pool-id>
|
|
191
|
+
DESCOPE_TELEMETRY_REGION=<aws-region>
|
|
192
|
+
DESCOPE_TELEMETRY_GUEST_ROLE_ARN=<iam-guest-role-arn> # optional, classic flow only
|
|
193
|
+
DESCOPE_TELEMETRY_SESSION_SAMPLE_RATE=1 # optional, defaults to 1
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
How it works: when `pnpm dev` starts, a small rollup plugin (`emitDemoEnv`
|
|
197
|
+
in `rollup.config.dev.mjs`) reads `.env` and writes `dist/demo-env.js`,
|
|
198
|
+
which exposes the values on `window.__demoEnv`. The test page loads that
|
|
199
|
+
script and copies the values into the form fields.
|
|
200
|
+
|
|
201
|
+
**Restart `pnpm dev` after editing `.env`** — rollup's watch mode does not
|
|
202
|
+
watch `.env` itself. If any required key is missing, the page shows a red
|
|
203
|
+
warning banner above the form and logs a `console.warn` to DevTools.
|
|
204
|
+
|
|
205
|
+
### Run the playground
|
|
206
|
+
|
|
207
|
+
1. Run `pnpm dev` inside the package.
|
|
208
|
+
2. Browser opens at `http://localhost:5555/test-standalone.html`.
|
|
209
|
+
3. Click **🚀 Initialize Telemetry**.
|
|
210
|
+
4. Use the test buttons to emit events. Verify they reach CloudWatch RUM
|
|
211
|
+
by either:
|
|
212
|
+
- watching the Network tab for POSTs to the RUM data plane, or
|
|
213
|
+
- opening the CloudWatch RUM console → app monitor → your session.
|
|
214
|
+
|
|
215
|
+
## Troubleshooting
|
|
216
|
+
|
|
217
|
+
- **Nothing records**: Confirm `config.enabled` is `true` and that the AWS
|
|
218
|
+
credentials map to a valid RUM app.
|
|
219
|
+
- **Network capture too noisy**: Provide a stricter `urlFilter` array.
|
|
220
|
+
- **DOM plugin in SSR**: Gate `dom` capture to browsers; the plugin assumes
|
|
221
|
+
`document` exists.
|
|
222
|
+
- **Need to reuse after shutdown**: Instantiate a new `TelemetryManager`. A
|
|
223
|
+
shutdown instance intentionally cannot be restarted.
|
|
224
|
+
|
|
225
|
+
## Backward compatibility (important)
|
|
226
|
+
|
|
227
|
+
The web-component SDK loads `@descope/debug-logs` from the CDN **at runtime**,
|
|
228
|
+
pinned to `latest` (`config.version || 'latest'`). This is intentional - it lets
|
|
229
|
+
us adapt telemetry logic without redeploying every SDK. The consequence: **a new
|
|
230
|
+
release of this package is picked up immediately by already-deployed SDKs.**
|
|
231
|
+
|
|
232
|
+
So the public API must stay backward compatible across releases:
|
|
233
|
+
|
|
234
|
+
- Do not remove or rename the exported `TelemetryManager` methods
|
|
235
|
+
(`isReady`, `shutdown`, `enable`, `disable`, `updateContext`, `getRumClient`),
|
|
236
|
+
change the constructor shape `(config, context, logger?)`, or drop an exported
|
|
237
|
+
type.
|
|
238
|
+
- Prefer additive changes (new optional config, new methods).
|
|
239
|
+
- Recorded event shapes are additive too - adding fields is safe; removing or
|
|
240
|
+
renaming fields breaks consumers of the RUM data.
|
|
241
|
+
|
|
242
|
+
`test/apiContract.test.ts` asserts this surface. If it fails, a deployed SDK
|
|
243
|
+
loading `latest` will be affected - change it only as a deliberate, coordinated
|
|
244
|
+
decision.
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT License. See the root repository `LICENSE` file for details.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("aws-rum-web");class e{constructor(t={}){this.enabled=!1,this.id="console-plugin",this.originalMethods={log:console.log,info:console.info,warn:console.warn,error:console.error,debug:console.debug},this.levels=new Set(t.levels||["log","info","warn","error","debug"]),this.maxMessageLength=t.maxMessageLength??10240}load(t){this.context=t,this.enable()}enable(){this.enabled||(this.enabled=!0,["log","info","warn","error","debug"].forEach((t=>{this.levels.has(t)&&(console[t]=(...e)=>{if(this.originalMethods[t](...e),this.enabled)try{let r=e.map((t=>"object"==typeof t?JSON.stringify(t):String(t))).join(" ");r.length>this.maxMessageLength&&(r=r.substring(0,this.maxMessageLength-20)+"... [truncated]"),this.context.record("console_log",{level:t,message:r,timestamp:Date.now()})}catch(t){}})})))}disable(){this.enabled&&(this.enabled=!1,["log","info","warn","error","debug"].forEach((t=>{this.levels.has(t)&&(console[t]=this.originalMethods[t])})))}getPluginId(){return this.id}}class r{constructor(){this.enabled=!1,this.id="navigation-plugin",this.originalPushState=history.pushState,this.originalReplaceState=history.replaceState,this.currentUrl="",this.eventHandlers=[]}load(t){this.context=t,this.currentUrl=window.location.href,this.enable()}enable(){if(this.enabled)return;this.enabled=!0,history.pushState=(...t)=>{const e=this.currentUrl;try{this.originalPushState.apply(history,t),this.currentUrl=window.location.href,this.recordNavigation(e,this.currentUrl,"pushState")}catch(t){throw this.currentUrl=window.location.href,t}},history.replaceState=(...t)=>{const e=this.currentUrl;try{this.originalReplaceState.apply(history,t),this.currentUrl=window.location.href,this.recordNavigation(e,this.currentUrl,"replaceState")}catch(t){throw this.currentUrl=window.location.href,t}};const t=()=>{const t=this.currentUrl;this.currentUrl=window.location.href,this.recordNavigation(t,this.currentUrl,"popstate")};window.addEventListener("popstate",t),this.eventHandlers.push({type:"popstate",handler:t});const e=()=>{const t=this.currentUrl;this.currentUrl=window.location.href,this.recordNavigation(t,this.currentUrl,"hashchange")};window.addEventListener("hashchange",e),this.eventHandlers.push({type:"hashchange",handler:e})}disable(){this.enabled&&(this.enabled=!1,history.pushState=this.originalPushState,history.replaceState=this.originalReplaceState,this.eventHandlers.forEach((({type:t,handler:e})=>{window.removeEventListener(t,e)})),this.eventHandlers=[])}getPluginId(){return this.id}recordNavigation(t,e,r){if(this.enabled)try{this.context.record("navigation",{type:r,from:t,to:e,timestamp:Date.now()})}catch(t){}}}class i{constructor(t={}){this.enabled=!1,this.id="dom-mutation-plugin",this.observer=null,this.pendingMutations=[],this.flushTimeout=null,this.rootElement=document.body,this.config=t,this.throttleMs=t.throttleMs||100,this.maxHtmlLength=t.maxHtmlLength??51200,this.includeText=!0===t.includeText}load(t){this.context=t,this.enable()}enable(){if(this.enabled)return;this.enabled=!0;let t=document.body;if(this.config.rootElement)if("string"==typeof this.config.rootElement){const e=document.querySelector(this.config.rootElement);e&&(t=e)}else t=this.config.rootElement;this.rootElement=t;try{this.observer=new MutationObserver((t=>{this.enabled&&this.scheduleMutationFlush(t)})),this.observer.observe(this.rootElement,{childList:!0,attributes:!0,characterData:!0,subtree:!0,attributeOldValue:!1,characterDataOldValue:!1});const t=this.snapshotHTML();t&&this.context.record("dom_mutation",{addedNodes:0,removedNodes:0,attributeChanges:0,characterDataChanges:0,timestamp:Date.now(),rootElementHTML:t,initial:!0})}catch(t){console.debug("DOM mutation plugin failed to start:",t)}}snapshotHTML(){const t=(this.includeText?this.rootElement:function(t){const e=document.createElement("div");e.innerHTML=t.innerHTML;const r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),i=[];let s=r.nextNode();for(;s;)i.push(s),s=r.nextNode();return i.forEach((t=>t.parentNode?.removeChild(t))),e}(this.rootElement)).innerHTML;return t.length>this.maxHtmlLength?t.substring(0,this.maxHtmlLength-20)+"... [truncated]":t}disable(){if(!this.enabled)return;this.enabled=!1,this.flushTimeout&&(clearTimeout(this.flushTimeout),this.flushTimeout=null),this.observer&&(this.observer.disconnect(),this.observer=null);const t=[...this.pendingMutations];this.pendingMutations=[],t.length>0&&this.recordPendingMutations(t)}getPluginId(){return this.id}scheduleMutationFlush(t){this.enabled&&(this.pendingMutations.push(...t),this.flushTimeout&&clearTimeout(this.flushTimeout),this.flushTimeout=setTimeout((()=>{this.enabled&&this.flushMutations()}),this.throttleMs))}flushMutations(){this.enabled&&this.observer&&(this.recordPendingMutations(),this.flushTimeout=null)}recordPendingMutations(t){if(!t&&!this.enabled)return;const e=t||this.pendingMutations;if(0!==e.length){try{let t=0,r=0,i=0,s=0;for(const n of e)t+=n.addedNodes.length,r+=n.removedNodes.length,"attributes"===n.type?i++:"characterData"===n.type&&s++;const n=t>0||r>0?this.snapshotHTML():"";this.context.record("dom_mutation",{addedNodes:t,removedNodes:r,attributeChanges:i,characterDataChanges:s,timestamp:Date.now(),rootElementHTML:n})}catch(t){}t||(this.pendingMutations=[])}}}function s(t){return"undefined"!=typeof Request&&t instanceof Request}function n(t,e){const r={};if(!t)return r;const i=(t,i)=>{const s=t.toLowerCase(),n=e?e(i):i;r[s]=n};return"undefined"!=typeof Headers&&t instanceof Headers?(t.forEach(((t,e)=>i(e,t))),r):Array.isArray(t)?(t.forEach((([t,e])=>i(t,e))),r):(Object.entries(t).forEach((([t,e])=>i(t,String(e)))),r)}function o(t,e){const r={};return t?(t.trim().split(/\r?\n/).forEach((t=>{const i=t.indexOf(":");if(-1===i)return;const s=t.slice(0,i).trim().toLowerCase(),n=t.slice(i+1).trim();r[s]=e(n)})),r):r}function a(t){if(!t)return t;try{return new URL(t,window.location.href).toString()}catch{return t}}function h(t,e){return!!t&&(!e||0===e.length||e.some((e=>{try{return e.test(t)}catch(t){return console.debug("Network plugin filter failed:",t),!1}})))}function l(t,e){return t.headers?n(t.headers,e):{}}function c(t,e){console.debug(t,e)}function u(t){return Date.now()-t}const d=Symbol("network-plugin-metadata");class g{constructor(t={}){this.enabled=!1,this.id="network-plugin",this.urlFilters=function(t){if(t)return Array.isArray(t)?t:[t]}(t.urlFilter),this.maxHeaderLength=t.maxHeaderLength??2048,this.truncate=t=>function(t,e){return t.length<=e?t:t.substring(0,e-20)+"... [truncated]"}(t,this.maxHeaderLength)}load(t){this.context=t,this.enable()}enable(){this.enabled||(this.enabled=!0,this.patchFetch(),this.patchXhr())}disable(){this.enabled&&(this.enabled=!1,this.restoreFetch(),this.restoreXhr())}getPluginId(){return this.id}patchFetch(){if("function"!=typeof window.fetch)return;this.originalFetch||(this.originalFetch=window.fetch);const t=this.originalFetch,e=this;window.fetch=function(...r){return e.handleFetch(t,r,this??window)}}restoreFetch(){this.originalFetch&&(window.fetch=this.originalFetch)}patchXhr(){if("undefined"==typeof XMLHttpRequest)return;this.originalXhrOpen||(this.originalXhrOpen=XMLHttpRequest.prototype.open,this.originalXhrSend=XMLHttpRequest.prototype.send,this.originalXhrSetRequestHeader=XMLHttpRequest.prototype.setRequestHeader);const t=this;XMLHttpRequest.prototype.open=function(e,r,i,s,n){const o=this;try{const i=t.getXhrMeta(o);i.method=(e||"GET").toUpperCase();const s="string"==typeof r?r:r?.toString()||"";i.url=a(s)}catch(t){c("XHR metadata collection failed:",t)}return t.originalXhrOpen.call(this,e,r,i??!0,s??null,n??null)},XMLHttpRequest.prototype.setRequestHeader=function(e,r){const i=this;try{const s=t.getXhrMeta(i);e&&(s.requestHeaders[e.toLowerCase()]=t.truncate(String(r??"")))}catch(t){c("XHR header capture failed:",t)}return t.originalXhrSetRequestHeader.call(this,e,r)},XMLHttpRequest.prototype.send=function(e){const r=this;let i=!1;try{const e=t.getXhrMeta(r);e.startTime=Date.now(),e.url||(e.url=a(r.responseURL||"")),i=h(e.url||"",t.urlFilters)}catch(t){c("XHR send metadata check failed:",t)}if(!i)return t.originalXhrSend.call(this,e);const s=()=>{try{t.recordXhrSuccess(r)}catch(t){c("XHR success recording failed:",t)}o()},n=e=>{try{t.recordXhrError(r,e.type)}catch(t){c("XHR error recording failed:",t)}o()},o=()=>{try{r.removeEventListener("load",s),r.removeEventListener("error",n),r.removeEventListener("abort",n),r.removeEventListener("timeout",n),delete r[d]}catch(t){c("XHR cleanup failed:",t)}};try{r.addEventListener("load",s),r.addEventListener("error",n),r.addEventListener("abort",n),r.addEventListener("timeout",n)}catch(t){c("XHR event listener attachment failed:",t)}return t.originalXhrSend.call(this,e)}}restoreXhr(){"undefined"!=typeof XMLHttpRequest&&(this.originalXhrOpen&&(XMLHttpRequest.prototype.open=this.originalXhrOpen),this.originalXhrSend&&(XMLHttpRequest.prototype.send=this.originalXhrSend),this.originalXhrSetRequestHeader&&(XMLHttpRequest.prototype.setRequestHeader=this.originalXhrSetRequestHeader))}handleFetch(t,e,r){if(!this.enabled)return t.apply(r,e);const[i,o]=e,d=a(function(t){return"string"==typeof t?t:t instanceof URL?t.toString():s(t)?t.url:String(t)}(i));if(!h(d,this.urlFilters))return t.apply(r,e);const g=function(t,e){return e?.method?e.method.toUpperCase():s(t)&&t.method?t.method.toUpperCase():"GET"}(i,o),p=function(t,e,r){const i={};return s(t)&&Object.assign(i,n(t.headers,r)),e?.headers&&Object.assign(i,n(e.headers,r)),i}(i,o,this.truncate),f=Date.now();return t.apply(r,e).then((t=>{try{this.recordNetworkSuccess({transport:"fetch",url:d,method:g,status:t.status,statusText:t.statusText,duration:u(f),timestamp:f,requestHeaders:p,responseHeaders:l(t,this.truncate)})}catch(t){c("Failed to record network success:",t)}return t})).catch((t=>{try{this.recordNetworkError({transport:"fetch",url:d,method:g,duration:u(f),timestamp:f,requestHeaders:p,error:t instanceof Error?t.message:String(t)})}catch(t){c("Failed to record network error:",t)}throw t}))}recordXhrSuccess(t){if(!this.enabled)return;const e=t[d];e?.startTime&&e.url&&this.recordNetworkSuccess({transport:"xhr",url:e.url,method:e.method||"GET",status:t.status,statusText:t.statusText,duration:u(e.startTime),timestamp:e.startTime,requestHeaders:e.requestHeaders,responseHeaders:o(t.getAllResponseHeaders(),this.truncate)})}recordXhrError(t,e){if(!this.enabled)return;const r=t[d];r?.startTime&&r.url&&this.recordNetworkError({transport:"xhr",url:r.url,method:r.method||"GET",duration:u(r.startTime),timestamp:r.startTime,requestHeaders:r.requestHeaders,status:t.status,statusText:t.statusText,error:e})}recordNetworkSuccess(t){if(this.enabled)try{this.context.record("network_request",t)}catch(t){c("Network plugin failed to record request:",t)}}recordNetworkError(t){if(this.enabled)try{this.context.record("network_error",t)}catch(t){c("Network plugin failed to record error:",t)}}getXhrMeta(t){return t[d]||(t[d]={requestHeaders:{}}),t[d]}}function p(t){if(t)return"object"==typeof t?t:{}}exports.default=class{constructor(t,e,r=console){if(this.rumClient=null,this.plugins=[],this.isShutdown=!1,this.initializationFailed=!1,this.config=t,this.context=e,this.logger=r,t.enabled)try{this.initializeRumClient()}catch(t){this.initializationFailed=!0,this.logger.error("Telemetry initialization failed:",t)}else this.logger.debug("Telemetry is disabled")}initializeRumClient(){try{const t=[...this.buildHttpTelemetry(),"errors"],e=this.buildCustomPlugins();this.rumClient=this.createRumClient(t,e),this.rumClient.addSessionAttributes({projectId:this.context.projectId,flowId:this.context.flowId}),this.plugins.forEach((t=>{t.enable()}));const r=this.tryGetSessionId();this.logger.info(`TelemetryManager: RUM client ready (sessionId=${r??"unknown"})`)}catch(t){throw this.logger.error("Failed to initialize telemetry:",t),t}}buildHttpTelemetry(){if(!1===this.config.capture?.network)return[];const t={recordAllRequests:!0,addXRayTraceIdHeader:!1,stackTraceLength:200},e=this.config.capture?.network?.urlFilter;if(e){const r=Array.isArray(e)?e:[e];t.recordResourceUrl=t=>r.some((e=>e.test(t)))}return[["http",t]]}buildCustomPlugins(){const t=[];if(!1!==this.config.capture?.console){const r=p(this.config.capture?.console);t.push(new e(r))}if(!1!==this.config.capture?.navigation&&t.push(new r),!1!==this.config.capture?.network){const e=p(this.config.capture?.network);t.push(new g(e))}if(!1!==this.config.capture?.dom){const e=p(this.config.capture?.dom);t.push(new i(e))}return this.plugins.push(...t),t}createRumClient(e,r){const i={endpoint:this.config.rumConfig.endpoint,telemetries:e,eventPluginsToLoad:r,allowCookies:!0,enableXRay:!1,sessionEventLimit:1e4,batchLimit:500,eventCacheSize:2e3,dispatchInterval:5e3,...this.config.rumConfig};return this.logger.debug("Creating RUM client with config:",i),new t.AwsRum(this.config.rumConfig.applicationId,this.context.version||"1.0.0",this.config.rumConfig.region,i)}shutdown(){this.isShutdown?this.logger.debug("Telemetry already shutdown"):(this.isShutdown=!0,this.safe("shutdown rum client",(()=>{this.rumClient&&(this.rumClient.disable(),this.rumClient=null)})),this.plugins.forEach((t=>{this.safe("disable plugin",(()=>t.disable()))})),this.plugins=[],this.logger.debug("Telemetry shutdown complete"))}enable(){this.assertMutable("enable")&&this.safe("enable",(()=>{this.plugins.forEach((t=>t.enable())),this.logger.debug("Telemetry enabled")}))}disable(){this.assertMutable("disable")&&this.safe("disable",(()=>{this.plugins.forEach((t=>t.disable())),this.logger.debug("Telemetry disabled")}))}updateContext(t){this.assertMutable("update telemetry context")&&this.safe("update telemetry context",(()=>{const e=Object.fromEntries(Object.entries(t).filter((([,t])=>void 0!==t)));this.context={...this.context,...e},this.rumClient.addSessionAttributes(e),this.logger.debug("Telemetry context updated:",e)}))}isReady(){return!this.isShutdown&&!this.initializationFailed&&null!==this.rumClient}getRumClient(){return this.rumClient}assertMutable(t){return this.initializationFailed?(this.logger.error(`Cannot ${t}: telemetry initialization failed`),!1):this.isShutdown?(this.logger.error(`Cannot ${t}: telemetry has been shutdown. Create a new instance.`),!1):!!this.rumClient||(this.logger.error(`Cannot ${t}: telemetry not initialized`),!1)}safe(t,e){try{e()}catch(e){this.logger.error(`Failed to ${t}:`,e)}}tryGetSessionId(){try{return this.rumClient?.eventCache?.getSession?.()?.sessionId??null}catch{return null}}};
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/plugins/consolePlugin.ts","../../src/plugins/navigationPlugin.ts","../../src/plugins/domMutationPlugin.ts","../../src/plugins/networkPlugin/helpers.ts","../../src/plugins/networkPlugin/types.ts","../../src/plugins/networkPlugin/NetworkPlugin.ts","../../src/telemetryManager.ts"],"sourcesContent":[null,null,null,null,null,null,null],"names":["ConsolePlugin","constructor","config","this","enabled","id","originalMethods","log","console","info","warn","error","debug","levels","Set","maxMessageLength","load","context","enable","forEach","level","has","args","message","map","arg","JSON","stringify","String","join","length","substring","record","timestamp","Date","now","disable","getPluginId","NavigationPlugin","originalPushState","history","pushState","originalReplaceState","replaceState","currentUrl","eventHandlers","window","location","href","previousUrl","apply","recordNavigation","handlePopState","addEventListener","push","type","handler","handleHashChange","removeEventListener","from","to","DomMutationPlugin","observer","pendingMutations","flushTimeout","rootElement","document","body","throttleMs","maxHtmlLength","includeText","observeTarget","element","querySelector","MutationObserver","mutations","scheduleMutationFlush","observe","childList","attributes","characterData","subtree","attributeOldValue","characterDataOldValue","rootElementHTML","snapshotHTML","addedNodes","removedNodes","attributeChanges","characterDataChanges","initial","raw","root","container","createElement","innerHTML","walker","createTreeWalker","NodeFilter","SHOW_TEXT","toRemove","node","nextNode","n","parentNode","removeChild","stripTextNodes","clearTimeout","disconnect","mutationsToFlush","recordPendingMutations","setTimeout","flushMutations","mutationsToRecord","m","isRequest","input","Request","toHeadersMap","headers","truncate","result","applyPair","key","value","normalizedKey","toLowerCase","normalizedValue","Headers","Array","isArray","Object","entries","parseResponseHeaders","rawHeaders","trim","split","line","separatorIndex","indexOf","slice","normalizeUrl","url","URL","toString","shouldCaptureUrl","urlFilters","some","filter","test","extractResponseHeaders","response","safeDebugLog","calculateDuration","startTime","XHR_METADATA","Symbol","NetworkPlugin","normalizeFilters","urlFilter","maxHeaderLength","maxLength","truncateHeader","patchFetch","patchXhr","restoreFetch","restoreXhr","fetch","originalFetch","plugin","handleFetch","XMLHttpRequest","originalXhrOpen","prototype","open","originalXhrSend","send","originalXhrSetRequestHeader","setRequestHeader","method","async","username","password","xhr","meta","getXhrMeta","toUpperCase","urlString","call","requestHeaders","shouldCapture","responseURL","handleLoad","recordXhrSuccess","cleanup","handleError","event","recordXhrError","thisArg","init","extractUrl","extractMethod","assign","extractRequestHeaders","then","recordNetworkSuccess","transport","status","statusText","duration","responseHeaders","recordError","catch","recordNetworkError","Error","getAllResponseHeaders","data","normalizeConfig","logger","rumClient","plugins","isShutdown","initializationFailed","initializeRumClient","telemetries","buildHttpTelemetry","eventPluginsToLoad","buildCustomPlugins","createRumClient","addSessionAttributes","projectId","flowId","sessionId","tryGetSessionId","capture","network","httpConfig","recordAllRequests","addXRayTraceIdHeader","stackTraceLength","filters","recordResourceUrl","navigation","dom","rumConfig","endpoint","allowCookies","enableXRay","sessionEventLimit","batchLimit","eventCacheSize","dispatchInterval","AwsRum","applicationId","version","region","shutdown","safe","assertMutable","updateContext","filteredContext","fromEntries","undefined","isReady","getRumClient","op","fn","eventCache","getSession"],"mappings":"uGAiBaA,EAeX,WAAAC,CAAYC,EAA8B,IAblCC,KAAOC,SAAG,EACDD,KAAEE,GAAG,iBAIdF,KAAAG,gBAAkB,CACxBC,IAAKC,QAAQD,IACbE,KAAMD,QAAQC,KACdC,KAAMF,QAAQE,KACdC,MAAOH,QAAQG,MACfC,MAAOJ,QAAQI,OAKfT,KAAKU,OAAS,IAAIC,IAChBZ,EAAOW,QAAU,CAAC,MAAO,OAAQ,OAAQ,QAAS,UAEpDV,KAAKY,iBACHb,EAAOa,kBA3BsB,MA8BjC,IAAAC,CAAKC,GACHd,KAAKc,QAAUA,EACfd,KAAKe,SAGP,MAAAA,GACMf,KAAKC,UACTD,KAAKC,SAAU,EAGd,CAAC,MAAO,OAAQ,OAAQ,QAAS,SAAmBe,SAASC,IACvDjB,KAAKU,OAAOQ,IAAID,KAErBZ,QAAQY,GAAS,IAAIE,KAKnB,GAHAnB,KAAKG,gBAAgBc,MAAUE,GAG1BnB,KAAKC,QAGV,IAEE,IAAImB,EAAUD,EACXE,KAAKC,GACW,iBAARA,EAAmBC,KAAKC,UAAUF,GAAOG,OAAOH,KAExDI,KAAK,KAGJN,EAAQO,OAAS3B,KAAKY,mBACxBQ,EACEA,EAAQQ,UAAU,EAAG5B,KAAKY,iBAAmB,IAC7C,mBAIJZ,KAAKc,QAAQe,OAAO,cAAe,CACjCZ,QACAG,UACAU,UAAWC,KAAKC,QAElB,MAAOxB,MAGV,KAIL,OAAAyB,GACOjC,KAAKC,UACVD,KAAKC,SAAU,EAGd,CAAC,MAAO,OAAQ,OA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AAOkI,YAC7BlI,OAAOC,QAAQnH,GAASmI,QAAO,EAAI,CAAAxB,UAAqB0I,IAAV1I,KAEhDzH,KAAKc,QAAU,IAAKd,KAAKc,WAAYmP,GACrCjQ,KAAKwN,UAAWU,qBAAqB+B,GACrCjQ,KAAKuN,OAAO9M,MAAM,6BAA8BwP,EAAgB,IAIpE,OAAAG,GACE,OACGpQ,KAAK0N,aAAe1N,KAAK2N,sBAA2C,OAAnB3N,KAAKwN,UAI3D,YAAA6C,GACE,OAAOrQ,KAAKwN,UAGN,aAAAuC,CAAcO,GACpB,OAAItQ,KAAK2N,sBACP3N,KAAKuN,OAAO/M,MAAM,UAAU8P,uCACrB,GAELtQ,KAAK0N,YACP1N,KAAKuN,OAAO/M,MACV,UAAU8P,2DAEL,KAEJtQ,KAAKwN,YACRxN,KAAKuN,OAAO/M,MAAM,UAAU8P,iCACrB,GAKH,IAAAR,CAAKQ,EAAYC,GACvB,IACEA,IACA,MAAO/P,GACPR,KAAKuN,OAAO/M,MAAM,aAAa8P,KAAO9P,IASlC,eAAA8N,GACN,IACE,OACGtO,KAAKwN,WAAmBgD,YAAYC,gBAAgBpC,WAAa,KAEpE,MACA,OAAO"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TelemetryManager } from './telemetryManager';
|
|
2
|
+
export default TelemetryManager;
|
|
3
|
+
export type { Logger } from './telemetryManager';
|
|
4
|
+
export type { TelemetryConfig, TelemetryContext, NetworkCaptureConfig, } from './types';
|
|
5
|
+
export type { ConsoleLevel } from './plugins/consolePlugin';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Plugin, PluginContext } from 'aws-rum-web';
|
|
2
|
+
export type ConsoleLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
3
|
+
export interface ConsolePluginConfig {
|
|
4
|
+
levels?: ConsoleLevel[];
|
|
5
|
+
maxMessageLength?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Console Plugin for AWS RUM
|
|
9
|
+
* Records console.log/info/warn/error/debug calls as custom events
|
|
10
|
+
*/
|
|
11
|
+
export declare class ConsolePlugin implements Plugin {
|
|
12
|
+
private context;
|
|
13
|
+
private enabled;
|
|
14
|
+
private readonly id;
|
|
15
|
+
private readonly levels;
|
|
16
|
+
private readonly maxMessageLength;
|
|
17
|
+
private originalMethods;
|
|
18
|
+
constructor(config?: ConsolePluginConfig);
|
|
19
|
+
load(context: PluginContext): void;
|
|
20
|
+
enable(): void;
|
|
21
|
+
disable(): void;
|
|
22
|
+
getPluginId(): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Plugin, PluginContext } from 'aws-rum-web';
|
|
2
|
+
export interface DomMutationPluginConfig {
|
|
3
|
+
rootElement?: string | HTMLElement;
|
|
4
|
+
throttleMs?: number;
|
|
5
|
+
maxHtmlLength?: number;
|
|
6
|
+
/**
|
|
7
|
+
* When false (DEFAULT), the DOM snapshot strips all text nodes — only tag
|
|
8
|
+
* hierarchy + attributes are recorded. Prevents rendered content leaking
|
|
9
|
+
* into RUM (e.g. an error screen echoing an email, one-time recovery codes,
|
|
10
|
+
* OTP flow copy). Structure is enough to debug most UI issues.
|
|
11
|
+
*
|
|
12
|
+
* Set to true only when you need to see rendered text for a specific
|
|
13
|
+
* support session, and confirm no sensitive text lives in the observed
|
|
14
|
+
* root at that time.
|
|
15
|
+
*/
|
|
16
|
+
includeText?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* DOM Mutation Plugin for AWS RUM
|
|
20
|
+
* Records aggregated DOM mutations using MutationObserver
|
|
21
|
+
*/
|
|
22
|
+
export declare class DomMutationPlugin implements Plugin {
|
|
23
|
+
private context;
|
|
24
|
+
private enabled;
|
|
25
|
+
private readonly id;
|
|
26
|
+
private observer;
|
|
27
|
+
private pendingMutations;
|
|
28
|
+
private flushTimeout;
|
|
29
|
+
private throttleMs;
|
|
30
|
+
private maxHtmlLength;
|
|
31
|
+
private includeText;
|
|
32
|
+
private config;
|
|
33
|
+
private rootElement;
|
|
34
|
+
constructor(config?: DomMutationPluginConfig);
|
|
35
|
+
load(context: PluginContext): void;
|
|
36
|
+
enable(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Serialize the observed root's HTML for a snapshot: strips text nodes unless
|
|
39
|
+
* includeText is set, then truncates to maxHtmlLength. Shared by the initial
|
|
40
|
+
* baseline snapshot and the structural-mutation path so the truncation math
|
|
41
|
+
* can't drift between the two.
|
|
42
|
+
*/
|
|
43
|
+
private snapshotHTML;
|
|
44
|
+
disable(): void;
|
|
45
|
+
getPluginId(): string;
|
|
46
|
+
private scheduleMutationFlush;
|
|
47
|
+
private flushMutations;
|
|
48
|
+
/**
|
|
49
|
+
* Records mutations.
|
|
50
|
+
* @param mutations - Mutations to record. If not provided, uses this.pendingMutations
|
|
51
|
+
*/
|
|
52
|
+
private recordPendingMutations;
|
|
53
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Plugin, PluginContext } from 'aws-rum-web';
|
|
2
|
+
/**
|
|
3
|
+
* Navigation Plugin for AWS RUM
|
|
4
|
+
* Records SPA navigation events (pushState, replaceState, popstate, hashchange)
|
|
5
|
+
*/
|
|
6
|
+
export declare class NavigationPlugin implements Plugin {
|
|
7
|
+
private context;
|
|
8
|
+
private enabled;
|
|
9
|
+
private readonly id;
|
|
10
|
+
private originalPushState;
|
|
11
|
+
private originalReplaceState;
|
|
12
|
+
private currentUrl;
|
|
13
|
+
private eventHandlers;
|
|
14
|
+
load(context: PluginContext): void;
|
|
15
|
+
enable(): void;
|
|
16
|
+
disable(): void;
|
|
17
|
+
getPluginId(): string;
|
|
18
|
+
private recordNavigation;
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Plugin, PluginContext } from 'aws-rum-web';
|
|
2
|
+
import type { NetworkCaptureConfig } from '../../types';
|
|
3
|
+
export declare class NetworkPlugin implements Plugin {
|
|
4
|
+
private context;
|
|
5
|
+
private enabled;
|
|
6
|
+
private readonly id;
|
|
7
|
+
private readonly urlFilters?;
|
|
8
|
+
private readonly maxHeaderLength;
|
|
9
|
+
private readonly truncate;
|
|
10
|
+
private originalFetch?;
|
|
11
|
+
private originalXhrOpen?;
|
|
12
|
+
private originalXhrSend?;
|
|
13
|
+
private originalXhrSetRequestHeader?;
|
|
14
|
+
constructor(config?: NetworkCaptureConfig);
|
|
15
|
+
load(context: PluginContext): void;
|
|
16
|
+
enable(): void;
|
|
17
|
+
disable(): void;
|
|
18
|
+
getPluginId(): string;
|
|
19
|
+
private patchFetch;
|
|
20
|
+
private restoreFetch;
|
|
21
|
+
private patchXhr;
|
|
22
|
+
private restoreXhr;
|
|
23
|
+
private handleFetch;
|
|
24
|
+
private recordXhrSuccess;
|
|
25
|
+
private recordXhrError;
|
|
26
|
+
private recordNetworkSuccess;
|
|
27
|
+
private recordNetworkError;
|
|
28
|
+
private getXhrMeta;
|
|
29
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { HeadersMap } from './types';
|
|
2
|
+
export declare const DEFAULT_MAX_HEADER_LENGTH = 2048;
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes filter input to an array of RegExp or undefined
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeFilters(filter?: RegExp | RegExp[]): RegExp[] | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to check if input is a Request object
|
|
9
|
+
*/
|
|
10
|
+
export declare function isRequest(input: RequestInfo | URL): input is Request;
|
|
11
|
+
/**
|
|
12
|
+
* Converts various header formats to a normalized HeadersMap
|
|
13
|
+
*/
|
|
14
|
+
export declare function toHeadersMap(headers?: Headers | HeadersInit, truncate?: (value: string) => string): HeadersMap;
|
|
15
|
+
/**
|
|
16
|
+
* Parses raw HTTP header string into a HeadersMap
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseResponseHeaders(rawHeaders: string, truncate: (value: string) => string): HeadersMap;
|
|
19
|
+
/**
|
|
20
|
+
* Truncates a header value to a maximum length
|
|
21
|
+
*/
|
|
22
|
+
export declare function truncateHeader(value: string, maxLength: number): string;
|
|
23
|
+
/**
|
|
24
|
+
* Normalizes a URL string to an absolute URL
|
|
25
|
+
*/
|
|
26
|
+
export declare function normalizeUrl(url: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Tests if a URL matches any of the provided filters
|
|
29
|
+
*/
|
|
30
|
+
export declare function shouldCaptureUrl(url: string, urlFilters?: RegExp[]): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Extracts HTTP method from fetch input
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractMethod(input: RequestInfo | URL, init?: RequestInit): string;
|
|
35
|
+
/**
|
|
36
|
+
* Extracts URL string from fetch input
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractUrl(input: RequestInfo | URL): string;
|
|
39
|
+
/**
|
|
40
|
+
* Extracts and normalizes request headers from fetch input
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractRequestHeaders(input: RequestInfo | URL, init: RequestInit | undefined, truncate: (value: string) => string): HeadersMap;
|
|
43
|
+
/**
|
|
44
|
+
* Extracts and normalizes response headers
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractResponseHeaders(response: Response, truncate: (value: string) => string): HeadersMap;
|
|
47
|
+
/**
|
|
48
|
+
* Safely logs debug messages with error handling
|
|
49
|
+
*/
|
|
50
|
+
export declare function safeDebugLog(message: string, error: unknown): void;
|
|
51
|
+
/**
|
|
52
|
+
* Calculates duration from start time
|
|
53
|
+
*/
|
|
54
|
+
export declare function calculateDuration(startTime: number): number;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { NetworkPlugin } from './NetworkPlugin';
|
|
2
|
+
export type { HeadersMap, XhrMetadata, XhrWithMeta } from './types';
|
|
3
|
+
export { XHR_METADATA } from './types';
|
|
4
|
+
export { extractMethod, extractUrl, extractRequestHeaders, extractResponseHeaders, normalizeUrl, shouldCaptureUrl, } from './helpers';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type HeadersMap = Record<string, string>;
|
|
2
|
+
export declare const XHR_METADATA: unique symbol;
|
|
3
|
+
export interface XhrMetadata {
|
|
4
|
+
method?: string;
|
|
5
|
+
url?: string;
|
|
6
|
+
startTime?: number;
|
|
7
|
+
requestHeaders: HeadersMap;
|
|
8
|
+
}
|
|
9
|
+
export type XhrWithMeta = XMLHttpRequest & {
|
|
10
|
+
[XHR_METADATA]?: XhrMetadata;
|
|
11
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { AwsRum } from 'aws-rum-web';
|
|
2
|
+
import type { TelemetryConfig, TelemetryContext } from './types';
|
|
3
|
+
export interface Logger {
|
|
4
|
+
debug: (...args: any[]) => void;
|
|
5
|
+
info: (...args: any[]) => void;
|
|
6
|
+
error: (...args: any[]) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* TelemetryManager - Class-based telemetry management for AWS CloudWatch RUM
|
|
10
|
+
*
|
|
11
|
+
* Manages the lifecycle of AWS RUM client and custom plugins for telemetry collection.
|
|
12
|
+
*
|
|
13
|
+
* Note: Initialization happens in the constructor. Once shutdown() is called,
|
|
14
|
+
* the instance cannot be reused - create a new instance instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare class TelemetryManager {
|
|
17
|
+
private rumClient;
|
|
18
|
+
private plugins;
|
|
19
|
+
private config;
|
|
20
|
+
private context;
|
|
21
|
+
private logger;
|
|
22
|
+
private isShutdown;
|
|
23
|
+
private initializationFailed;
|
|
24
|
+
constructor(config: TelemetryConfig, context: TelemetryContext, logger?: Logger);
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the RUM client and plugins
|
|
27
|
+
*/
|
|
28
|
+
private initializeRumClient;
|
|
29
|
+
/**
|
|
30
|
+
* Build HTTP telemetry configuration
|
|
31
|
+
*/
|
|
32
|
+
private buildHttpTelemetry;
|
|
33
|
+
/**
|
|
34
|
+
* Build all custom event plugins
|
|
35
|
+
*/
|
|
36
|
+
private buildCustomPlugins;
|
|
37
|
+
/**
|
|
38
|
+
* Create AWS RUM client instance
|
|
39
|
+
*/
|
|
40
|
+
private createRumClient;
|
|
41
|
+
/**
|
|
42
|
+
* Shutdown the telemetry manager and cleanup resources.
|
|
43
|
+
* After calling shutdown, this instance cannot be reused.
|
|
44
|
+
*/
|
|
45
|
+
shutdown(): void;
|
|
46
|
+
enable(): void;
|
|
47
|
+
disable(): void;
|
|
48
|
+
updateContext(context: Partial<Record<string, string | number | boolean>>): void;
|
|
49
|
+
isReady(): boolean;
|
|
50
|
+
getRumClient(): AwsRum | null;
|
|
51
|
+
private assertMutable;
|
|
52
|
+
private safe;
|
|
53
|
+
/**
|
|
54
|
+
* aws-rum-web does not expose a public getSessionId(); the session lives
|
|
55
|
+
* inside the private eventCache. Reach in for debug logging only — keep
|
|
56
|
+
* this strictly best-effort.
|
|
57
|
+
*/
|
|
58
|
+
private tryGetSessionId;
|
|
59
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ConsoleLevel } from './plugins/consolePlugin';
|
|
2
|
+
export interface NetworkCaptureConfig {
|
|
3
|
+
urlFilter?: RegExp | RegExp[];
|
|
4
|
+
maxHeaderLength?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface TelemetryConfig {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
rumConfig: {
|
|
9
|
+
sessionSampleRate: number;
|
|
10
|
+
applicationId: string;
|
|
11
|
+
identityPoolId: string;
|
|
12
|
+
guestRoleArn?: string;
|
|
13
|
+
region: string;
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
};
|
|
16
|
+
capture?: {
|
|
17
|
+
console?: boolean | {
|
|
18
|
+
levels?: ConsoleLevel[];
|
|
19
|
+
};
|
|
20
|
+
network?: boolean | NetworkCaptureConfig;
|
|
21
|
+
navigation?: boolean;
|
|
22
|
+
dom?: boolean | {
|
|
23
|
+
rootElement?: string | HTMLElement;
|
|
24
|
+
throttleMs?: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface TelemetryContext {
|
|
29
|
+
projectId: string;
|
|
30
|
+
flowId: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
}
|