@reproapp/node-sdk 0.0.1 → 0.0.2
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/tracing.md +158 -0
- package/package.json +2 -13
- package/src/index.ts +2851 -0
- package/src/integrations/sendgrid.ts +184 -0
- package/tracer/cjs-hook.js +281 -0
- package/tracer/dep-hook.js +142 -0
- package/tracer/esm-loader.mjs +46 -0
- package/tracer/index.js +68 -0
- package/tracer/register.js +194 -0
- package/tracer/runtime.js +963 -0
- package/tracer/server.js +65 -0
- package/tracer/wrap-plugin.js +608 -0
- package/tsconfig.json +12 -0
package/docs/tracing.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Repro Tracing Configuration
|
|
2
|
+
|
|
3
|
+
Use `initReproTracing` to start the tracer and control which instrumented calls
|
|
4
|
+
are persisted. The helper exposes two optional knobs:
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
initReproTracing({
|
|
8
|
+
disableFunctionTraces: [
|
|
9
|
+
// Drop all constructor calls coming from mongoose models
|
|
10
|
+
{ library: 'mongoose', functionType: 'constructor' },
|
|
11
|
+
|
|
12
|
+
// Ignore a specific helper by name
|
|
13
|
+
{ fn: 'formatSensitiveData' },
|
|
14
|
+
|
|
15
|
+
// Skip noisy enter logs from a third-party file using a regular expression
|
|
16
|
+
{ file: /node_modules\/some-logger\/.*\.js$/ },
|
|
17
|
+
|
|
18
|
+
// Provide a custom predicate for advanced logic
|
|
19
|
+
(event) => event.fn?.startsWith('debug') ?? false,
|
|
20
|
+
],
|
|
21
|
+
disableFunctionTypes: ['constructor'],
|
|
22
|
+
logFunctionCalls: false,
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## `disableFunctionTypes`
|
|
27
|
+
|
|
28
|
+
Shorthand for suppressing entire categories of functions such as constructors
|
|
29
|
+
or getters. Provide a string, regular expression, or array of them and every
|
|
30
|
+
matching trace event will be ignored, regardless of library or filename.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { setDisabledFunctionTypes } from 'repro-nest';
|
|
34
|
+
|
|
35
|
+
setDisabledFunctionTypes(['constructor']);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Pass `null` or an empty array to reset the filter. This is useful when you want
|
|
39
|
+
to silence noisy dependency-injection constructors globally while still
|
|
40
|
+
allowing more targeted rules to run.
|
|
41
|
+
|
|
42
|
+
## `disableFunctionTraces`
|
|
43
|
+
|
|
44
|
+
Accepts an array of declarative rules or predicate functions. If any rule or
|
|
45
|
+
predicate returns `true` for an event, the tracer drops that event before it is
|
|
46
|
+
captured in the session payload.
|
|
47
|
+
|
|
48
|
+
### Declarative rule fields
|
|
49
|
+
|
|
50
|
+
| Property | Description |
|
|
51
|
+
| --------------- | ------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `fn`/`functionName` | Match against the instrumented function name (substring or RegExp). |
|
|
53
|
+
| `wrapper`/`wrapperClass`/`className`/`owner` | Match the wrapper/owner inferred from the function name (e.g. `"UserService"` in `"UserService.create"`). |
|
|
54
|
+
| `file` | Match the filename reported by the trace event (callsite when available; may fall back to the function definition file when the caller is not instrumented). |
|
|
55
|
+
| `line` | Match the line number reported by the trace event. |
|
|
56
|
+
| `lib`/`library` | Match the npm package inferred from the file path (e.g. `"mongoose"`). |
|
|
57
|
+
| `type`/`functionType` | Match the detected function kind (e.g. `"constructor"`, `"method"`, `"arrow"`). |
|
|
58
|
+
| `event`/`eventType` | Match the trace phase (`"enter"` or `"exit"`) to suppress only specific edges of a call. |
|
|
59
|
+
|
|
60
|
+
Each field accepts a string, regular expression, or array of them. Empty values
|
|
61
|
+
are ignored, so you can combine fields to scope rules as narrowly as needed.
|
|
62
|
+
|
|
63
|
+
### Predicate rules
|
|
64
|
+
|
|
65
|
+
Provide a function that receives the raw trace event and returns `true` when it
|
|
66
|
+
should be discarded. Use this form for complex, stateful, or cross-field logic.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { setDisabledFunctionTraces } from 'repro-nest';
|
|
70
|
+
|
|
71
|
+
setDisabledFunctionTraces([
|
|
72
|
+
(event) => event.library === 'mongoose' && event.functionType === 'constructor',
|
|
73
|
+
]);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Pass `null` or an empty array to `initReproTracing` or `setDisabledFunctionTraces`
|
|
77
|
+
to remove previously configured rules.
|
|
78
|
+
|
|
79
|
+
## Payload masking (`reproMiddleware`)
|
|
80
|
+
|
|
81
|
+
`reproMiddleware` can mask request/response payloads, request headers, and traced
|
|
82
|
+
function inputs/outputs before they are persisted.
|
|
83
|
+
|
|
84
|
+
### Targets
|
|
85
|
+
|
|
86
|
+
- `request.headers`
|
|
87
|
+
- `request.body`
|
|
88
|
+
- `request.params`
|
|
89
|
+
- `request.query`
|
|
90
|
+
- `response.body`
|
|
91
|
+
- `trace.args`
|
|
92
|
+
- `trace.returnValue`
|
|
93
|
+
- `trace.error`
|
|
94
|
+
|
|
95
|
+
### Rules
|
|
96
|
+
|
|
97
|
+
- `when.method` / `when.path` / `when.key` scope rules by endpoint (`key` is `"METHOD /path"` without query string).
|
|
98
|
+
- For function-specific rules, `when` supports the same fields as `disableFunctionTraces` (`fn`, `wrapperClass`, `file`, `line`, etc). This is useful when multiple functions share the same name.
|
|
99
|
+
- `paths` uses dot/bracket syntax and supports `*`, `[0]`, `[*]` (example: `"items[*].token"` or `"0.password"` for trace args arrays).
|
|
100
|
+
- `keys` masks matching key names anywhere in the payload (string/RegExp/array).
|
|
101
|
+
- `replacement` overrides the default replacement value (defaults to `"[REDACTED]"`).
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { reproMiddleware } from 'repro-nest';
|
|
105
|
+
|
|
106
|
+
app.use(reproMiddleware({
|
|
107
|
+
appId,
|
|
108
|
+
appName,
|
|
109
|
+
appSecret,
|
|
110
|
+
masking: {
|
|
111
|
+
rules: [
|
|
112
|
+
{
|
|
113
|
+
when: { key: 'POST /api/auth/login' },
|
|
114
|
+
target: 'request.body',
|
|
115
|
+
paths: ['password'],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
when: { wrapperClass: 'AuthService', functionName: 'login', file: '/app/src/auth/auth.service.ts' },
|
|
119
|
+
target: ['trace.args', 'trace.returnValue', 'trace.error'],
|
|
120
|
+
keys: [/token/i],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
target: 'request.headers',
|
|
124
|
+
keys: [/authorization/i, /cookie/i],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
}));
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Header capture/masking (`captureHeaders`)
|
|
132
|
+
|
|
133
|
+
Headers are captured by default with sensitive values masked. Configure `captureHeaders`
|
|
134
|
+
to change the behavior:
|
|
135
|
+
|
|
136
|
+
- `captureHeaders: false` disables header capture entirely.
|
|
137
|
+
- `captureHeaders: true` (or omitted) captures headers and masks sensitive ones.
|
|
138
|
+
- `captureHeaders.allowSensitiveHeaders: true` keeps default sensitive headers unmasked (use with care).
|
|
139
|
+
- `captureHeaders.maskHeaders` adds additional header names to mask.
|
|
140
|
+
- `captureHeaders.unmaskHeaders` keeps specific header names unmasked (overrides defaults and `maskHeaders`).
|
|
141
|
+
- `captureHeaders.dropHeaders` / `captureHeaders.keepHeaders` are legacy aliases for `maskHeaders` / `unmaskHeaders`.
|
|
142
|
+
|
|
143
|
+
## `logFunctionCalls`
|
|
144
|
+
|
|
145
|
+
Set to `true` to enable verbose console logging of function entry/exit events at
|
|
146
|
+
runtime, or to `false` to silence them. The value is forwarded to
|
|
147
|
+
`setReproTraceLogsEnabled`, so you can also toggle logging later in the process:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { enableReproTraceLogs, disableReproTraceLogs } from 'repro-nest';
|
|
151
|
+
|
|
152
|
+
enableReproTraceLogs();
|
|
153
|
+
// ...
|
|
154
|
+
disableReproTraceLogs();
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
These helpers are safe to call even if the tracer failed to initialize; they
|
|
158
|
+
simply no-op when tracing is unavailable.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reproapp/node-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Repro Nest SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,17 +8,6 @@
|
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=18"
|
|
10
10
|
},
|
|
11
|
-
"files": [
|
|
12
|
-
"dist",
|
|
13
|
-
"README.md",
|
|
14
|
-
"LICENSE"
|
|
15
|
-
],
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"require": "./dist/index.js",
|
|
19
|
-
"types": "./dist/index.d.ts"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
11
|
"scripts": {
|
|
23
12
|
"build": "tsc -p tsconfig.json",
|
|
24
13
|
"prepublishOnly": "npm run build",
|
|
@@ -55,4 +44,4 @@
|
|
|
55
44
|
"shimmer": "^1.2.1",
|
|
56
45
|
"testcontainers": "^11.8.1"
|
|
57
46
|
}
|
|
58
|
-
}
|
|
47
|
+
}
|