
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@kyletaylored/datadog-rum-interceptor
Advanced tools
A lightweight request/response interceptor to provide payload visibility for debugging and monitoring.
A lightweight request/response interceptor for Datadog RUM, providing enhanced payload visibility for debugging and monitoring.
npm install @kyletaylored/datadog-rum-interceptor
For direct use in the browser:
<script src="https://www.unpkg.com/@kyletaylored/datadog-rum-interceptor/dist/umd/index.js"></script>
const DRI = window.DD_RUM_INTERCEPTOR.init({ debug: true });
window.DD_RUM.init({
applicationId: "YOUR_APP_ID",
clientToken: "YOUR_CLIENT_TOKEN",
beforeSend: (event, context) => {
if (
event.type === "resource" &&
["xhr", "fetch"].includes(event.resource.type)
) {
const payload = DRI.getPayload({ event, context });
if (payload) {
event.context.payload = payload;
}
}
return true;
},
});
import datadogRumInterceptor from "@kyletaylored/datadog-rum-interceptor";
import { datadogRum } from '@datadog/browser-rum'
const DRI = datadogRumInterceptor.init({ debug: true });
datadogRum.init({
applicationId: '<DATADOG_APPLICATION_ID>',
clientToken: '<DATADOG_CLIENT_TOKEN>',
...
beforeSend: (event, context) => {
if (event.type === 'resource' && ['xhr', 'fetch'].includes(event.resource.type)) {
const payload = DRI.getPayload({ event, context });
if (payload) {
event.context.payload = payload;
}
}
return true;
},
})
graph TD;
A[Intercept HTTP Requests] -->|Fetch & XHR| B[Listen using @mswjs/interceptors];
B --> C{Trace ID Exists?};
C -->|Yes| D[Use Trace ID for tracking];
C -->|No| E[Generate fingerprint from resource attributes];
D --> F[Store Request Data Temporarily];
E --> F;
F -->|Store using requestId| G[Wait for response];
G -->|Response received| H[Retrieve request-response pair];
G -->|No response within 5s| I[Evict unmatched requests];
H --> J[Call getPayload in beforeSend];
J --> K[Attach payload to context or log];
style A fill:#f9f,stroke:#333,stroke-width:2px,color:#000;
style J fill:#ff9,stroke:#333,stroke-width:2px,color:#000;
style K fill:#9f9,stroke:#333,stroke-width:2px,color:#000;
@mswjs/interceptors to listen for Fetch & XHR requests.requestId until the response is received.beforeSend
getPayload({ event, context }) method automatically finds and attaches the payload.init(config: object)Initializes the interceptor.
const DRI = window.DD_RUM_INTERCEPTOR.init({ debug: true });
| Option | Type | Default | Description |
|---|---|---|---|
debug | bool | false | Enable logging for debugging |
getPayload({ event, context }): object | nullRetrieves the request/response payload for a given Datadog RUM event.
const data = DRI.getPayload({ event, context });
console.log(data);
| Parameter | Type | Description |
|---|---|---|
event | object | The Datadog RUM event object. |
context | object | The Datadog RUM context object. |
| Returns | object | null | The extracted payload data or null if not found. |
stop()Stops the interceptor and cleans up resources.
DRI.stop();
beforeSend is correctly configured.x-datadog-trace-id).This software is provided "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors, contributors, or their employers be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
By using this software, you acknowledge and agree that you assume all risks and liabilities associated with its use, and you waive any and all claims against the authors, contributors, and their employers.
FAQs
A lightweight request/response interceptor to provide payload visibility for debugging and monitoring.
We found that @kyletaylored/datadog-rum-interceptor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.