@laburen/delta-sdk 1.1.1 → 1.5.0-canary.10
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/CHANGELOG.md +84 -0
- package/README.md +32 -23
- package/dist/core/config.d.ts +12 -12
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +88 -88
- package/dist/core/config.js.map +1 -1
- package/dist/core/{constantes.d.ts → constants.d.ts} +3 -3
- package/dist/core/constants.d.ts.map +1 -0
- package/dist/core/{constantes.js → constants.js} +3 -3
- package/dist/core/constants.js.map +1 -0
- package/dist/core/{contadores.d.ts → counters.d.ts} +12 -11
- package/dist/core/counters.d.ts.map +1 -0
- package/dist/core/counters.js +53 -0
- package/dist/core/counters.js.map +1 -0
- package/dist/core/{sobre.d.ts → envelope.d.ts} +17 -17
- package/dist/core/envelope.d.ts.map +1 -0
- package/dist/core/envelope.js +198 -0
- package/dist/core/envelope.js.map +1 -0
- package/dist/core/scrubbing.d.ts +4 -4
- package/dist/core/scrubbing.d.ts.map +1 -1
- package/dist/core/scrubbing.js +38 -38
- package/dist/core/scrubbing.js.map +1 -1
- package/dist/core/{sesion.d.ts → session.d.ts} +2 -2
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/{sesion.js → session.js} +2 -2
- package/dist/core/session.js.map +1 -0
- package/dist/core/{transporte.d.ts → transport.d.ts} +9 -9
- package/dist/core/transport.d.ts.map +1 -0
- package/dist/core/{transporte.js → transport.js} +15 -15
- package/dist/core/transport.js.map +1 -0
- package/dist/core/{tipos.d.ts → types.d.ts} +4 -4
- package/dist/core/{tipos.d.ts.map → types.d.ts.map} +1 -1
- package/dist/core/{tipos.js → types.js} +1 -1
- package/dist/core/{tipos.js.map → types.js.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/platform/client.d.ts +8 -0
- package/dist/platform/client.d.ts.map +1 -0
- package/dist/platform/client.js +30 -0
- package/dist/platform/client.js.map +1 -0
- package/dist/platform/core/errors.d.ts +150 -0
- package/dist/platform/core/errors.d.ts.map +1 -0
- package/dist/platform/core/errors.js +265 -0
- package/dist/platform/core/errors.js.map +1 -0
- package/dist/platform/core/oauth.d.ts +37 -0
- package/dist/platform/core/oauth.d.ts.map +1 -0
- package/dist/platform/core/oauth.js +144 -0
- package/dist/platform/core/oauth.js.map +1 -0
- package/dist/platform/core/pagination.d.ts +30 -0
- package/dist/platform/core/pagination.d.ts.map +1 -0
- package/dist/platform/core/pagination.js +44 -0
- package/dist/platform/core/pagination.js.map +1 -0
- package/dist/platform/core/request.d.ts +6 -0
- package/dist/platform/core/request.d.ts.map +1 -0
- package/dist/platform/core/request.js +24 -0
- package/dist/platform/core/request.js.map +1 -0
- package/dist/platform/core/send.d.ts +36 -0
- package/dist/platform/core/send.d.ts.map +1 -0
- package/dist/platform/core/send.js +171 -0
- package/dist/platform/core/send.js.map +1 -0
- package/dist/platform/core/sse.d.ts +8 -0
- package/dist/platform/core/sse.d.ts.map +1 -0
- package/dist/platform/core/sse.js +72 -0
- package/dist/platform/core/sse.js.map +1 -0
- package/dist/platform/core/stream.d.ts +21 -0
- package/dist/platform/core/stream.d.ts.map +1 -0
- package/dist/platform/core/stream.js +268 -0
- package/dist/platform/core/stream.js.map +1 -0
- package/dist/platform/generated/resources.d.ts +120 -0
- package/dist/platform/generated/resources.d.ts.map +1 -0
- package/dist/platform/generated/resources.js +65 -0
- package/dist/platform/generated/resources.js.map +1 -0
- package/dist/platform/generated/schemas.d.ts +78 -0
- package/dist/platform/generated/schemas.d.ts.map +1 -0
- package/dist/platform/generated/schemas.js +2 -0
- package/dist/platform/generated/schemas.js.map +1 -0
- package/dist/platform/generated/types.d.ts +5167 -0
- package/dist/platform/generated/types.d.ts.map +1 -0
- package/dist/platform/generated/types.js +6 -0
- package/dist/platform/generated/types.js.map +1 -0
- package/dist/platform/index.d.ts +9 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +7 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/telemetry/{captura.d.ts → capture.d.ts} +3 -3
- package/dist/telemetry/capture.d.ts.map +1 -0
- package/dist/telemetry/{captura.js → capture.js} +54 -54
- package/dist/telemetry/capture.js.map +1 -0
- package/dist/telemetry/index.d.ts +2 -2
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/{tipos.d.ts → types.d.ts} +2 -2
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +2 -0
- package/dist/telemetry/types.js.map +1 -0
- package/dist/telemetry/with-telemetry.d.ts +9 -9
- package/dist/telemetry/with-telemetry.d.ts.map +1 -1
- package/dist/telemetry/with-telemetry.js +36 -33
- package/dist/telemetry/with-telemetry.js.map +1 -1
- package/dist/telemetry/with-tool.d.ts +2 -2
- package/dist/telemetry/with-tool.d.ts.map +1 -1
- package/dist/telemetry/with-tool.js +3 -3
- package/dist/telemetry/with-tool.js.map +1 -1
- package/docs/empezar.md +35 -0
- package/docs/platform/guide.md +554 -0
- package/docs/superficies.md +1 -1
- package/docs/{telemetria.md → telemetry/guia.md} +52 -5
- package/docs/{que-se-manda.md → telemetry/que-se-manda.md} +14 -3
- package/docs/telemetry/troubleshooting.md +48 -0
- package/docs/troubleshooting.md +13 -46
- package/package.json +15 -5
- package/src/core/config.ts +81 -83
- package/src/core/{constantes.ts → constants.ts} +2 -2
- package/src/core/counters.ts +72 -0
- package/src/core/envelope.ts +234 -0
- package/src/core/scrubbing.ts +41 -41
- package/src/core/{sesion.ts → session.ts} +1 -1
- package/src/core/{transporte.ts → transport.ts} +20 -20
- package/src/core/{tipos.ts → types.ts} +3 -3
- package/src/index.ts +1 -1
- package/src/platform/client.ts +32 -0
- package/src/platform/core/errors.ts +348 -0
- package/src/platform/core/oauth.ts +201 -0
- package/src/platform/core/pagination.ts +67 -0
- package/src/platform/core/request.ts +27 -0
- package/src/platform/core/send.ts +212 -0
- package/src/platform/core/sse.ts +68 -0
- package/src/platform/core/stream.ts +314 -0
- package/src/platform/generated/resources.ts +192 -0
- package/src/platform/generated/schemas.ts +79 -0
- package/src/platform/generated/types.ts +5167 -0
- package/src/platform/index.ts +45 -0
- package/src/telemetry/{captura.ts → capture.ts} +57 -57
- package/src/telemetry/index.ts +2 -2
- package/src/telemetry/{tipos.ts → types.ts} +1 -1
- package/src/telemetry/with-telemetry.ts +56 -50
- package/src/telemetry/with-tool.ts +5 -5
- package/dist/core/constantes.d.ts.map +0 -1
- package/dist/core/constantes.js.map +0 -1
- package/dist/core/contadores.d.ts.map +0 -1
- package/dist/core/contadores.js +0 -53
- package/dist/core/contadores.js.map +0 -1
- package/dist/core/sesion.d.ts.map +0 -1
- package/dist/core/sesion.js.map +0 -1
- package/dist/core/sobre.d.ts.map +0 -1
- package/dist/core/sobre.js +0 -200
- package/dist/core/sobre.js.map +0 -1
- package/dist/core/transporte.d.ts.map +0 -1
- package/dist/core/transporte.js.map +0 -1
- package/dist/telemetry/captura.d.ts.map +0 -1
- package/dist/telemetry/captura.js.map +0 -1
- package/dist/telemetry/tipos.d.ts.map +0 -1
- package/dist/telemetry/tipos.js +0 -2
- package/dist/telemetry/tipos.js.map +0 -1
- package/src/core/contadores.ts +0 -71
- package/src/core/sobre.ts +0 -236
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const stats = {
|
|
2
|
+
fired: 0,
|
|
3
|
+
completed: 0,
|
|
4
|
+
failed: 0,
|
|
5
|
+
before_send: 0,
|
|
6
|
+
trimmed: 0,
|
|
7
|
+
internal: 0,
|
|
8
|
+
};
|
|
9
|
+
/** Veces que el código pidió enviar. */
|
|
10
|
+
export function countFired() {
|
|
11
|
+
stats.fired += 1;
|
|
12
|
+
}
|
|
13
|
+
/** Envíos que terminaron, con cualquier status: un 429 y un 503 salieron y los rechazaron. */
|
|
14
|
+
export function countCompleted() {
|
|
15
|
+
stats.completed += 1;
|
|
16
|
+
}
|
|
17
|
+
/** Envíos que lanzaron: red, DNS. */
|
|
18
|
+
export function countFailed() {
|
|
19
|
+
stats.failed += 1;
|
|
20
|
+
}
|
|
21
|
+
export function countBeforeSend() {
|
|
22
|
+
stats.before_send += 1;
|
|
23
|
+
}
|
|
24
|
+
export function countTrimmed() {
|
|
25
|
+
stats.trimmed += 1;
|
|
26
|
+
}
|
|
27
|
+
/** La quinta forma de perder un evento: algo entre `buildEvent` y `serializeCapped` lanzó, y la
|
|
28
|
+
* red del `catch` de `capture` lo atrapó. Sin este contador, ese evento desaparecía sin dejar
|
|
29
|
+
* rastro en ningún `drops` del sobre siguiente. */
|
|
30
|
+
export function countInternal() {
|
|
31
|
+
stats.internal += 1;
|
|
32
|
+
}
|
|
33
|
+
/** `incompletos` es la resta, y es el único contador que prueba pérdida por ciclo de vida: sin
|
|
34
|
+
* esta separación, un 429 por rate limit y "se perdió el evento" se ven idénticos. */
|
|
35
|
+
export function drops() {
|
|
36
|
+
return {
|
|
37
|
+
incompletos: stats.fired - stats.completed - stats.failed,
|
|
38
|
+
fallados: stats.failed,
|
|
39
|
+
before_send: stats.before_send,
|
|
40
|
+
recortados: stats.trimmed,
|
|
41
|
+
internos: stats.internal,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Solo para los tests. No sale por ninguna puerta del `exports` map. */
|
|
45
|
+
export function resetCounters() {
|
|
46
|
+
stats.fired = 0;
|
|
47
|
+
stats.completed = 0;
|
|
48
|
+
stats.failed = 0;
|
|
49
|
+
stats.before_send = 0;
|
|
50
|
+
stats.trimmed = 0;
|
|
51
|
+
stats.internal = 0;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=counters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counters.js","sourceRoot":"","sources":["../../src/core/counters.ts"],"names":[],"mappings":"AAYA,MAAM,KAAK,GAAG;IACb,KAAK,EAAE,CAAC;IACR,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,CAAC;IACT,WAAW,EAAE,CAAC;IACd,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;CACX,CAAC;AAEF,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
|
1
|
+
import type { CaptureOptions, Envelope, Notify, RetryInfo, Severity, Surface, TelemetryEvent } from "./types.js";
|
|
2
2
|
/** El mismo truncado que aplica la ingesta del lado servidor. */
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function truncate(value: string, max: number): string;
|
|
4
4
|
/** Deja las primeras 64 claves. Los valores ya son escalares por tipo, así que no hay nada que
|
|
5
5
|
* serializar del lado del cliente. */
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function capAttributes(attrs: Record<string, string | number | boolean> | undefined): Record<string, string | number | boolean> | undefined;
|
|
7
7
|
/** Semántica de excepciones de OTel: type, message y stacktrace. */
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function extractException(error: unknown): TelemetryEvent["exception"];
|
|
9
9
|
/** Solo devuelve números donde el SDK REALMENTE los sabe. En `alarm` los maneja el repo, en
|
|
10
10
|
* `workflow` viven en el ctx del step y en `queue` en el mensaje: ahí se omite el bloque, porque
|
|
11
11
|
* un valor inventado silencia la alerta terminal. */
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function retryForSurface(surface: Surface): TelemetryEvent["retry"] | undefined;
|
|
13
13
|
/** Mapea los números de camelCase (API pública) a snake_case (contrato). */
|
|
14
|
-
export declare function
|
|
15
|
-
export interface
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export declare function retryFromOptions(info: RetryInfo): NonNullable<TelemetryEvent["retry"]>;
|
|
15
|
+
export interface EventArgs {
|
|
16
|
+
kind: "error" | "event";
|
|
17
|
+
message: string | undefined;
|
|
18
18
|
exception: TelemetryEvent["exception"] | undefined;
|
|
19
19
|
agentId: string;
|
|
20
20
|
surface: Surface;
|
|
21
21
|
severityDefault: Severity;
|
|
22
|
-
|
|
22
|
+
options: CaptureOptions;
|
|
23
23
|
}
|
|
24
|
-
export declare function
|
|
25
|
-
export interface
|
|
26
|
-
|
|
24
|
+
export declare function buildEvent(args: EventArgs): TelemetryEvent;
|
|
25
|
+
export interface EnvelopeArgs {
|
|
26
|
+
event: TelemetryEvent;
|
|
27
27
|
service: {
|
|
28
28
|
name: string;
|
|
29
29
|
version?: string;
|
|
@@ -35,12 +35,12 @@ export interface ArgsSobre {
|
|
|
35
35
|
}
|
|
36
36
|
/** Un sobre por captura, sin batching: el caso es 1 error por invocación, y batchear exigiría un
|
|
37
37
|
* punto de flush, que es justo donde se pierde data. */
|
|
38
|
-
export declare function
|
|
38
|
+
export declare function buildEnvelope(args: EnvelopeArgs): Envelope;
|
|
39
39
|
/** Recorta el sobre hasta que entre en el tope de bytes. NUNCA descarta el evento: un error con
|
|
40
40
|
* stacktrace enorme sigue siendo un error que hay que reportar. Muta el sobre, que es
|
|
41
41
|
* recién armado y de este módulo. */
|
|
42
|
-
export declare function
|
|
42
|
+
export declare function serializeCapped(envelope: Envelope): {
|
|
43
43
|
body: string;
|
|
44
|
-
|
|
44
|
+
trimmed: boolean;
|
|
45
45
|
};
|
|
46
|
-
//# sourceMappingURL=
|
|
46
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/core/envelope.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,QAAQ,EACR,MAAM,EACN,SAAS,EACT,QAAQ,EACR,OAAO,EACP,cAAc,EACd,MAAM,YAAY,CAAC;AAEpB,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3D;AAOD;uCACuC;AACvC,wBAAgB,aAAa,CAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS,GAC1D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS,CAIvD;AAWD,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,cAA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
|
|
3
|
+
import { nextSeq, session } from "./session.js";
|
|
4
|
+
/** El mismo truncado que aplica la ingesta del lado servidor. */
|
|
5
|
+
export function truncate(value, max) {
|
|
6
|
+
return value.length <= max ? value : `${value.slice(0, max)}…[truncado]`;
|
|
7
|
+
}
|
|
8
|
+
function bytesOf(text) {
|
|
9
|
+
// Se mide en bytes y no en caracteres, igual que la ingesta: un `é` ocupa 2 en UTF-8.
|
|
10
|
+
return new TextEncoder().encode(text).byteLength;
|
|
11
|
+
}
|
|
12
|
+
/** Deja las primeras 64 claves. Los valores ya son escalares por tipo, así que no hay nada que
|
|
13
|
+
* serializar del lado del cliente. */
|
|
14
|
+
export function capAttributes(attrs) {
|
|
15
|
+
if (attrs === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
const entries = Object.entries(attrs).slice(0, LIMITS.attributeKeys);
|
|
18
|
+
return Object.fromEntries(entries);
|
|
19
|
+
}
|
|
20
|
+
function textOf(value) {
|
|
21
|
+
try {
|
|
22
|
+
return typeof value === "string" ? value : (JSON.stringify(value) ?? String(value));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Un objeto con referencias circulares no puede hacer perder el evento.
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Semántica de excepciones de OTel: type, message y stacktrace. */
|
|
30
|
+
export function extractException(error) {
|
|
31
|
+
if (error instanceof Error) {
|
|
32
|
+
const output = {
|
|
33
|
+
type: error.name,
|
|
34
|
+
message: error.message,
|
|
35
|
+
};
|
|
36
|
+
if (error.stack !== undefined)
|
|
37
|
+
output.stacktrace = error.stack;
|
|
38
|
+
return output;
|
|
39
|
+
}
|
|
40
|
+
// Varios repos de cliente lanzan cosas que no son Error; igual tienen que llegar legibles.
|
|
41
|
+
return { type: "UnknownError", message: textOf(error) };
|
|
42
|
+
}
|
|
43
|
+
const NEUTRAL = {
|
|
44
|
+
attempt: 1,
|
|
45
|
+
limit: 1,
|
|
46
|
+
is_final_attempt: true,
|
|
47
|
+
work_unit_id: null,
|
|
48
|
+
};
|
|
49
|
+
/** Solo devuelve números donde el SDK REALMENTE los sabe. En `alarm` los maneja el repo, en
|
|
50
|
+
* `workflow` viven en el ctx del step y en `queue` en el mensaje: ahí se omite el bloque, porque
|
|
51
|
+
* un valor inventado silencia la alerta terminal. */
|
|
52
|
+
export function retryForSurface(surface) {
|
|
53
|
+
switch (surface) {
|
|
54
|
+
case "worker":
|
|
55
|
+
case "durable_object":
|
|
56
|
+
case "cron":
|
|
57
|
+
return { ...NEUTRAL };
|
|
58
|
+
default:
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// La ingesta exige `attempt`/`limit` >= 1: un 0 (o negativo, o no entero) pasado a mano por
|
|
63
|
+
// CaptureOptions se omite en vez de mandar un 400.
|
|
64
|
+
function positiveInteger(value) {
|
|
65
|
+
return value !== undefined && Number.isInteger(value) && value >= 1;
|
|
66
|
+
}
|
|
67
|
+
/** Mapea los números de camelCase (API pública) a snake_case (contrato). */
|
|
68
|
+
export function retryFromOptions(info) {
|
|
69
|
+
const output = {};
|
|
70
|
+
if (positiveInteger(info.attempt))
|
|
71
|
+
output.attempt = info.attempt;
|
|
72
|
+
if (positiveInteger(info.limit))
|
|
73
|
+
output.limit = info.limit;
|
|
74
|
+
if (info.isFinalAttempt !== undefined) {
|
|
75
|
+
output.is_final_attempt = info.isFinalAttempt;
|
|
76
|
+
}
|
|
77
|
+
else if (output.attempt !== undefined && output.limit !== undefined) {
|
|
78
|
+
// `>=` y nunca `>`: `limit` son intentos totales, así que con `>` la alerta terminal no
|
|
79
|
+
// se dispararía jamás.
|
|
80
|
+
output.is_final_attempt = output.attempt >= output.limit;
|
|
81
|
+
}
|
|
82
|
+
if (info.workUnitId !== undefined)
|
|
83
|
+
output.work_unit_id = info.workUnitId;
|
|
84
|
+
return output;
|
|
85
|
+
}
|
|
86
|
+
export function buildEvent(args) {
|
|
87
|
+
const { options } = args;
|
|
88
|
+
const event = {
|
|
89
|
+
event_id: crypto.randomUUID(),
|
|
90
|
+
seq: nextSeq(),
|
|
91
|
+
timestamp: new Date().toISOString(),
|
|
92
|
+
type: args.kind,
|
|
93
|
+
severity: options.severity ?? args.severityDefault,
|
|
94
|
+
// El agentId de las opciones pisa el de la config: los workers multi-tenant no lo
|
|
95
|
+
// conocen cuando se arma el cliente. `||` y no `??`: el agentId de la config ya se
|
|
96
|
+
// validó no vacío, así que un "" del caller (fila de D1 con NULL) no puede ganarle.
|
|
97
|
+
context: { agent_id: options.agentId || args.agentId },
|
|
98
|
+
};
|
|
99
|
+
if (args.message !== undefined) {
|
|
100
|
+
event.message = truncate(args.message, LIMITS.messageChars);
|
|
101
|
+
}
|
|
102
|
+
if (options.workUnit !== undefined)
|
|
103
|
+
event.context.work_unit = options.workUnit;
|
|
104
|
+
if (options.traceId !== undefined)
|
|
105
|
+
event.context.trace_id = options.traceId;
|
|
106
|
+
if (options.conversationId !== undefined) {
|
|
107
|
+
event.context.conversation_id = options.conversationId;
|
|
108
|
+
}
|
|
109
|
+
if (options.requestId !== undefined)
|
|
110
|
+
event.context.request_id = options.requestId;
|
|
111
|
+
if (args.exception !== undefined) {
|
|
112
|
+
const exception = { ...args.exception };
|
|
113
|
+
if (exception.stacktrace !== undefined) {
|
|
114
|
+
exception.stacktrace = truncate(exception.stacktrace, LIMITS.stacktraceChars);
|
|
115
|
+
}
|
|
116
|
+
// La ingesta no trunca este campo, pero es el mismo texto que `message` y dejarlo suelto
|
|
117
|
+
// hace que un mensaje enorme se coma el tope de bytes del sobre.
|
|
118
|
+
if (exception.message !== undefined) {
|
|
119
|
+
exception.message = truncate(exception.message, LIMITS.messageChars);
|
|
120
|
+
}
|
|
121
|
+
event.exception = exception;
|
|
122
|
+
}
|
|
123
|
+
const retry = options.retry !== undefined ? retryFromOptions(options.retry) : retryForSurface(args.surface);
|
|
124
|
+
if (retry !== undefined)
|
|
125
|
+
event.retry = retry;
|
|
126
|
+
const attrs = capAttributes(options.attributes);
|
|
127
|
+
if (attrs !== undefined)
|
|
128
|
+
event.attributes = attrs;
|
|
129
|
+
// Si va, la ingesta lo usa tal cual en vez de calcular la huella.
|
|
130
|
+
if (options.fingerprint !== undefined)
|
|
131
|
+
event.fingerprint = options.fingerprint;
|
|
132
|
+
return event;
|
|
133
|
+
}
|
|
134
|
+
/** Un sobre por captura, sin batching: el caso es 1 error por invocación, y batchear exigiría un
|
|
135
|
+
* punto de flush, que es justo donde se pierde data. */
|
|
136
|
+
export function buildEnvelope(args) {
|
|
137
|
+
return {
|
|
138
|
+
sdk: { name: SDK_NAME, version: SDK_VERSION },
|
|
139
|
+
sent_at: new Date().toISOString(),
|
|
140
|
+
// El spread arma un objeto fresco: `Drops` es una interfaz sin índice y TypeScript no la
|
|
141
|
+
// deja pasar directo como `Record<string, number>` (el tipo del sobre, más permisivo a propósito).
|
|
142
|
+
drops: { ...drops() },
|
|
143
|
+
// Perezoso: la primera captura es la que genera el id del isolate.
|
|
144
|
+
session: session(),
|
|
145
|
+
resource: {
|
|
146
|
+
service: args.service,
|
|
147
|
+
client: { organization_id: args.organizationId },
|
|
148
|
+
surface: args.surface,
|
|
149
|
+
},
|
|
150
|
+
notify: args.notify,
|
|
151
|
+
events: [args.event],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** Recorta el sobre hasta que entre en el tope de bytes. NUNCA descarta el evento: un error con
|
|
155
|
+
* stacktrace enorme sigue siendo un error que hay que reportar. Muta el sobre, que es
|
|
156
|
+
* recién armado y de este módulo. */
|
|
157
|
+
export function serializeCapped(envelope) {
|
|
158
|
+
let body = JSON.stringify(envelope);
|
|
159
|
+
if (bytesOf(body) <= LIMITS.bodyBytes)
|
|
160
|
+
return { body, trimmed: false };
|
|
161
|
+
const event = envelope.events[0];
|
|
162
|
+
// En orden de "lo más grande y lo menos valioso" primero.
|
|
163
|
+
const steps = [
|
|
164
|
+
() => {
|
|
165
|
+
if (event.exception?.stacktrace !== undefined) {
|
|
166
|
+
event.exception.stacktrace = truncate(event.exception.stacktrace, 1024);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
() => {
|
|
170
|
+
if (event.exception !== undefined)
|
|
171
|
+
delete event.exception.stacktrace;
|
|
172
|
+
},
|
|
173
|
+
() => {
|
|
174
|
+
if (event.attributes !== undefined)
|
|
175
|
+
event.attributes = {};
|
|
176
|
+
},
|
|
177
|
+
() => {
|
|
178
|
+
if (event.message !== undefined)
|
|
179
|
+
event.message = truncate(event.message, 256);
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
for (const step of steps) {
|
|
183
|
+
step();
|
|
184
|
+
body = JSON.stringify(envelope);
|
|
185
|
+
if (bytesOf(body) <= LIMITS.bodyBytes)
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
// No cambia la política —no se descarta el evento, no se agregan pasos—, solo deja de ser
|
|
189
|
+
// mudo: el exceso vive en un campo que ningún paso toca (`fingerprint`, un identificador
|
|
190
|
+
// gigantesco), y la ingesta lo va a rechazar con 413 (docs/telemetry/troubleshooting.md).
|
|
191
|
+
const finalBytes = bytesOf(body);
|
|
192
|
+
if (finalBytes > LIMITS.bodyBytes) {
|
|
193
|
+
console.error(`[delta-sdk] el sobre sigue arriba del tope de ${LIMITS.bodyBytes} bytes después de recortar (${finalBytes} bytes); la ingesta lo va a rechazar con 413`);
|
|
194
|
+
}
|
|
195
|
+
countTrimmed();
|
|
196
|
+
return { body, trimmed: true };
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/core/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,OAAO,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AAS,CAAC,UAAU,CAAC;QACtE,CAAC;QACD,GAAG,EAAE;YACJ,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;gBAAE,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC;QAC3D,CAAC;QACD,GAAG,EAAE;YACJ,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS;gBAAE,KAAK,CAAC,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC/E,CAAC;KACD,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,EAAE,CAAC;QACP,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM;IAC9C,CAAC;IAED,0FAA0F;IAC1F,yFAAyF;IACzF,0FAA0F;IAC1F,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,UAAU,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QACnC,OAAO,CAAC,KAAK,CACZ,iDAAiD,MAAM,CAAC,SAAS,+BAA+B,UAAU,8CAA8C,CACxJ,CAAC;IACH,CAAC;IAED,YAAY,EAAE,CAAC;IACf,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC"}
|
package/dist/core/scrubbing.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { TelemetryEvent } from "./
|
|
2
|
-
export declare const
|
|
1
|
+
import type { TelemetryEvent } from "./types.js";
|
|
2
|
+
export declare const REDACTED = "[redactado]";
|
|
3
3
|
/** Los términos habituales en credenciales: claves, tokens y headers de autorización. */
|
|
4
4
|
export declare const DENYLIST: readonly ["secret", "token", "apikey", "api_key", "password", "authorization", "bearer", "cookie", "credential", "private_key"];
|
|
5
5
|
/** Devuelve una copia con la denylist y los términos del cliente aplicados. No muta la entrada:
|
|
6
6
|
* el evento original es el que ve el implementador si algo falla después. */
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function scrubEvent(event: TelemetryEvent, extra?: string[]): TelemetryEvent;
|
|
8
8
|
/** El escape hatch. Un `null` descarta el evento; una excepción no puede hacerlo perder. */
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function applyBeforeSend(event: TelemetryEvent, beforeSend: ((event: TelemetryEvent) => TelemetryEvent | null) | undefined): TelemetryEvent | null;
|
|
10
10
|
//# sourceMappingURL=scrubbing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrubbing.d.ts","sourceRoot":"","sources":["../../src/core/scrubbing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"scrubbing.d.ts","sourceRoot":"","sources":["../../src/core/scrubbing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,QAAQ,gBAAgB,CAAC;AAEtC,yFAAyF;AACzF,eAAO,MAAM,QAAQ,iIAWX,CAAC;AAwCX;8EAC8E;AAC9E,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,GAAE,MAAM,EAAO,GAAG,cAAc,CA+BtF;AAED,4FAA4F;AAC5F,wBAAgB,eAAe,CAC9B,KAAK,EAAE,cAAc,EACrB,UAAU,EAAE,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,cAAc,GAAG,IAAI,CAAC,GAAG,SAAS,GACxE,cAAc,GAAG,IAAI,CAQvB"}
|
package/dist/core/scrubbing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const REDACTED = "[redactado]";
|
|
2
2
|
/** Los términos habituales en credenciales: claves, tokens y headers de autorización. */
|
|
3
3
|
export const DENYLIST = [
|
|
4
4
|
"secret",
|
|
@@ -12,12 +12,12 @@ export const DENYLIST = [
|
|
|
12
12
|
"credential",
|
|
13
13
|
"private_key",
|
|
14
14
|
];
|
|
15
|
-
function
|
|
16
|
-
return
|
|
15
|
+
function escapeRegex(term) {
|
|
16
|
+
return term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
return
|
|
18
|
+
function suspiciousKey(key, terms) {
|
|
19
|
+
const lower = key.toLowerCase();
|
|
20
|
+
return terms.some((term) => lower.includes(term.toLowerCase()));
|
|
21
21
|
}
|
|
22
22
|
/** Es una red para descuidos, no una garantía: un secreto en un campo llamado `config` no lo
|
|
23
23
|
* agarra. La defensa real es no meter secretos en el mensaje de error.
|
|
@@ -30,63 +30,63 @@ function claveSospechosa(clave, terminos) {
|
|
|
30
30
|
* tenían ningún secreto. Con `bearer` la apuesta vale la pena porque el 100% de sus apariciones
|
|
31
31
|
* reales son un header sin dos puntos (`Bearer eyJ…`); con los términos que el propio cliente
|
|
32
32
|
* pasa por `scrub` también, porque ahí la agresividad es la que pidió explícitamente. */
|
|
33
|
-
function
|
|
34
|
-
let
|
|
35
|
-
for (const
|
|
36
|
-
const t =
|
|
33
|
+
function redactText(text, full, aggressive) {
|
|
34
|
+
let output = text;
|
|
35
|
+
for (const term of full) {
|
|
36
|
+
const t = escapeRegex(term);
|
|
37
37
|
// `clave: valor` y `clave=valor`: se borra el resto de la línea, porque el valor puede
|
|
38
38
|
// tener espacios (`Authorization: Bearer eyJ…`).
|
|
39
|
-
|
|
39
|
+
output = output.replace(new RegExp(`(${t})\\s*[:=]\\s*[^\\n]*`, "gi"), `$1: ${REDACTED}`);
|
|
40
40
|
}
|
|
41
|
-
for (const
|
|
42
|
-
const t =
|
|
41
|
+
for (const term of aggressive) {
|
|
42
|
+
const t = escapeRegex(term);
|
|
43
43
|
// `clave valor`: solo el token que sigue, y solo para `bearer` y los términos del cliente
|
|
44
44
|
// (ver el comentario de arriba). No matchea una mención suelta al final de la frase, que
|
|
45
45
|
// no tiene nada detrás.
|
|
46
|
-
|
|
46
|
+
output = output.replace(new RegExp(`(${t})\\s+(\\S+)`, "gi"), `$1 ${REDACTED}`);
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return output;
|
|
49
49
|
}
|
|
50
50
|
/** Devuelve una copia con la denylist y los términos del cliente aplicados. No muta la entrada:
|
|
51
51
|
* el evento original es el que ve el implementador si algo falla después. */
|
|
52
|
-
export function
|
|
53
|
-
const
|
|
52
|
+
export function scrubEvent(event, extra = []) {
|
|
53
|
+
const terms = [...DENYLIST, ...extra];
|
|
54
54
|
// La regla sin separador solo corre para `bearer` (headers reales sin dos puntos) y lo que el
|
|
55
55
|
// cliente mismo eligió redactar así: el resto de la denylist es prosa común, no un valor.
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
56
|
+
const aggressive = ["bearer", ...extra];
|
|
57
|
+
const output = { ...event };
|
|
58
|
+
if (output.message !== undefined) {
|
|
59
|
+
output.message = redactText(output.message, terms, aggressive);
|
|
60
60
|
}
|
|
61
|
-
if (
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
61
|
+
if (output.exception !== undefined) {
|
|
62
|
+
const exception = { ...output.exception };
|
|
63
|
+
if (exception.message !== undefined) {
|
|
64
|
+
exception.message = redactText(exception.message, terms, aggressive);
|
|
65
65
|
}
|
|
66
|
-
if (
|
|
67
|
-
|
|
66
|
+
if (exception.stacktrace !== undefined) {
|
|
67
|
+
exception.stacktrace = redactText(exception.stacktrace, terms, aggressive);
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
output.exception = exception;
|
|
70
70
|
}
|
|
71
|
-
if (
|
|
72
|
-
const
|
|
73
|
-
for (const [
|
|
74
|
-
|
|
71
|
+
if (output.attributes !== undefined) {
|
|
72
|
+
const scrubbedAttrs = {};
|
|
73
|
+
for (const [key, value] of Object.entries(output.attributes)) {
|
|
74
|
+
scrubbedAttrs[key] = suspiciousKey(key, terms) ? REDACTED : value;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
output.attributes = scrubbedAttrs;
|
|
77
77
|
}
|
|
78
|
-
return
|
|
78
|
+
return output;
|
|
79
79
|
}
|
|
80
80
|
/** El escape hatch. Un `null` descarta el evento; una excepción no puede hacerlo perder. */
|
|
81
|
-
export function
|
|
81
|
+
export function applyBeforeSend(event, beforeSend) {
|
|
82
82
|
if (beforeSend === undefined)
|
|
83
|
-
return
|
|
83
|
+
return event;
|
|
84
84
|
try {
|
|
85
|
-
return beforeSend(
|
|
85
|
+
return beforeSend(event);
|
|
86
86
|
}
|
|
87
87
|
catch (error) {
|
|
88
88
|
console.error("[delta-sdk] beforeSend lanzó; el evento se manda sin aplicarlo", error);
|
|
89
|
-
return
|
|
89
|
+
return event;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
//# sourceMappingURL=scrubbing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrubbing.js","sourceRoot":"","sources":["../../src/core/scrubbing.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"scrubbing.js","sourceRoot":"","sources":["../../src/core/scrubbing.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAAG,aAAa,CAAC;AAEtC,yFAAyF;AACzF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,SAAS;IACT,UAAU;IACV,eAAe;IACf,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,aAAa;CACJ,CAAC;AAEX,SAAS,WAAW,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,aAAa,CAAC,GAAW,EAAE,KAAe;IAClD,MAAM,K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U,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,gEAAgE,EAAE,KAAK,CAAC,CAAC;QACvF,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC"}
|
|
@@ -5,5 +5,5 @@ export declare function session(): string;
|
|
|
5
5
|
* llegan. Detecta huecos en el medio, no una cola cortada. */
|
|
6
6
|
export declare function nextSeq(): number;
|
|
7
7
|
/** Solo para los tests. No sale por ninguna puerta del `exports` map. */
|
|
8
|
-
export declare function
|
|
9
|
-
//# sourceMappingURL=
|
|
8
|
+
export declare function resetSession(): void;
|
|
9
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAGA;yDACyD;AACzD,wBAAgB,OAAO,IAAI,MAAM,CAGhC;AAED;+DAC+D;AAC/D,wBAAgB,OAAO,IAAI,MAAM,CAGhC;AAED,yEAAyE;AACzE,wBAAgB,YAAY,IAAI,IAAI,CAGnC"}
|
|
@@ -13,8 +13,8 @@ export function nextSeq() {
|
|
|
13
13
|
return _seq;
|
|
14
14
|
}
|
|
15
15
|
/** Solo para los tests. No sale por ninguna puerta del `exports` map. */
|
|
16
|
-
export function
|
|
16
|
+
export function resetSession() {
|
|
17
17
|
_session = null;
|
|
18
18
|
_seq = 0;
|
|
19
19
|
}
|
|
20
|
-
//# sourceMappingURL=
|
|
20
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/core/session.ts"],"names":[],"mappings":"AAAA,IAAI,QAAQ,GAAkB,IAAI,CAAC;AACnC,IAAI,IAAI,GAAG,CAAC,CAAC;AAEb;yDACyD;AACzD,MAAM,UAAU,OAAO;IACtB,gGAAgG;IAChG,OAAO,CAAC,QAAQ,KAAK,MAAM,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;+DAC+D;AAC/D,MAAM,UAAU,OAAO;IACtB,IAAI,IAAI,CAAC,CAAC;IACV,OAAO,IAAI,CAAC;AACb,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,YAAY;IAC3B,QAAQ,GAAG,IAAI,CAAC;IAChB,IAAI,GAAG,CAAC,CAAC;AACV,CAAC"}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { CtxLike } from "./
|
|
1
|
+
import type { CtxLike } from "./types.js";
|
|
2
2
|
/** El texto completo del aviso: dice qué pasó, qué consecuencia tiene y cómo arreglarlo. Sin este
|
|
3
3
|
* aviso el evento se pierde en silencio en `worker` y `queue`, que es exactamente el modo de
|
|
4
4
|
* falla que este paquete existe para eliminar. */
|
|
5
|
-
export declare const
|
|
6
|
-
export interface
|
|
5
|
+
export declare const BROKEN_CTX_WARNING: string;
|
|
6
|
+
export interface UsableCtx {
|
|
7
7
|
waitUntil: (p: Promise<unknown>) => void;
|
|
8
8
|
}
|
|
9
9
|
/** Lo prueba UNA vez, con una promesa ya resuelta. No alcanza con preguntar si `waitUntil`
|
|
10
10
|
* existe: la copia del ctx hereda el método pero no la identidad del objeto nativo, así que
|
|
11
11
|
* existe y tira `Illegal invocation` al invocarlo. */
|
|
12
|
-
export declare function
|
|
13
|
-
export interface
|
|
12
|
+
export declare function probeCtx(ctx: CtxLike | undefined, warn: () => void): UsableCtx | null;
|
|
13
|
+
export interface SendArgs {
|
|
14
14
|
body: string;
|
|
15
15
|
apiKey: string;
|
|
16
16
|
url: string;
|
|
17
|
-
ctx:
|
|
17
|
+
ctx: UsableCtx | null;
|
|
18
18
|
debug: boolean;
|
|
19
|
-
|
|
19
|
+
warnBrokenCtx: () => void;
|
|
20
20
|
}
|
|
21
21
|
/** Dispara el POST y no espera nada. No reintenta, no lanza, y la promesa que le pasa a
|
|
22
22
|
* `waitUntil` nunca rechaza. */
|
|
23
|
-
export declare function
|
|
24
|
-
//# sourceMappingURL=
|
|
23
|
+
export declare function send(args: SendArgs): void;
|
|
24
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/core/transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;mDAEmD;AACnD,eAAO,MAAM,kBAAkB,QAMpB,CAAC;AAEZ,MAAM,WAAW,SAAS;IACzB,SAAS,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CACzC;AAED;;uDAEuD;AACvD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,SAAS,GAAG,IAAI,CASrF;AAkBD,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,aAAa,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED;iCACiC;AACjC,wBAAgB,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAiCzC"}
|