@deploze/next 0.0.0-stage → 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 +70 -2
- package/dist/chunk-2ZXSSRDV.js +305 -0
- package/dist/collector-BHP98_1d.d.cts +39 -0
- package/dist/collector-BHP98_1d.d.ts +39 -0
- package/dist/core/index.cjs +347 -0
- package/dist/core/index.d.cts +127 -0
- package/dist/core/index.d.ts +127 -0
- package/dist/core/index.js +16 -0
- package/dist/index.cjs +521 -0
- package/dist/index.d.cts +134 -0
- package/dist/index.d.ts +134 -0
- package/dist/index.js +182 -0
- package/package.json +72 -4
- package/postinstall.cjs +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Deploze
|
|
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
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @deploze/next
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Deploze](https://deploze.com) watches your deploys and tells you, within minutes, whether they're healthy — by combining AI code-diff analysis with real runtime data and alerting you in Slack/email before your users notice a problem.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i @deploze/next
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Set your ingest key ([generate one](https://app.deploze.com) in your repository's Settings → Data source):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# .env
|
|
15
|
+
DEPLOZE_INGEST_KEY=dpi_...
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Register the Deploze span processor in `instrumentation.ts` (project root or `src/`):
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { registerDeploze } from '@deploze/next';
|
|
22
|
+
|
|
23
|
+
export function register() {
|
|
24
|
+
return registerDeploze();
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
That's it. Next.js emits a span for every request, and Deploze records request count, status, latency, and error samples for every route automatically — no per-route code.
|
|
29
|
+
|
|
30
|
+
> **Local dev is skipped by default.** If `NODE_ENV=development` (e.g. `next dev`), the collector is a no-op even with an ingest key set — this avoids local traffic getting attributed to whatever deploy is currently monitored in production. Set `DEPLOZE_ENABLE_DEV=1` to force it on for local testing.
|
|
31
|
+
|
|
32
|
+
## Fallbacks (when you can't run OpenTelemetry)
|
|
33
|
+
|
|
34
|
+
**Error-only** — captures failures but not request volume or latency:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
export { register, onRequestError } from '@deploze/next';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Manual capture** — wrap route handlers, or record from middleware / a custom server:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { withDeploze } from '@deploze/next';
|
|
44
|
+
export const GET = withDeploze(async (req) => { /* your handler */ });
|
|
45
|
+
|
|
46
|
+
// or, in middleware / custom servers:
|
|
47
|
+
import { trackRequest } from '@deploze/next';
|
|
48
|
+
trackRequest({ path: '/api/users/42', status: 200, durationMs: 87 });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## What the SDK sends
|
|
52
|
+
|
|
53
|
+
Aggregates only, once per flush:
|
|
54
|
+
|
|
55
|
+
- Per route and minute: request count, 5xx and 4xx counts, average and p95 latency.
|
|
56
|
+
- The route: Next's route template where available (`/blog/:slug`), otherwise the request path with the query string removed and ID-like segments (UUIDs, long hex, numbers) replaced by `:id`.
|
|
57
|
+
- For 5xx responses: the error message, truncated to 1,000 characters. Keep personal data out of error messages — they are sent as written.
|
|
58
|
+
|
|
59
|
+
Not sent: query strings, headers, cookies, bodies, IP addresses, or anything identifying a visitor.
|
|
60
|
+
|
|
61
|
+
## Health checks
|
|
62
|
+
|
|
63
|
+
Separately from the SDK, Deploze requests the pages changed in each deploy to confirm they load. Those requests use the user agent `Deploze-SyntheticMonitor/1.0`; the SDK recognises it and leaves them out of your metrics. If you run a firewall or bot protection, allow that user agent.
|
|
64
|
+
|
|
65
|
+
Dynamic routes (`/blog/[slug]`) are checked through a URL from your site's `/sitemap.xml` — never through paths the SDK observed. See [Get your pages covered by health checks](https://app.deploze.com/docs/guides#health-checks).
|
|
66
|
+
|
|
67
|
+
## Links
|
|
68
|
+
|
|
69
|
+
- [Deploze docs](https://app.deploze.com/docs/integrations)
|
|
70
|
+
- [Source](https://github.com/deploze/next) · [Ingest protocol](https://github.com/deploze/next/blob/main/PROTOCOL.md)
|
|
71
|
+
- [Issues / support](mailto:support@deploze.com)
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// src/core/normalize.ts
|
|
2
|
+
function normalizePathPattern(path) {
|
|
3
|
+
if (!path) return "/unknown";
|
|
4
|
+
return path.split("?")[0].split("#")[0].replace(
|
|
5
|
+
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
|
|
6
|
+
":id"
|
|
7
|
+
).replace(/\/[0-9a-f]{16,}\b/gi, "/:id").replace(/\/\d{2,}\b/g, "/:id").replace(/\/$/, "") || "/";
|
|
8
|
+
}
|
|
9
|
+
function normalizeErrorSignature(message) {
|
|
10
|
+
return message.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "{UUID}").replace(/\b[0-9a-f]{16,}\b/gi, "{ID}").replace(/\b\d{6,}\b/g, "{ID}").replace(/:\d+:\d+/g, ":{LINE}").replace(/\s+/g, " ").trim().slice(0, 200);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/core/protocol.ts
|
|
14
|
+
var SCHEMA_VERSION = 1;
|
|
15
|
+
|
|
16
|
+
// src/core/build-id.ts
|
|
17
|
+
function getEnv(name) {
|
|
18
|
+
try {
|
|
19
|
+
return globalThis.process?.env?.[name];
|
|
20
|
+
} catch {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function readGeneratedBuildId() {
|
|
25
|
+
if (process.env.NEXT_RUNTIME !== "edge") {
|
|
26
|
+
try {
|
|
27
|
+
const fs = await import("fs");
|
|
28
|
+
const path = await import("path");
|
|
29
|
+
const { fileURLToPath } = await import("url");
|
|
30
|
+
const dir = getModuleDir(path, fileURLToPath);
|
|
31
|
+
const candidates = [
|
|
32
|
+
path.join(dir, ".build-id.json"),
|
|
33
|
+
path.join(dir, "..", ".build-id.json"),
|
|
34
|
+
path.join(dir, "..", "..", ".build-id.json")
|
|
35
|
+
];
|
|
36
|
+
for (const candidate of candidates) {
|
|
37
|
+
try {
|
|
38
|
+
if (!fs.existsSync(candidate)) continue;
|
|
39
|
+
const raw = JSON.parse(fs.readFileSync(candidate, "utf8"));
|
|
40
|
+
return typeof raw?.sha === "string" && raw.sha ? raw.sha : null;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function getModuleDir(path, fileURLToPath) {
|
|
51
|
+
try {
|
|
52
|
+
return path.dirname(fileURLToPath(import.meta.url));
|
|
53
|
+
} catch {
|
|
54
|
+
const dir = globalThis.__dirname;
|
|
55
|
+
return typeof dir !== "undefined" ? dir : process.cwd();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function getBuildId() {
|
|
59
|
+
return getEnv("DEPLOZE_GIT_SHA") || getEnv("VERCEL_GIT_COMMIT_SHA") || await readGeneratedBuildId() || null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/core/transport.ts
|
|
63
|
+
var SDK_VERSION = "0.1.0";
|
|
64
|
+
function parseRemoteConfig(body) {
|
|
65
|
+
if (!body || typeof body !== "object") return void 0;
|
|
66
|
+
const raw = body.config;
|
|
67
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
68
|
+
const cfg = raw;
|
|
69
|
+
const config = {};
|
|
70
|
+
const flush = Number(cfg.flush_interval_ms);
|
|
71
|
+
if (Number.isFinite(flush) && flush >= 1e3 && flush <= 6e5) {
|
|
72
|
+
config.flush_interval_ms = Math.floor(flush);
|
|
73
|
+
}
|
|
74
|
+
const buckets = Number(cfg.max_buckets);
|
|
75
|
+
if (Number.isFinite(buckets) && buckets >= 1 && buckets <= 1e4) {
|
|
76
|
+
config.max_buckets = Math.floor(buckets);
|
|
77
|
+
}
|
|
78
|
+
const samples = Number(cfg.max_error_samples);
|
|
79
|
+
if (Number.isFinite(samples) && samples >= 1 && samples <= 1e3) {
|
|
80
|
+
config.max_error_samples = Math.floor(samples);
|
|
81
|
+
}
|
|
82
|
+
return Object.keys(config).length > 0 ? config : void 0;
|
|
83
|
+
}
|
|
84
|
+
async function send(payload, options) {
|
|
85
|
+
const { endpoint, apiKey, timeoutMs = 3e3 } = options;
|
|
86
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
87
|
+
if (typeof fetchImpl !== "function") return { ok: false };
|
|
88
|
+
try {
|
|
89
|
+
const controller = new AbortController();
|
|
90
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
91
|
+
const body = {
|
|
92
|
+
schema_version: payload.schema_version ?? SCHEMA_VERSION,
|
|
93
|
+
stats: payload.stats,
|
|
94
|
+
errors: payload.errors
|
|
95
|
+
};
|
|
96
|
+
const buildId = await getBuildId();
|
|
97
|
+
const headers = {
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
Authorization: `Bearer ${apiKey}`,
|
|
100
|
+
"User-Agent": `@deploze/next/${SDK_VERSION}`
|
|
101
|
+
};
|
|
102
|
+
if (buildId) headers["X-Deploze-Git-Sha"] = buildId;
|
|
103
|
+
const res = await fetchImpl(endpoint, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers,
|
|
106
|
+
body: JSON.stringify(body),
|
|
107
|
+
keepalive: true,
|
|
108
|
+
signal: controller.signal
|
|
109
|
+
});
|
|
110
|
+
clearTimeout(timer);
|
|
111
|
+
if (!res.ok) return { ok: false };
|
|
112
|
+
let config;
|
|
113
|
+
try {
|
|
114
|
+
const parsed = typeof res.json === "function" ? await res.json() : typeof res.text === "function" ? JSON.parse(await res.text()) : void 0;
|
|
115
|
+
config = parseRemoteConfig(parsed);
|
|
116
|
+
} catch {
|
|
117
|
+
}
|
|
118
|
+
return { ok: true, config };
|
|
119
|
+
} catch {
|
|
120
|
+
return { ok: false };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/core/collector.ts
|
|
125
|
+
var DEFAULT_MAX_BUCKETS = 200;
|
|
126
|
+
var DEFAULT_MAX_ERROR_SAMPLES = 10;
|
|
127
|
+
var RESERVOIR_SIZE = 200;
|
|
128
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 3e4;
|
|
129
|
+
var DEFAULT_ENDPOINT = "https://app.deploze.com/api/ingest";
|
|
130
|
+
function p95(values) {
|
|
131
|
+
if (values.length === 0) return void 0;
|
|
132
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
133
|
+
const idx = Math.min(sorted.length - 1, Math.ceil(sorted.length * 0.95) - 1);
|
|
134
|
+
return sorted[Math.max(0, idx)];
|
|
135
|
+
}
|
|
136
|
+
function createCollector(options = {}) {
|
|
137
|
+
const apiKey = options.apiKey ?? getEnv2("DEPLOZE_INGEST_KEY");
|
|
138
|
+
const endpoint = options.endpoint ?? getEnv2("DEPLOZE_INGEST_URL") ?? DEFAULT_ENDPOINT;
|
|
139
|
+
let flushIntervalMs = options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
|
|
140
|
+
let maxBuckets = DEFAULT_MAX_BUCKETS;
|
|
141
|
+
let maxErrorSamples = DEFAULT_MAX_ERROR_SAMPLES;
|
|
142
|
+
const now = options.now ?? Date.now;
|
|
143
|
+
const autoFlush = options.autoFlush !== false;
|
|
144
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
145
|
+
const errorSamples = /* @__PURE__ */ new Map();
|
|
146
|
+
let timer = null;
|
|
147
|
+
let flushing = false;
|
|
148
|
+
const isLocalDev = getEnv2("NODE_ENV") === "development" && getEnv2("DEPLOZE_ENABLE_DEV") !== "1";
|
|
149
|
+
const enabled = Boolean(apiKey) && !isLocalDev;
|
|
150
|
+
if (!enabled) {
|
|
151
|
+
return {
|
|
152
|
+
record() {
|
|
153
|
+
},
|
|
154
|
+
async flush() {
|
|
155
|
+
},
|
|
156
|
+
stop() {
|
|
157
|
+
},
|
|
158
|
+
pendingBucketCount: () => 0
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const transport = {
|
|
162
|
+
endpoint,
|
|
163
|
+
apiKey,
|
|
164
|
+
fetchImpl: options.fetchImpl
|
|
165
|
+
};
|
|
166
|
+
function startTimer(intervalMs) {
|
|
167
|
+
if (!autoFlush) return;
|
|
168
|
+
if (timer) {
|
|
169
|
+
clearInterval(timer);
|
|
170
|
+
timer = null;
|
|
171
|
+
}
|
|
172
|
+
timer = setInterval(() => {
|
|
173
|
+
void flush();
|
|
174
|
+
}, intervalMs);
|
|
175
|
+
if (typeof timer === "object" && "unref" in timer) {
|
|
176
|
+
timer.unref();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function applyConfig(config) {
|
|
180
|
+
if (!config) return;
|
|
181
|
+
if (typeof config.max_buckets === "number") {
|
|
182
|
+
maxBuckets = config.max_buckets;
|
|
183
|
+
}
|
|
184
|
+
if (typeof config.max_error_samples === "number") {
|
|
185
|
+
maxErrorSamples = config.max_error_samples;
|
|
186
|
+
}
|
|
187
|
+
if (typeof config.flush_interval_ms === "number" && config.flush_interval_ms !== flushIntervalMs) {
|
|
188
|
+
flushIntervalMs = config.flush_interval_ms;
|
|
189
|
+
startTimer(flushIntervalMs);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function record(input) {
|
|
193
|
+
try {
|
|
194
|
+
const status = Number(input.status);
|
|
195
|
+
if (!Number.isFinite(status)) return;
|
|
196
|
+
const path = normalizePathPattern(input.path ?? null);
|
|
197
|
+
const minute = new Date(Math.floor(now() / 6e4) * 6e4).toISOString();
|
|
198
|
+
const key = `${minute}|${path}`;
|
|
199
|
+
let bucket = buckets.get(key);
|
|
200
|
+
if (!bucket) {
|
|
201
|
+
if (buckets.size >= maxBuckets) return;
|
|
202
|
+
bucket = {
|
|
203
|
+
path,
|
|
204
|
+
minute,
|
|
205
|
+
count: 0,
|
|
206
|
+
e5xx: 0,
|
|
207
|
+
e4xx: 0,
|
|
208
|
+
latencySum: 0,
|
|
209
|
+
latencyCount: 0,
|
|
210
|
+
reservoir: [],
|
|
211
|
+
seen: 0
|
|
212
|
+
};
|
|
213
|
+
buckets.set(key, bucket);
|
|
214
|
+
}
|
|
215
|
+
bucket.count += 1;
|
|
216
|
+
if (status >= 500) bucket.e5xx += 1;
|
|
217
|
+
else if (status >= 400) bucket.e4xx += 1;
|
|
218
|
+
const duration = Number(input.durationMs);
|
|
219
|
+
if (Number.isFinite(duration) && duration >= 0) {
|
|
220
|
+
bucket.latencySum += duration;
|
|
221
|
+
bucket.latencyCount += 1;
|
|
222
|
+
bucket.seen += 1;
|
|
223
|
+
if (bucket.reservoir.length < RESERVOIR_SIZE) {
|
|
224
|
+
bucket.reservoir.push(duration);
|
|
225
|
+
} else {
|
|
226
|
+
const j = Math.floor(Math.random() * bucket.seen);
|
|
227
|
+
if (j < RESERVOIR_SIZE) bucket.reservoir[j] = duration;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (status >= 500 && input.errorMessage) {
|
|
231
|
+
const pattern = normalizeErrorSignature(input.errorMessage);
|
|
232
|
+
const existing = errorSamples.get(`${path}|${pattern}`);
|
|
233
|
+
if (existing) {
|
|
234
|
+
existing.count += 1;
|
|
235
|
+
} else if (errorSamples.size < maxErrorSamples) {
|
|
236
|
+
errorSamples.set(`${path}|${pattern}`, {
|
|
237
|
+
path,
|
|
238
|
+
pattern,
|
|
239
|
+
sample: input.errorMessage.slice(0, 1e3),
|
|
240
|
+
count: 1
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} catch {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function flush() {
|
|
248
|
+
if (flushing || buckets.size === 0 && errorSamples.size === 0) return;
|
|
249
|
+
flushing = true;
|
|
250
|
+
try {
|
|
251
|
+
const statRows = [...buckets.values()];
|
|
252
|
+
const errorRows = [...errorSamples.values()];
|
|
253
|
+
buckets.clear();
|
|
254
|
+
errorSamples.clear();
|
|
255
|
+
const payload = {
|
|
256
|
+
schema_version: SCHEMA_VERSION,
|
|
257
|
+
stats: statRows.map((b) => ({
|
|
258
|
+
path: b.path,
|
|
259
|
+
minute: b.minute,
|
|
260
|
+
total_requests: b.count,
|
|
261
|
+
error_count: b.e5xx,
|
|
262
|
+
client_error_count: b.e4xx,
|
|
263
|
+
avg_latency_ms: b.latencyCount > 0 ? Math.round(b.latencySum / b.latencyCount) : void 0,
|
|
264
|
+
p95_latency_ms: p95(b.reservoir)
|
|
265
|
+
})),
|
|
266
|
+
errors: errorRows.map((e) => ({
|
|
267
|
+
path: e.path,
|
|
268
|
+
error_pattern: e.pattern,
|
|
269
|
+
sample_message: e.sample,
|
|
270
|
+
count: e.count
|
|
271
|
+
}))
|
|
272
|
+
};
|
|
273
|
+
const result = await send(payload, transport);
|
|
274
|
+
if (result.ok) {
|
|
275
|
+
applyConfig(result.config);
|
|
276
|
+
}
|
|
277
|
+
} finally {
|
|
278
|
+
flushing = false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function stop() {
|
|
282
|
+
if (timer) {
|
|
283
|
+
clearInterval(timer);
|
|
284
|
+
timer = null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
startTimer(flushIntervalMs);
|
|
288
|
+
return { record, flush, stop, pendingBucketCount: () => buckets.size };
|
|
289
|
+
}
|
|
290
|
+
function getEnv2(name) {
|
|
291
|
+
try {
|
|
292
|
+
return globalThis.process?.env?.[name];
|
|
293
|
+
} catch {
|
|
294
|
+
return void 0;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export {
|
|
299
|
+
normalizePathPattern,
|
|
300
|
+
normalizeErrorSignature,
|
|
301
|
+
SCHEMA_VERSION,
|
|
302
|
+
getBuildId,
|
|
303
|
+
send,
|
|
304
|
+
createCollector
|
|
305
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory aggregating collector.
|
|
3
|
+
*
|
|
4
|
+
* Buckets requests by (minute, normalized path) and keeps counters plus a
|
|
5
|
+
* bounded latency reservoir per bucket. Payload size scales with the number
|
|
6
|
+
* of active routes per minute — never with traffic volume.
|
|
7
|
+
*
|
|
8
|
+
* Caps (mirror the server's ingest limits; overridable via remote config):
|
|
9
|
+
* - 200 distinct (minute, path) buckets per flush — cardinality guard
|
|
10
|
+
* - 10 deduplicated error samples per flush
|
|
11
|
+
* - 200 latency samples per bucket (reservoir sampling for p95)
|
|
12
|
+
*/
|
|
13
|
+
interface CollectorOptions {
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
flushIntervalMs?: number;
|
|
17
|
+
/** Disable the automatic interval (callers flush manually / via after()) */
|
|
18
|
+
autoFlush?: boolean;
|
|
19
|
+
/** Injectable for tests */
|
|
20
|
+
fetchImpl?: typeof fetch;
|
|
21
|
+
now?: () => number;
|
|
22
|
+
}
|
|
23
|
+
interface RecordInput {
|
|
24
|
+
path: string;
|
|
25
|
+
method?: string;
|
|
26
|
+
status: number;
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
errorMessage?: string;
|
|
29
|
+
}
|
|
30
|
+
interface Collector {
|
|
31
|
+
record(input: RecordInput): void;
|
|
32
|
+
flush(): Promise<void>;
|
|
33
|
+
stop(): void;
|
|
34
|
+
/** Test/debug introspection */
|
|
35
|
+
pendingBucketCount(): number;
|
|
36
|
+
}
|
|
37
|
+
declare function createCollector(options?: CollectorOptions): Collector;
|
|
38
|
+
|
|
39
|
+
export { type Collector as C, type RecordInput as R, type CollectorOptions as a, createCollector as c };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory aggregating collector.
|
|
3
|
+
*
|
|
4
|
+
* Buckets requests by (minute, normalized path) and keeps counters plus a
|
|
5
|
+
* bounded latency reservoir per bucket. Payload size scales with the number
|
|
6
|
+
* of active routes per minute — never with traffic volume.
|
|
7
|
+
*
|
|
8
|
+
* Caps (mirror the server's ingest limits; overridable via remote config):
|
|
9
|
+
* - 200 distinct (minute, path) buckets per flush — cardinality guard
|
|
10
|
+
* - 10 deduplicated error samples per flush
|
|
11
|
+
* - 200 latency samples per bucket (reservoir sampling for p95)
|
|
12
|
+
*/
|
|
13
|
+
interface CollectorOptions {
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
endpoint?: string;
|
|
16
|
+
flushIntervalMs?: number;
|
|
17
|
+
/** Disable the automatic interval (callers flush manually / via after()) */
|
|
18
|
+
autoFlush?: boolean;
|
|
19
|
+
/** Injectable for tests */
|
|
20
|
+
fetchImpl?: typeof fetch;
|
|
21
|
+
now?: () => number;
|
|
22
|
+
}
|
|
23
|
+
interface RecordInput {
|
|
24
|
+
path: string;
|
|
25
|
+
method?: string;
|
|
26
|
+
status: number;
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
errorMessage?: string;
|
|
29
|
+
}
|
|
30
|
+
interface Collector {
|
|
31
|
+
record(input: RecordInput): void;
|
|
32
|
+
flush(): Promise<void>;
|
|
33
|
+
stop(): void;
|
|
34
|
+
/** Test/debug introspection */
|
|
35
|
+
pendingBucketCount(): number;
|
|
36
|
+
}
|
|
37
|
+
declare function createCollector(options?: CollectorOptions): Collector;
|
|
38
|
+
|
|
39
|
+
export { type Collector as C, type RecordInput as R, type CollectorOptions as a, createCollector as c };
|