@decocms/blocks 8.20.2 → 8.22.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/dist/v8/analytics/client.d.ts +3 -1
- package/dist/v8/analytics/client.d.ts.map +1 -1
- package/dist/v8/analytics/client.js +12 -3
- package/dist/v8/analytics/client.js.map +1 -1
- package/dist/v8/builtins/experiments.d.ts +7 -2
- package/dist/v8/builtins/experiments.d.ts.map +1 -1
- package/dist/v8/builtins/experiments.js +22 -5
- package/dist/v8/builtins/experiments.js.map +1 -1
- package/dist/v8/cli/check/index.d.ts.map +1 -1
- package/dist/v8/cli/check/index.js +16 -0
- package/dist/v8/cli/check/index.js.map +1 -1
- package/dist/v8/cli/schema/builtinSchemas.js +1 -1
- package/dist/v8/cli/schema/builtinSchemas.js.map +1 -1
- package/dist/v8/errorReporting.d.ts +23 -0
- package/dist/v8/errorReporting.d.ts.map +1 -0
- package/dist/v8/errorReporting.js +140 -0
- package/dist/v8/errorReporting.js.map +1 -0
- package/dist/v8/experiments.d.ts +14 -3
- package/dist/v8/experiments.d.ts.map +1 -1
- package/dist/v8/experiments.js +11 -3
- package/dist/v8/experiments.js.map +1 -1
- package/dist/v8/nested.d.ts +23 -0
- package/dist/v8/nested.d.ts.map +1 -0
- package/dist/v8/nested.js +40 -0
- package/dist/v8/nested.js.map +1 -0
- package/dist/v8/telemetry.d.ts +6 -1
- package/dist/v8/telemetry.d.ts.map +1 -1
- package/dist/v8/telemetry.js +27 -18
- package/dist/v8/telemetry.js.map +1 -1
- package/dist/v8/telemetryText.d.ts +3 -0
- package/dist/v8/telemetryText.d.ts.map +1 -0
- package/dist/v8/telemetryText.js +21 -0
- package/dist/v8/telemetryText.js.map +1 -0
- package/package.json +7 -2
- package/skills/deco-variants/SKILL.md +1 -1
- package/skills/deco-variants/references/experiments-and-campaigns.md +32 -3
- package/src/v8/analytics/client.ts +14 -3
- package/src/v8/builtins/experiments.ts +21 -5
- package/src/v8/cli/check/index.ts +21 -0
- package/src/v8/cli/schema/builtinSchemas.ts +1 -1
- package/src/v8/errorReporting.ts +155 -0
- package/src/v8/experiments.ts +16 -4
- package/src/v8/nested.ts +40 -0
- package/src/v8/telemetry.ts +111 -90
- package/src/v8/telemetryText.ts +22 -0
package/src/v8/telemetry.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import { hasBackgroundHook, later, runInBackground } from "./background.ts";
|
|
21
21
|
import { rate, type SampleRates, TELEMETRY_DEFAULTS } from "./builtins/data.ts";
|
|
22
22
|
import { isResolutionError } from "./errors.ts";
|
|
23
|
+
import { scrubText } from "./telemetryText.ts";
|
|
23
24
|
import type { CMSError, Telemetry, TelemetryConfig } from "./types.ts";
|
|
24
25
|
|
|
25
26
|
/** The hosted Deco CMS collector, for `createCMS({ token })`. */
|
|
@@ -140,6 +141,7 @@ export class TelemetryPipeline {
|
|
|
140
141
|
#spans: (SpanInput & { spanId: string })[] = [];
|
|
141
142
|
#windowStart = Date.now();
|
|
142
143
|
#scheduled = false;
|
|
144
|
+
#sending = new Set<Promise<void>>();
|
|
143
145
|
|
|
144
146
|
constructor(destination: Destination) {
|
|
145
147
|
this.#destination = destination;
|
|
@@ -171,6 +173,11 @@ export class TelemetryPipeline {
|
|
|
171
173
|
return this.#settings.enabled && this.#settings.metrics;
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
/** Whether an error recorded now can be kept, independently of metrics. */
|
|
177
|
+
logging(): boolean {
|
|
178
|
+
return this.#settings.enabled && this.#settings.errorSampleRate > 0;
|
|
179
|
+
}
|
|
180
|
+
|
|
174
181
|
histogram(name: string, attributes: Attributes, seconds: number): void {
|
|
175
182
|
if (!this.measuring()) return;
|
|
176
183
|
const key = `${name}\u0000${JSON.stringify(attributes)}`;
|
|
@@ -277,7 +284,10 @@ export class TelemetryPipeline {
|
|
|
277
284
|
}
|
|
278
285
|
|
|
279
286
|
/** Sends what's been collected since the last batch. Never throws. */
|
|
280
|
-
async flush(): Promise<void> {
|
|
287
|
+
async flush(options: { signal?: AbortSignal; waitForPending?: boolean } = {}): Promise<void> {
|
|
288
|
+
// Explicit serverless drains also wait for batches already detached by a
|
|
289
|
+
// background flush. Ordinary scheduled batches remain independent.
|
|
290
|
+
const pending = options.waitForPending ? [...this.#sending] : [];
|
|
281
291
|
const now = Date.now();
|
|
282
292
|
const start = this.#windowStart;
|
|
283
293
|
this.#windowStart = now;
|
|
@@ -295,90 +305,109 @@ export class TelemetryPipeline {
|
|
|
295
305
|
const byName = new Map<string, Histogram[]>();
|
|
296
306
|
for (const h of histograms) byName.set(h.name, [...(byName.get(h.name) ?? []), h]);
|
|
297
307
|
sends.push(
|
|
298
|
-
this.#send(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
308
|
+
this.#send(
|
|
309
|
+
"metrics",
|
|
310
|
+
{
|
|
311
|
+
resourceMetrics: [
|
|
312
|
+
{
|
|
313
|
+
resource,
|
|
314
|
+
scopeMetrics: [
|
|
315
|
+
{
|
|
316
|
+
scope,
|
|
317
|
+
metrics: [...byName].map(([name, points]) => ({
|
|
318
|
+
name,
|
|
319
|
+
unit: "s",
|
|
320
|
+
histogram: {
|
|
321
|
+
aggregationTemporality: 1, // DELTA
|
|
322
|
+
dataPoints: points.map((h) => ({
|
|
323
|
+
attributes: encode(h.attributes),
|
|
324
|
+
startTimeUnixNano: nanos(start),
|
|
325
|
+
timeUnixNano: nanos(now),
|
|
326
|
+
count: String(h.count),
|
|
327
|
+
sum: h.sum,
|
|
328
|
+
min: h.min,
|
|
329
|
+
max: h.max,
|
|
330
|
+
bucketCounts: h.buckets.map(String),
|
|
331
|
+
explicitBounds: BOUNDS,
|
|
332
|
+
})),
|
|
333
|
+
},
|
|
334
|
+
})),
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
},
|
|
340
|
+
options.signal,
|
|
341
|
+
),
|
|
328
342
|
);
|
|
329
343
|
}
|
|
330
344
|
if (logs.length > 0) {
|
|
331
345
|
sends.push(
|
|
332
|
-
this.#send(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
346
|
+
this.#send(
|
|
347
|
+
"logs",
|
|
348
|
+
{
|
|
349
|
+
resourceLogs: [
|
|
350
|
+
{
|
|
351
|
+
resource,
|
|
352
|
+
scopeLogs: [
|
|
353
|
+
{
|
|
354
|
+
scope,
|
|
355
|
+
logRecords: logs.map((log) => ({
|
|
356
|
+
timeUnixNano: nanos(log.time),
|
|
357
|
+
severityNumber: log.severity === "ERROR" ? 17 : 13,
|
|
358
|
+
severityText: log.severity,
|
|
359
|
+
body: { stringValue: scrubText(log.message) },
|
|
360
|
+
attributes: encode(log.attributes),
|
|
361
|
+
})),
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
options.signal,
|
|
368
|
+
),
|
|
351
369
|
);
|
|
352
370
|
}
|
|
353
371
|
if (spans.length > 0) {
|
|
354
372
|
const kinds = { internal: 1, server: 2, client: 3 };
|
|
355
373
|
sends.push(
|
|
356
|
-
this.#send(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
374
|
+
this.#send(
|
|
375
|
+
"traces",
|
|
376
|
+
{
|
|
377
|
+
resourceSpans: [
|
|
378
|
+
{
|
|
379
|
+
resource,
|
|
380
|
+
scopeSpans: [
|
|
381
|
+
{
|
|
382
|
+
scope,
|
|
383
|
+
spans: spans.map((span) => ({
|
|
384
|
+
traceId: span.traceId,
|
|
385
|
+
spanId: span.spanId,
|
|
386
|
+
...(span.parentSpanId ? { parentSpanId: span.parentSpanId } : {}),
|
|
387
|
+
name: span.name,
|
|
388
|
+
kind: kinds[span.kind],
|
|
389
|
+
startTimeUnixNano: nanos(span.start),
|
|
390
|
+
endTimeUnixNano: nanos(span.end),
|
|
391
|
+
attributes: encode(span.attributes),
|
|
392
|
+
status: { code: span.error ? 2 : 0 },
|
|
393
|
+
})),
|
|
394
|
+
},
|
|
395
|
+
],
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
},
|
|
399
|
+
options.signal,
|
|
400
|
+
),
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
for (const send of sends) {
|
|
404
|
+
this.#sending.add(send);
|
|
405
|
+
void send.then(
|
|
406
|
+
() => this.#sending.delete(send),
|
|
407
|
+
() => this.#sending.delete(send),
|
|
379
408
|
);
|
|
380
409
|
}
|
|
381
|
-
await Promise.all(sends);
|
|
410
|
+
await Promise.all([...pending, ...sends]);
|
|
382
411
|
}
|
|
383
412
|
|
|
384
413
|
#schedule(): void {
|
|
@@ -416,7 +445,7 @@ export class TelemetryPipeline {
|
|
|
416
445
|
};
|
|
417
446
|
}
|
|
418
447
|
|
|
419
|
-
async #send(signal: Signal, payload: unknown): Promise<void> {
|
|
448
|
+
async #send(signal: Signal, payload: unknown, abortSignal?: AbortSignal): Promise<void> {
|
|
420
449
|
const url = `${this.#destination.endpoint.replace(/\/+$/, "")}/v1/${signal}`;
|
|
421
450
|
const { body, gzipped } = await gzip(JSON.stringify(payload));
|
|
422
451
|
const headers: Record<string, string> = {
|
|
@@ -425,9 +454,15 @@ export class TelemetryPipeline {
|
|
|
425
454
|
};
|
|
426
455
|
if (gzipped) headers["content-encoding"] = "gzip";
|
|
427
456
|
for (let attempt = 0; ; attempt++) {
|
|
457
|
+
if (abortSignal?.aborted) return;
|
|
428
458
|
let response: Response;
|
|
429
459
|
try {
|
|
430
|
-
response = await fetch(url, {
|
|
460
|
+
response = await fetch(url, {
|
|
461
|
+
method: "POST",
|
|
462
|
+
headers,
|
|
463
|
+
body,
|
|
464
|
+
...(abortSignal === undefined ? {} : { signal: abortSignal }),
|
|
465
|
+
});
|
|
431
466
|
} catch {
|
|
432
467
|
return; // a collector that's down loses this batch
|
|
433
468
|
}
|
|
@@ -455,20 +490,6 @@ export function setCurrentTelemetry(pipeline: TelemetryPipeline | undefined): vo
|
|
|
455
490
|
// Helpers
|
|
456
491
|
// ---------------------------------------------------------------------------
|
|
457
492
|
|
|
458
|
-
const QUERY = /(https?:\/\/[^\s?#"'<>]+)\?[^\s#"'<>]*/gi;
|
|
459
|
-
const CREDENTIAL = /\b(Bearer|Basic)\s+[\w~+/.=-]+/gi;
|
|
460
|
-
const SENSITIVE =
|
|
461
|
-
/\b(authorization|cookie|set-cookie|x-api-key|api[-_]?key|app[-_]?key|app[-_]?token|token|secret|password)(["']?\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;&]+)/gi;
|
|
462
|
-
|
|
463
|
-
/** Removes query strings, credentials and cookie/token values from text before it's sent. */
|
|
464
|
-
function scrubText(text: string): string {
|
|
465
|
-
return text
|
|
466
|
-
.replace(QUERY, "$1?[redacted]")
|
|
467
|
-
.replace(CREDENTIAL, "$1 [redacted]")
|
|
468
|
-
.replace(SENSITIVE, "$1$2[redacted]")
|
|
469
|
-
.slice(0, 1_000);
|
|
470
|
-
}
|
|
471
|
-
|
|
472
493
|
export function newTraceId(): string {
|
|
473
494
|
return randomHex(16);
|
|
474
495
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Scrubs server exception text before final OTLP encoding; no runtime state. */
|
|
2
|
+
const URL_CREDENTIALS = /((?:[a-z][a-z0-9+.-]*:)?\/\/)[^\s/?#"'<>]*@/gi;
|
|
3
|
+
// Relative URLs inside exceptions (`/cart?...`, `assets/chunk.js?...`) have
|
|
4
|
+
// the same privacy boundary as absolute URLs.
|
|
5
|
+
const URL_DETAILS = /([^\s?#"'<>()]+)([?#])([^\s"'<>()]*)/g;
|
|
6
|
+
const CREDENTIAL = /\b(Bearer|Basic)\s+[\w~+/.=-]+/gi;
|
|
7
|
+
const SENSITIVE =
|
|
8
|
+
/\b(authorization|cookie|set-cookie|x-api-key|api[-_]?key|app[-_]?key|app[-_]?token|token|secret|password)(["']?\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;&]+)/gi;
|
|
9
|
+
|
|
10
|
+
/** Removes URL details and credential values before exception text leaves its runtime. */
|
|
11
|
+
export function scrubText(text: string): string {
|
|
12
|
+
return text
|
|
13
|
+
.replace(URL_CREDENTIALS, "$1")
|
|
14
|
+
.replace(URL_DETAILS, (_url, path: string, separator: string, details: string) => {
|
|
15
|
+
// JavaScript stack frames can append :line:column after a URL's query/hash.
|
|
16
|
+
const position = /(:\d+:\d+)$/.exec(details)?.[1] ?? "";
|
|
17
|
+
return `${path}${separator}[redacted]${position}`;
|
|
18
|
+
})
|
|
19
|
+
.replace(CREDENTIAL, "$1 [redacted]")
|
|
20
|
+
.replace(SENSITIVE, "$1$2[redacted]")
|
|
21
|
+
.slice(0, 1_000);
|
|
22
|
+
}
|