@ddd-ts-kit/sentry 0.105.0 → 0.106.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/README.fr.md +16 -3
- package/README.md +14 -2
- package/dist/scrubbing/scrub-event.d.ts +6 -4
- package/dist/scrubbing/scrub-event.d.ts.map +1 -1
- package/dist/scrubbing/scrub-event.js +47 -5
- package/dist/scrubbing/scrub-event.js.map +1 -1
- package/dist/scrubbing/without-quoted-values.d.ts +3 -0
- package/dist/scrubbing/without-quoted-values.d.ts.map +1 -0
- package/dist/scrubbing/without-quoted-values.js +52 -0
- package/dist/scrubbing/without-quoted-values.js.map +1 -0
- package/package.json +8 -5
package/README.fr.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[English](README.md) · **Français**
|
|
2
|
-
<!-- translation-of: README.md sha256:
|
|
2
|
+
<!-- translation-of: README.md sha256:463278a43493852b -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/sentry
|
|
5
5
|
|
|
@@ -43,7 +43,8 @@ reportProcessFailures(errors); // uncaughtException et unhandledRejection : remo
|
|
|
43
43
|
import { tracing } from '@/platform/observability/tracing'; // en premier
|
|
44
44
|
import { errors } from '@/platform/observability/errors'; // en second
|
|
45
45
|
import { DeadLetterReports, ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
46
|
-
import {
|
|
46
|
+
import { kernelModule } from '@ddd-ts-kit/di';
|
|
47
|
+
import { createApplication } from '@ddd-ts-kit/di/tsyringe';
|
|
47
48
|
import { reportHttpErrors } from '@ddd-ts-kit/http';
|
|
48
49
|
import { RabbitMqEventBus } from '@ddd-ts-kit/rabbitmq';
|
|
49
50
|
|
|
@@ -255,7 +256,8 @@ par l'exportateur du kit.
|
|
|
255
256
|
| *tenant* | non envoyé | `tagTenant: true` |
|
|
256
257
|
| variables locales | jamais | |
|
|
257
258
|
| fil d'Ariane (breadcrumbs) | aucun n'est enregistré automatiquement : ni console, ni appel sortant | `Sentry.addBreadcrumb` là où le projet le décide |
|
|
258
|
-
| message de l'exception |
|
|
259
|
+
| message de l'exception | envoyé, les valeurs que cite une requête SQL en échec masquées | `scrubMessages: true` le retire pour chaque erreur qui n'est pas une `DomainError` |
|
|
260
|
+
| valeurs que cite une requête SQL en échec | jamais, dans un message, une cause ou ce qu'une intégration a copié de l'erreur (`extra`, contextes) : la requête reste, paramètres positionnels compris | |
|
|
259
261
|
|
|
260
262
|
**Messages.** Le message est la première chose qu'on lit dans un outil de suivi des erreurs, et
|
|
261
263
|
le premier endroit où fuient des données personnelles : un pilote cite la ligne qu'il a refusée.
|
|
@@ -268,6 +270,17 @@ assez sensibles pour qu'aucun opérateur ne doive les y lire. Les *loggers* du k
|
|
|
268
270
|
(`StdoutLogger`, `@ddd-ts-kit/pino`, `@ddd-ts-kit/winston`) prennent l'option sous le même nom,
|
|
269
271
|
avec la même règle et le même marqueur, `SCRUBBED_MESSAGE` du noyau.
|
|
270
272
|
|
|
273
|
+
**Valeurs d'une requête SQL en échec.** Quoi que dise `scrubMessages`, `scrubEvent` remplace par
|
|
274
|
+
`[redacted]` chaque valeur que cite un pilote, et garde la requête, qui est le signal : les
|
|
275
|
+
paramètres que Drizzle écrit après `params:` dans une `DrizzleQueryError` ; la clé d'une
|
|
276
|
+
contrainte d'unicité ou de clé étrangère violée (`Key (email)=([redacted]) already exists.`, dans
|
|
277
|
+
un message ou un `detail`) ; la ligne qu'une contrainte `not null` ou `check` a refusée
|
|
278
|
+
(`Failing row contains ([redacted]).`) ; une valeur que PostgreSQL n'a pas su lire
|
|
279
|
+
(`invalid input syntax for type integer: "[redacted]"`) ; les arguments que Prisma affiche d'un
|
|
280
|
+
appel qu'il refuse ; un champ nommé `parameters`, `params` ou `bindings` qu'une intégration a
|
|
281
|
+
copié de l'erreur. Knex sur PostgreSQL cite `$1`, et TypeORM le message du serveur, dont les
|
|
282
|
+
formes sont celles ci-dessus.
|
|
283
|
+
|
|
271
284
|
`beforeSend` s'exécute en dernier, sur l'événement nettoyé, et peut l'écarter en renvoyant
|
|
272
285
|
`null`.
|
|
273
286
|
|
package/README.md
CHANGED
|
@@ -40,7 +40,8 @@ reportProcessFailures(errors); // uncaughtException and unhandledRejection: repo
|
|
|
40
40
|
import { tracing } from '@/platform/observability/tracing'; // first
|
|
41
41
|
import { errors } from '@/platform/observability/errors'; // second
|
|
42
42
|
import { DeadLetterReports, ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
43
|
-
import {
|
|
43
|
+
import { kernelModule } from '@ddd-ts-kit/di';
|
|
44
|
+
import { createApplication } from '@ddd-ts-kit/di/tsyringe';
|
|
44
45
|
import { reportHttpErrors } from '@ddd-ts-kit/http';
|
|
45
46
|
import { RabbitMqEventBus } from '@ddd-ts-kit/rabbitmq';
|
|
46
47
|
|
|
@@ -243,7 +244,8 @@ spans themselves are exported once, by the exporter of the kit.
|
|
|
243
244
|
| tenant | not sent | `tagTenant: true` |
|
|
244
245
|
| local variables | never | |
|
|
245
246
|
| breadcrumbs | none is recorded automatically: no console, no outgoing call | `Sentry.addBreadcrumb` where the project decides |
|
|
246
|
-
| exception message | sent | `scrubMessages: true` removes it for every error that is not a `DomainError` |
|
|
247
|
+
| exception message | sent, the values a failed statement quotes redacted | `scrubMessages: true` removes it for every error that is not a `DomainError` |
|
|
248
|
+
| values a failed statement quotes | never, in a message, a cause or what an integration copied of the error (`extra`, contexts): the statement stays, placeholders included | |
|
|
247
249
|
|
|
248
250
|
**Messages.** The message is the first thing read in an error tracker, and the first place
|
|
249
251
|
where personal data leaks: a driver quotes the row it refused. The default keeps it, because an
|
|
@@ -255,6 +257,16 @@ when the data is sensitive enough that no operator should read it there. The log
|
|
|
255
257
|
kit (`StdoutLogger`, `@ddd-ts-kit/pino`, `@ddd-ts-kit/winston`) take the option under the same
|
|
256
258
|
name, with the same rule and the same marker, `SCRUBBED_MESSAGE` of the kernel.
|
|
257
259
|
|
|
260
|
+
**Values of a failed statement.** Whatever `scrubMessages` says, `scrubEvent` replaces by
|
|
261
|
+
`[redacted]` each value a driver quotes, and keeps the statement, which is the signal: the
|
|
262
|
+
parameters Drizzle writes after `params:` in a `DrizzleQueryError`; the key of a violated unique
|
|
263
|
+
or foreign key constraint (`Key (email)=([redacted]) already exists.`, in a message or a
|
|
264
|
+
`detail`); the row a not-null or a check constraint refused (`Failing row contains
|
|
265
|
+
([redacted]).`); a value PostgreSQL could not read (`invalid input syntax for type integer:
|
|
266
|
+
"[redacted]"`); the arguments Prisma renders of a call it refused; a field named `parameters`,
|
|
267
|
+
`params` or `bindings` that an integration copied of the error. Knex on PostgreSQL quotes `$1`,
|
|
268
|
+
and TypeORM the message of the server, whose forms are the ones above.
|
|
269
|
+
|
|
258
270
|
`beforeSend` runs last, on the scrubbed event, and may drop it by answering `null`.
|
|
259
271
|
|
|
260
272
|
The DSN stays inside the SDK client. A `SentryErrorReporter` that is logged, spread or
|
|
@@ -5,10 +5,12 @@ export interface ScrubOptions {
|
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* What leaves the process, whatever an integration or the project put on the event: of the
|
|
8
|
-
* request, its method and its URL without query string; of the user, the id alone
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* request, its method and its URL without query string; of the user, the id alone; of a failed
|
|
9
|
+
* statement, the statement without the values a driver quotes, in the messages and in what an
|
|
10
|
+
* integration copied of the error (`extra`, contexts). With `scrubMessages`, an exception keeps its
|
|
11
|
+
* message only when a `DomainError` of that class is in the chain of the reported error: those
|
|
12
|
+
* messages are written by the project, the others come from drivers and libraries and quote the
|
|
13
|
+
* data they choked on.
|
|
12
14
|
*/
|
|
13
15
|
export declare function scrubEvent(event: ErrorEvent, hint: EventHint, options: ScrubOptions): ErrorEvent;
|
|
14
16
|
//# sourceMappingURL=scrub-event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrub-event.d.ts","sourceRoot":"","sources":["../../src/scrubbing/scrub-event.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"scrub-event.d.ts","sourceRoot":"","sources":["../../src/scrubbing/scrub-event.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI1D,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC;AAQD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU,CAgBhG"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { DomainError, SCRUBBED_MESSAGE } from '@ddd-ts-kit/kernel';
|
|
1
|
+
import { DomainError, REDACTED, SCRUBBED_MESSAGE } from '@ddd-ts-kit/kernel';
|
|
2
2
|
import { scrubRequest } from './scrub-request.js';
|
|
3
|
+
import { withoutQuotedValues } from './without-quoted-values.js';
|
|
3
4
|
const DEEPEST_CAUSE = 8;
|
|
5
|
+
const DEEPEST_FIELD = 8;
|
|
6
|
+
/* Where a driver keeps the values of a statement on its error: TypeORM, Knex, Drizzle. */
|
|
7
|
+
const PARAMETER_KEYS = new Set(['parameters', 'params', 'bindings']);
|
|
4
8
|
/**
|
|
5
9
|
* What leaves the process, whatever an integration or the project put on the event: of the
|
|
6
|
-
* request, its method and its URL without query string; of the user, the id alone
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* request, its method and its URL without query string; of the user, the id alone; of a failed
|
|
11
|
+
* statement, the statement without the values a driver quotes, in the messages and in what an
|
|
12
|
+
* integration copied of the error (`extra`, contexts). With `scrubMessages`, an exception keeps its
|
|
13
|
+
* message only when a `DomainError` of that class is in the chain of the reported error: those
|
|
14
|
+
* messages are written by the project, the others come from drivers and libraries and quote the
|
|
15
|
+
* data they choked on.
|
|
10
16
|
*/
|
|
11
17
|
export function scrubEvent(event, hint, options) {
|
|
12
18
|
if (event.request !== undefined) {
|
|
@@ -15,6 +21,7 @@ export function scrubEvent(event, hint, options) {
|
|
|
15
21
|
if (event.user !== undefined) {
|
|
16
22
|
event.user = event.user.id === undefined ? {} : { id: event.user.id };
|
|
17
23
|
}
|
|
24
|
+
dropQuotedValues(event);
|
|
18
25
|
if (options.scrubMessages) {
|
|
19
26
|
scrubMessages(event, domainErrorNames(hint.originalException, DEEPEST_CAUSE));
|
|
20
27
|
}
|
|
@@ -33,6 +40,41 @@ function innerErrors(error) {
|
|
|
33
40
|
const aggregated = error instanceof AggregateError ? error.errors : [];
|
|
34
41
|
return 'cause' in error ? [error.cause, ...aggregated] : aggregated;
|
|
35
42
|
}
|
|
43
|
+
function dropQuotedValues(event) {
|
|
44
|
+
for (const exception of event.exception?.values ?? []) {
|
|
45
|
+
if (exception.value !== undefined) {
|
|
46
|
+
exception.value = withoutQuotedValues(exception.value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (event.message !== undefined) {
|
|
50
|
+
event.message = withoutQuotedValues(event.message);
|
|
51
|
+
}
|
|
52
|
+
if (event.extra !== undefined) {
|
|
53
|
+
event.extra = withoutValuesIn(event.extra, DEEPEST_FIELD);
|
|
54
|
+
}
|
|
55
|
+
if (event.contexts !== undefined) {
|
|
56
|
+
event.contexts = withoutValuesIn(event.contexts, DEEPEST_FIELD);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** What an integration copied of an error (`detail`, `parameters` of TypeORM), its values redacted. */
|
|
60
|
+
function withoutValuesIn(fields, depth) {
|
|
61
|
+
const redacted = {};
|
|
62
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
63
|
+
redacted[key] = PARAMETER_KEYS.has(key) ? REDACTED : withoutValuesOf(value, depth - 1);
|
|
64
|
+
}
|
|
65
|
+
return Object.assign(fields, redacted);
|
|
66
|
+
}
|
|
67
|
+
function withoutValuesOf(value, depth) {
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
return withoutQuotedValues(value);
|
|
70
|
+
}
|
|
71
|
+
if (depth === 0 || typeof value !== 'object' || value === null) {
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
return Array.isArray(value)
|
|
75
|
+
? value.map((one) => withoutValuesOf(one, depth - 1))
|
|
76
|
+
: withoutValuesIn({ ...value }, depth);
|
|
77
|
+
}
|
|
36
78
|
function scrubMessages(event, kept) {
|
|
37
79
|
for (const exception of event.exception?.values ?? []) {
|
|
38
80
|
if (exception.type === undefined || !kept.includes(exception.type)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrub-event.js","sourceRoot":"","sources":["../../src/scrubbing/scrub-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"scrub-event.js","sourceRoot":"","sources":["../../src/scrubbing/scrub-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAO9D,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,0FAA0F;AAC1F,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;AAE1F;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,IAAe,EAAE,OAAqB;IAClF,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChC,KAAK,CAAC,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,OAAO,CA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,CAAC,KAAc,EAAE,KAAa;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,KAAK,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC/D,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAY,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC,CAAC,eAAe,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,aAAa,CAAC,KAAiB,EAAE,IAAuB;IAC/D,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC;QACtD,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YACnE,SAAS,CAAC,KAAK,GAAG,gBAAgB,CAAC;QACrC,CAAC;IACH,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChC,KAAK,CAAC,OAAO,GAAG,gBAAgB,CAAC;IACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"without-quoted-values.d.ts","sourceRoot":"","sources":["../../src/scrubbing/without-quoted-values.ts"],"names":[],"mappings":"AAgCA,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIxD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { REDACTED } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/*
|
|
3
|
+
* Each form in which a driver quotes a value of the statement it ran, as drizzle-orm 0.45, pg 8,
|
|
4
|
+
* knex 3, TypeORM 1 and Prisma 7 write it on PostgreSQL. The statement stays, placeholders
|
|
5
|
+
* included: it is what a failure is read for. Knex on PostgreSQL quotes `$1`, TypeORM the message
|
|
6
|
+
* of the server: what they quote of a value is one of the forms of PostgreSQL.
|
|
7
|
+
*/
|
|
8
|
+
const QUOTED_VALUES = [
|
|
9
|
+
// `DrizzleQueryError`: `Failed query: <statement>\nparams: <the parameters, joined by commas>`.
|
|
10
|
+
[/^(Failed query: [\s\S]*?\nparams: )[\s\S]*$/, `$1${REDACTED}`],
|
|
11
|
+
// The `detail` of a unique or a foreign key violation: `Key (email)=(ada@example.org) already exists.`
|
|
12
|
+
[
|
|
13
|
+
/(Key \([^)\n]*\)=\()[^\n]*?(\) (?:already exists|is not present in table|is still referenced from table))/g,
|
|
14
|
+
`$1${REDACTED}$2`,
|
|
15
|
+
],
|
|
16
|
+
// The `detail` of a not-null or a check violation: `Failing row contains (ada@example.org, null).`
|
|
17
|
+
[/(Failing row contains \()[^\n]*(\)\.?)/g, `$1${REDACTED}$2`],
|
|
18
|
+
// A value the server could not read: `invalid input syntax for type integer: "ada@example.org"`.
|
|
19
|
+
[/((?:invalid input syntax for type|invalid input value for enum) [^:\n]+: ")[^\n]*(")/g, `$1${REDACTED}$2`],
|
|
20
|
+
[/(date\/time field value out of range: ")[^\n]*(")/g, `$1${REDACTED}$2`],
|
|
21
|
+
[/(value ")[^\n]*(" is out of range for type )/g, `$1${REDACTED}$2`],
|
|
22
|
+
];
|
|
23
|
+
/* The line of a message of Prisma that names the call it refused. */
|
|
24
|
+
const PRISMA_CALL = /^(?:Invalid|It occurred in the) `[^`]+` invocation(?: in|:)$/;
|
|
25
|
+
/* A colour of the terminal: the escape character, then `[<codes>m`. */
|
|
26
|
+
const COLOUR = new RegExp(`${String.fromCharCode(0x1b)}\\[[0-9;]*m`, 'g');
|
|
27
|
+
/* A field of the call Prisma renders when it refuses one: ` email: "ada@example.org",`. */
|
|
28
|
+
const PRISMA_ARGUMENT = /^(\s+[\w$]+: )(?![{[]\s*$)[^\n]*?(,?)$/;
|
|
29
|
+
const ARROW = '→';
|
|
30
|
+
/** The text with every value a failed statement quotes replaced by `[redacted]`. */
|
|
31
|
+
export function withoutQuotedValues(text) {
|
|
32
|
+
const redacted = QUOTED_VALUES.reduce((current, [form, replacement]) => current.replace(form, replacement), text);
|
|
33
|
+
return withoutPrismaArguments(redacted);
|
|
34
|
+
}
|
|
35
|
+
/*
|
|
36
|
+
* Prisma writes the call it refused, the code around it, then the arguments of the call with their
|
|
37
|
+
* values after the line of the arrow (right after the call when it has no code to show), and the
|
|
38
|
+
* reason, which is not indented.
|
|
39
|
+
*/
|
|
40
|
+
function withoutPrismaArguments(text) {
|
|
41
|
+
const lines = text.replace(COLOUR, '').split('\n');
|
|
42
|
+
const invocation = lines.findIndex((line) => PRISMA_CALL.test(line));
|
|
43
|
+
if (invocation === -1) {
|
|
44
|
+
return text;
|
|
45
|
+
}
|
|
46
|
+
const arrow = lines.findIndex((line) => line.startsWith(ARROW));
|
|
47
|
+
const from = arrow === -1 ? invocation : arrow;
|
|
48
|
+
return lines
|
|
49
|
+
.map((line, index) => (index > from ? line.replace(PRISMA_ARGUMENT, `$1${REDACTED}$2`) : line))
|
|
50
|
+
.join('\n');
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=without-quoted-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"without-quoted-values.js","sourceRoot":"","sources":["../../src/scrubbing/without-quoted-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,aAAa,GAA2D;IAC5E,gGAAgG;IAChG,CAAC,6CAA6C,EAAE,KAAK,QAAQ,EAAE,CAAC;IAChE,uGAAuG;IACvG;QACE,4GA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AM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC;IAE/C,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC9F,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/sentry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.106.0",
|
|
4
4
|
"description": "Error reporting to Sentry or GlitchTip behind the kernel ErrorReporter port: unexpected failures only, correlated with traces, scrubbed before sending.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ddd",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"type": "module",
|
|
29
29
|
"sideEffects": false,
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22.12.0"
|
|
32
|
+
},
|
|
30
33
|
"exports": {
|
|
31
34
|
".": {
|
|
32
35
|
"types": "./dist/index.d.ts",
|
|
@@ -37,12 +40,12 @@
|
|
|
37
40
|
"dist"
|
|
38
41
|
],
|
|
39
42
|
"dependencies": {
|
|
40
|
-
"@ddd-ts-kit/kernel": "0.
|
|
43
|
+
"@ddd-ts-kit/kernel": "0.106.0"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
|
-
"@ddd-ts-kit/di": "0.
|
|
44
|
-
"@ddd-ts-kit/http": "0.
|
|
45
|
-
"@ddd-ts-kit/tracing": "0.
|
|
46
|
+
"@ddd-ts-kit/di": "0.106.0",
|
|
47
|
+
"@ddd-ts-kit/http": "0.106.0",
|
|
48
|
+
"@ddd-ts-kit/tracing": "0.106.0",
|
|
46
49
|
"@opentelemetry/api": "^1.10.0",
|
|
47
50
|
"@opentelemetry/sdk-trace": "^3.0.0",
|
|
48
51
|
"@sentry/node": "^11.9.0"
|