@ddd-ts-kit/sentry 0.0.0-stage → 0.1.1
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.md +229 -2
- package/dist/event/active-trace.d.ts +10 -0
- package/dist/event/active-trace.d.ts.map +1 -0
- package/dist/event/active-trace.js +13 -0
- package/dist/event/active-trace.js.map +1 -0
- package/dist/event/fingerprint-of.d.ts +9 -0
- package/dist/event/fingerprint-of.d.ts.map +1 -0
- package/dist/event/fingerprint-of.js +29 -0
- package/dist/event/fingerprint-of.js.map +1 -0
- package/dist/event/frame-origin.d.ts +7 -0
- package/dist/event/frame-origin.d.ts.map +1 -0
- package/dist/event/frame-origin.js +61 -0
- package/dist/event/frame-origin.js.map +1 -0
- package/dist/event/tags-of.d.ts +4 -0
- package/dist/event/tags-of.d.ts.map +1 -0
- package/dist/event/tags-of.js +12 -0
- package/dist/event/tags-of.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/init-sentry-options.d.ts +33 -0
- package/dist/init-sentry-options.d.ts.map +1 -0
- package/dist/init-sentry-options.js +2 -0
- package/dist/init-sentry-options.js.map +1 -0
- package/dist/init-sentry.d.ts +12 -0
- package/dist/init-sentry.d.ts.map +1 -0
- package/dist/init-sentry.js +62 -0
- package/dist/init-sentry.js.map +1 -0
- package/dist/scrubbing/scrub-event.d.ts +14 -0
- package/dist/scrubbing/scrub-event.d.ts.map +1 -0
- package/dist/scrubbing/scrub-event.js +46 -0
- package/dist/scrubbing/scrub-event.js.map +1 -0
- package/dist/scrubbing/scrub-request.d.ts +8 -0
- package/dist/scrubbing/scrub-request.d.ts.map +1 -0
- package/dist/scrubbing/scrub-request.js +18 -0
- package/dist/scrubbing/scrub-request.js.map +1 -0
- package/dist/secrecy/conceal.d.ts +8 -0
- package/dist/secrecy/conceal.d.ts.map +1 -0
- package/dist/secrecy/conceal.js +12 -0
- package/dist/secrecy/conceal.js.map +1 -0
- package/dist/sentry-error-reporter.d.ts +27 -0
- package/dist/sentry-error-reporter.d.ts.map +1 -0
- package/dist/sentry-error-reporter.js +74 -0
- package/dist/sentry-error-reporter.js.map +1 -0
- package/package.json +41 -4
package/README.md
CHANGED
|
@@ -1,3 +1,230 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ddd-ts-kit/sentry
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The kernel `ErrorReporter` on Sentry or on GlitchTip, which speaks the same protocol: one adapter,
|
|
4
|
+
only the DSN differs. Unexpected failures only, each one leading to its trace, scrubbed before it
|
|
5
|
+
leaves the process. Nothing in `domain/` or `application/` imports this package, or reports
|
|
6
|
+
anything: handlers throw, and what stands around them reports.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm i @ddd-ts-kit/sentry @sentry/node @opentelemetry/api
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Written against `@sentry/node` 11: the options it relies on (`enableOpenTelemetrySetup`,
|
|
13
|
+
`dataCollection`) do not exist in earlier majors.
|
|
14
|
+
|
|
15
|
+
## Composition root
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// platform/errors.ts: imported second, right after platform/tracing.ts
|
|
19
|
+
import { reportProcessFailures } from '@ddd-ts-kit/kernel';
|
|
20
|
+
import { initSentry } from '@ddd-ts-kit/sentry';
|
|
21
|
+
import { loadConfig } from '@/platform/config/load-config.js';
|
|
22
|
+
|
|
23
|
+
// { dsn?, environment, release?, scrubMessages } of the validated configuration.
|
|
24
|
+
// Without a DSN nothing starts and nothing is reported.
|
|
25
|
+
export const errors = initSentry(loadConfig(process.env).errorReporting);
|
|
26
|
+
|
|
27
|
+
reportProcessFailures(errors); // uncaughtException and unhandledRejection: reported, then exit 1
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// main.ts
|
|
32
|
+
import { tracing } from '@/platform/tracing.js'; // first
|
|
33
|
+
import { errors } from '@/platform/errors.js'; // second
|
|
34
|
+
import { DeadLetterReports } from '@ddd-ts-kit/kernel';
|
|
35
|
+
import { createApplication, kernelModule } from '@ddd-ts-kit/di';
|
|
36
|
+
import { reportHttpErrors } from '@ddd-ts-kit/http';
|
|
37
|
+
|
|
38
|
+
const deadLetters = new DeadLetterReports(errors);
|
|
39
|
+
const bus = new RabbitMqEventBus({ url, onFailure: (failure) => deadLetters.onFailure(failure) });
|
|
40
|
+
|
|
41
|
+
const app = createApplication({
|
|
42
|
+
modules: [
|
|
43
|
+
kernelModule({
|
|
44
|
+
errorReporter: errors, // buses and jobs report through it, app.stop() flushes it
|
|
45
|
+
eventBus: bus,
|
|
46
|
+
eventSubscribers: { forContext: (name) => deadLetters.observing(bus.forConsumer(name)) },
|
|
47
|
+
}),
|
|
48
|
+
...contexts,
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const http = { onError: reportHttpErrors(errors), executionScope: app.resolve(ExecutionScope) };
|
|
53
|
+
|
|
54
|
+
process.on('SIGTERM', () => void app.stop().then(() => tracing.shutdown()));
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Three lines carry it: `initSentry`, `errorReporter: errors`, `onError: reportHttpErrors(errors)`.
|
|
58
|
+
The process handlers and the dead letters are one line each, for who wants them.
|
|
59
|
+
|
|
60
|
+
`init --errors sentry` writes exactly these pieces, each in its file: `platform/errors.ts` as
|
|
61
|
+
above, with `SENTRY_DSN`, `SENTRY_ENVIRONMENT` (default: `NODE_ENV`), `SENTRY_RELEASE` and
|
|
62
|
+
`SENTRY_SCRUB_MESSAGES` read by `platform/config/load-config.ts`; `errors` handed by `main.ts`
|
|
63
|
+
to `composeApplication`, which gives it to `kernelModule({ errorReporter })`;
|
|
64
|
+
`reportHttpErrors` in `platform/auth/http-boundary.ts`; `DeadLetterReports` in
|
|
65
|
+
`platform/events/create-event-provider.ts` (the broker) and in
|
|
66
|
+
`platform/events/start-outbox-relay.ts` (a publication declared dead).
|
|
67
|
+
|
|
68
|
+
**Load order.** `platform/tracing.ts` stays the first import: OpenTelemetry patches `http` and
|
|
69
|
+
the drivers when they are loaded, so it must run before them. `initSentry` patches nothing, so
|
|
70
|
+
its place changes nothing for tracing, whichever of the two starts first (both orders are
|
|
71
|
+
tested). It goes second so that a failure while the rest of the application loads is already
|
|
72
|
+
reported by `reportProcessFailures`.
|
|
73
|
+
|
|
74
|
+
## What is reported
|
|
75
|
+
|
|
76
|
+
Only what nobody planned. A `DomainError` is a business refusal, an answer and not an incident.
|
|
77
|
+
|
|
78
|
+
| Capture point | Attached by | Reports | Does not report |
|
|
79
|
+
|---|---|---|---|
|
|
80
|
+
| command and query buses | `kernelModule` (the default buses carry `errorReportingMiddleware`) | a command or a query that fails with anything but a `DomainError` | a `DomainError`; anything while an event is consumed |
|
|
81
|
+
| HTTP | `onError: reportHttpErrors(errors)` | every request answered 5xx, a `DomainError` mapped to a 5xx included | a 4xx |
|
|
82
|
+
| scheduled jobs | `kernelModule` (the default scheduler observes with `reportFailedRuns`) | a run whose outcome is `failed`, timeouts included | a `DomainError`, a skipped or missed occurrence |
|
|
83
|
+
| integration events | `DeadLetterReports` on the `onFailure` hook of the provider | an event given up: retries exhausted, poison message, publication of the outbox relay declared dead | a delivery that fails and is retried |
|
|
84
|
+
| process | `reportProcessFailures(errors)` | `uncaughtException` and `unhandledRejection`, as `fatal` | |
|
|
85
|
+
|
|
86
|
+
**One failure, one report.** The first capture point that sees an error object reports it and
|
|
87
|
+
marks it; the boundaries it crosses afterwards recognise it, also as the `cause` of an error
|
|
88
|
+
that wraps it. A command that fails inside a request is therefore reported once, by the bus,
|
|
89
|
+
under the name of the command, and the route that answers 500 stays silent. The report still
|
|
90
|
+
says where it came from: `origin` is the origin of the execution context (`http`, `schedule`),
|
|
91
|
+
and the correlation id and the trace lead to the request.
|
|
92
|
+
|
|
93
|
+
**Events.** A consumer is retried: its first failures are expected, and reporting them would
|
|
94
|
+
bury the real incidents. The bus middleware therefore says nothing while an event is consumed,
|
|
95
|
+
and `DeadLetterReports` reports the event once its provider gives it up. The hooks of the
|
|
96
|
+
providers say codes only, so `observing(subscriber)` remembers what each handler threw: the
|
|
97
|
+
report carries the real error and its stack. Without it, or for a poison message, the report
|
|
98
|
+
is a `DeadLetterError` naming the code. An event buried by a `DomainError` is reported as a
|
|
99
|
+
`warning`: it is lost to its consumer all the same.
|
|
100
|
+
|
|
101
|
+
## With OpenTelemetry
|
|
102
|
+
|
|
103
|
+
`@ddd-ts-kit/tracing` owns the tracer provider, the context manager, the propagator and the
|
|
104
|
+
auto-instrumentations. `initSentry` leaves all of them alone:
|
|
105
|
+
|
|
106
|
+
- `enableOpenTelemetrySetup: false`: the SDK registers no tracer provider and no propagator;
|
|
107
|
+
- none of the SDK's default integrations, and `enableRuntimeChannelInjection: false`: no second
|
|
108
|
+
instrumentation of `http` or of a driver;
|
|
109
|
+
- no `tracesSampleRate` unless given: no performance data goes to the tracker.
|
|
110
|
+
|
|
111
|
+
What links the two is one read: when a failure is reported, the reporter takes the trace id and
|
|
112
|
+
the span id of the active OpenTelemetry span and puts them in `contexts.trace` of the event.
|
|
113
|
+
From an issue in Sentry or GlitchTip, the trace id opens the trace in the tracing backend. The
|
|
114
|
+
spans themselves are exported once, by the exporter of the kit.
|
|
115
|
+
|
|
116
|
+
## Privacy
|
|
117
|
+
|
|
118
|
+
| | Default | Opt in |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| request | never collected. If something else adds one: method, URL without query string, headers that carry neither a credential nor an address. No body, no cookie | a project `beforeSend` |
|
|
121
|
+
| user | the actor id, nothing else: no email, no name, no address | |
|
|
122
|
+
| tenant | not sent | `tagTenant: true` |
|
|
123
|
+
| local variables | never | |
|
|
124
|
+
| breadcrumbs | none is recorded automatically: no console, no outgoing call | `Sentry.addBreadcrumb` where the project decides |
|
|
125
|
+
| exception message | sent | `scrubMessages: true` removes it for every error that is not a `DomainError` |
|
|
126
|
+
|
|
127
|
+
**Messages.** The message is the first thing read in an error tracker, and the first place
|
|
128
|
+
where personal data leaks: a driver quotes the row it refused. The default keeps it, because an
|
|
129
|
+
issue titled `[message removed]` costs every investigation, and because the tracker is an
|
|
130
|
+
internal tool whose access and retention the project controls. With `scrubMessages: true` only
|
|
131
|
+
the messages the project wrote itself survive, those of its `DomainError`s; type, code, stack
|
|
132
|
+
and trace remain for the others. Turn it on when the tracker is hosted by a third party or
|
|
133
|
+
when the data is sensitive enough that no operator should read it there. The loggers of the
|
|
134
|
+
kit (`StdoutLogger`, `@ddd-ts-kit/pino`, `@ddd-ts-kit/winston`) take the option under the same
|
|
135
|
+
name, with the same rule and the same marker, `SCRUBBED_MESSAGE` of the kernel.
|
|
136
|
+
|
|
137
|
+
`beforeSend` runs last, on the scrubbed event, and may drop it by answering `null`.
|
|
138
|
+
|
|
139
|
+
The DSN stays inside the SDK client. A `SentryErrorReporter` that is logged, spread or
|
|
140
|
+
serialised shows `SentryErrorReporter [client concealed]`; the client of the SDK, if you log
|
|
141
|
+
it yourself, shows its options.
|
|
142
|
+
|
|
143
|
+
## Grouping and tags
|
|
144
|
+
|
|
145
|
+
The fingerprint never contains the message, so identifiers in a message do not turn one problem
|
|
146
|
+
into thousands of issues: a `DomainError` is its class and its code; any other error is its
|
|
147
|
+
class, its code when it has one, and the function and file of its first frame, without line
|
|
148
|
+
numbers.
|
|
149
|
+
|
|
150
|
+
Tags: `origin`, `operation`, `correlation_id`, `bounded_context`, `error_code`, and `tenant_id`
|
|
151
|
+
on request. The fields a project adds to `ErrorReportExtensions` are sent as the `report`
|
|
152
|
+
context.
|
|
153
|
+
|
|
154
|
+
## Options
|
|
155
|
+
|
|
156
|
+
| Option | Default | |
|
|
157
|
+
|---|---|---|
|
|
158
|
+
| `dsn` | none | without it `initSentry` answers a `NoopErrorReporter` and starts nothing. `SENTRY_DSN` is not read behind the configuration |
|
|
159
|
+
| `environment`, `release` | none | |
|
|
160
|
+
| `enabled` | `true` | `false` reports nothing, whatever the DSN |
|
|
161
|
+
| `sampleRate` | 1 | share of the error events sent |
|
|
162
|
+
| `tracesSampleRate` | none | only for spans started through the Sentry API; the spans of the kit never go there |
|
|
163
|
+
| `scrubMessages` | `false` | see "Privacy" |
|
|
164
|
+
| `tagTenant` | `false` | |
|
|
165
|
+
| `beforeSend` | none | runs after the scrubber of the kit |
|
|
166
|
+
| `integrations` | none | added to linked errors and source context lines |
|
|
167
|
+
|
|
168
|
+
`flush(timeoutMs)` answers `true` when nothing is left to send. `app.stop()` calls it with two
|
|
169
|
+
seconds; `reportProcessFailures` does before exiting.
|
|
170
|
+
|
|
171
|
+
## GlitchTip for development
|
|
172
|
+
|
|
173
|
+
GlitchTip 6 runs as one service next to its PostgreSQL (14 or later) and, recommended by its
|
|
174
|
+
documentation, Valkey. The development image bootstraps a user, an organization and a project
|
|
175
|
+
and prints the DSN:
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
services:
|
|
179
|
+
glitchtip:
|
|
180
|
+
image: glitchtip/glitchtip:6.2.6
|
|
181
|
+
profiles: [errors]
|
|
182
|
+
depends_on:
|
|
183
|
+
glitchtip-postgres: { condition: service_healthy }
|
|
184
|
+
glitchtip-valkey: { condition: service_started }
|
|
185
|
+
ports: ['127.0.0.1:8000:8000']
|
|
186
|
+
environment:
|
|
187
|
+
SERVER_ROLE: all_in_one # web and worker in one process
|
|
188
|
+
DATABASE_URL: postgres://postgres:postgres@glitchtip-postgres:5432/glitchtip
|
|
189
|
+
VALKEY_URL: redis://glitchtip-valkey:6379
|
|
190
|
+
SECRET_KEY: local-development-only-not-a-secret # never in production: openssl rand -hex 32
|
|
191
|
+
GLITCHTIP_DOMAIN: http://localhost:8000
|
|
192
|
+
EMAIL_URL: consolemail://
|
|
193
|
+
DEFAULT_FROM_EMAIL: glitchtip@localhost
|
|
194
|
+
DEBUG: 'true' # development only: required by the bootstrap below
|
|
195
|
+
GLITCHTIP_BOOTSTRAP_DEV: 'true' # user test@example.com / admin_pass, organization, project, DSN
|
|
196
|
+
healthcheck:
|
|
197
|
+
test: [CMD, python, healthcheck.py]
|
|
198
|
+
interval: 10s
|
|
199
|
+
timeout: 6s
|
|
200
|
+
retries: 6
|
|
201
|
+
start_period: 180s # the first start migrates the database
|
|
202
|
+
glitchtip-postgres:
|
|
203
|
+
image: postgres:18-alpine
|
|
204
|
+
profiles: [errors]
|
|
205
|
+
environment: { POSTGRES_DB: glitchtip, POSTGRES_PASSWORD: postgres }
|
|
206
|
+
volumes: ['glitchtip-postgres:/var/lib/postgresql']
|
|
207
|
+
healthcheck:
|
|
208
|
+
test: [CMD-SHELL, pg_isready -U postgres -d glitchtip]
|
|
209
|
+
interval: 5s
|
|
210
|
+
retries: 12
|
|
211
|
+
glitchtip-valkey:
|
|
212
|
+
image: valkey/valkey:9-alpine
|
|
213
|
+
profiles: [errors]
|
|
214
|
+
|
|
215
|
+
volumes:
|
|
216
|
+
glitchtip-postgres:
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
docker compose --profile errors up -d --wait
|
|
221
|
+
docker compose logs glitchtip | grep 'DSN:'
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Put the DSN in `SENTRY_DSN`; from another container of the stack, replace `localhost` with
|
|
225
|
+
`glitchtip`. Sign in at http://localhost:8000 with the user above.
|
|
226
|
+
|
|
227
|
+
## In a test
|
|
228
|
+
|
|
229
|
+
Nothing of this package: the test application binds `InMemoryErrorReporter`, and
|
|
230
|
+
`app.errors.reports` lists what the buses and the jobs reported, as data.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ActiveTrace {
|
|
2
|
+
readonly traceId: string;
|
|
3
|
+
readonly spanId?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The trace an event belongs to: the active OpenTelemetry span when there is one, whoever
|
|
7
|
+
* owns the tracer provider, else the trace id the capture point knew.
|
|
8
|
+
*/
|
|
9
|
+
export declare function activeTrace(reportedTraceId: string | undefined): ActiveTrace | undefined;
|
|
10
|
+
//# sourceMappingURL=active-trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-trace.d.ts","sourceRoot":"","sources":["../../src/event/active-trace.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAQxF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isSpanContextValid, trace } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* The trace an event belongs to: the active OpenTelemetry span when there is one, whoever
|
|
4
|
+
* owns the tracer provider, else the trace id the capture point knew.
|
|
5
|
+
*/
|
|
6
|
+
export function activeTrace(reportedTraceId) {
|
|
7
|
+
const spanContext = trace.getActiveSpan()?.spanContext();
|
|
8
|
+
if (spanContext !== undefined && isSpanContextValid(spanContext)) {
|
|
9
|
+
return { traceId: spanContext.traceId, spanId: spanContext.spanId };
|
|
10
|
+
}
|
|
11
|
+
return reportedTraceId === undefined ? undefined : { traceId: reportedTraceId };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=active-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-trace.js","sourceRoot":"","sources":["../../src/event/active-trace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAO/D;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,eAAmC;IAC7D,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC;IAEzD,IAAI,WAAW,KAAK,SAAS,IAAI,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC;IACtE,CAAC;IAED,OAAO,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ErrorReport } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/**
|
|
3
|
+
* What makes two events the same problem. Never the message: it quotes identifiers, and one
|
|
4
|
+
* problem would become thousands of issues. A `DomainError` is its class and its code. Any
|
|
5
|
+
* other error is its class, its code when it has one, and where it was raised: the function
|
|
6
|
+
* and the file of the first frame, without line numbers, which move at every release.
|
|
7
|
+
*/
|
|
8
|
+
export declare function fingerprintOf(error: unknown, report: ErrorReport): string[];
|
|
9
|
+
//# sourceMappingURL=fingerprint-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint-of.d.ts","sourceRoot":"","sources":["../../src/event/fingerprint-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGnE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,CAS3E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DomainError } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { frameOrigin } from './frame-origin.js';
|
|
3
|
+
/**
|
|
4
|
+
* What makes two events the same problem. Never the message: it quotes identifiers, and one
|
|
5
|
+
* problem would become thousands of issues. A `DomainError` is its class and its code. Any
|
|
6
|
+
* other error is its class, its code when it has one, and where it was raised: the function
|
|
7
|
+
* and the file of the first frame, without line numbers, which move at every release.
|
|
8
|
+
*/
|
|
9
|
+
export function fingerprintOf(error, report) {
|
|
10
|
+
const type = error instanceof Error ? error.constructor.name : typeof error;
|
|
11
|
+
const code = report.errorCode === undefined ? [] : [report.errorCode];
|
|
12
|
+
if (error instanceof DomainError) {
|
|
13
|
+
return [type, ...code];
|
|
14
|
+
}
|
|
15
|
+
return [type, ...code, ...raisedAt(error)];
|
|
16
|
+
}
|
|
17
|
+
function raisedAt(error) {
|
|
18
|
+
if (!(error instanceof Error) || error.stack === undefined) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
for (const line of error.stack.split('\n')) {
|
|
22
|
+
const origin = frameOrigin(line);
|
|
23
|
+
if (origin !== undefined) {
|
|
24
|
+
return [origin];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=fingerprint-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint-of.js","sourceRoot":"","sources":["../../src/event/fingerprint-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,MAAmB;IAC/D,MAAM,IAAI,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC;IAC5E,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAEtE,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC3D,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QAEjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The function and the file of a stack frame, `at <function> (<directory>/<file>:<line>:<column>)`
|
|
3
|
+
* where the function and the directory are optional; undefined for any other line. Read by hand:
|
|
4
|
+
* a stack is as long as the code that raised wants it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function frameOrigin(line: string): string | undefined;
|
|
7
|
+
//# sourceMappingURL=frame-origin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-origin.d.ts","sourceRoot":"","sources":["../../src/event/frame-origin.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAmB5D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const AT = 'at ';
|
|
2
|
+
const ASYNC = 'async ';
|
|
3
|
+
const NOT_IN_A_FILE_NAME = '/\\:()';
|
|
4
|
+
const LINE_BREAK = /[\r\u2028\u2029]/;
|
|
5
|
+
/**
|
|
6
|
+
* The function and the file of a stack frame, `at <function> (<directory>/<file>:<line>:<column>)`
|
|
7
|
+
* where the function and the directory are optional; undefined for any other line. Read by hand:
|
|
8
|
+
* a stack is as long as the code that raised wants it.
|
|
9
|
+
*/
|
|
10
|
+
export function frameOrigin(line) {
|
|
11
|
+
const text = line.trimStart();
|
|
12
|
+
const frame = text.startsWith(AT) ? withoutPosition(text.slice(AT.length)) : undefined;
|
|
13
|
+
if (frame === undefined) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const readings = frame.startsWith(ASYNC) ? [frame.slice(ASYNC.length), frame] : [frame];
|
|
17
|
+
for (const reading of readings) {
|
|
18
|
+
const origin = originOf(reading);
|
|
19
|
+
if (origin !== undefined) {
|
|
20
|
+
return origin;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The frame without `:<line>:<column>` and the parenthesis that may close it. */
|
|
26
|
+
function withoutPosition(frame) {
|
|
27
|
+
const column = numberStart(frame, frame.endsWith(')') ? frame.length - 1 : frame.length);
|
|
28
|
+
const line = column === undefined ? undefined : numberStart(frame, column - 1);
|
|
29
|
+
return line === undefined ? undefined : frame.slice(0, line - 1);
|
|
30
|
+
}
|
|
31
|
+
/** Where the digits that end at `end` start, when a colon precedes them. */
|
|
32
|
+
function numberStart(text, end) {
|
|
33
|
+
let start = end;
|
|
34
|
+
while (start > 0 && text.charAt(start - 1) >= '0' && text.charAt(start - 1) <= '9') {
|
|
35
|
+
start -= 1;
|
|
36
|
+
}
|
|
37
|
+
return start < end && text.charAt(start - 1) === ':' ? start : undefined;
|
|
38
|
+
}
|
|
39
|
+
function originOf(located) {
|
|
40
|
+
let start = located.length;
|
|
41
|
+
while (start > 0 && !NOT_IN_A_FILE_NAME.includes(located.charAt(start - 1))) {
|
|
42
|
+
start -= 1;
|
|
43
|
+
}
|
|
44
|
+
const named = start === located.length ? undefined : functionOf(located.slice(0, start));
|
|
45
|
+
return named === undefined ? undefined : [...named, located.slice(start)].join(' ');
|
|
46
|
+
}
|
|
47
|
+
/** The function named before the file: none, one, or undefined when the text is not the start of a frame. */
|
|
48
|
+
function functionOf(head) {
|
|
49
|
+
if (head === '') {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
if (LINE_BREAK.test(head)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (head.endsWith('/') || head.endsWith('\\')) {
|
|
56
|
+
const open = head.indexOf(' (', 1);
|
|
57
|
+
return open === -1 ? [] : [head.slice(0, open)];
|
|
58
|
+
}
|
|
59
|
+
return head.endsWith(' (') && head.length > 2 ? [head.slice(0, -2)] : undefined;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=frame-origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-origin.js","sourceRoot":"","sources":["../../src/event/frame-origin.ts"],"names":[],"mappings":"AAAA,MAAM,EAAE,GAAG,KAAK,CAAC;AACjB,MAAM,KAAK,GAAG,QAAQ,CAAC;AACvB,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AACpC,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEvF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAExF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ErrorReport } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/** The tags an issue is searched by. The tenant only when the project asked for it. */
|
|
3
|
+
export declare function tagsOf(report: ErrorReport, tagTenant: boolean): Record<string, string>;
|
|
4
|
+
//# sourceMappingURL=tags-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags-of.d.ts","sourceRoot":"","sources":["../../src/event/tags-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,uFAAuF;AACvF,wBAAgB,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAStF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The tags an issue is searched by. The tenant only when the project asked for it. */
|
|
2
|
+
export function tagsOf(report, tagTenant) {
|
|
3
|
+
return {
|
|
4
|
+
origin: report.origin,
|
|
5
|
+
operation: report.operation,
|
|
6
|
+
...(report.correlationId === undefined ? {} : { correlation_id: report.correlationId }),
|
|
7
|
+
...(report.context === undefined ? {} : { bounded_context: report.context }),
|
|
8
|
+
...(report.errorCode === undefined ? {} : { error_code: report.errorCode }),
|
|
9
|
+
...(tagTenant && report.tenantId !== undefined ? { tenant_id: report.tenantId } : {}),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=tags-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags-of.js","sourceRoot":"","sources":["../../src/event/tags-of.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,MAAM,UAAU,MAAM,CAAC,MAAmB,EAAE,SAAkB;IAC5D,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,GAAG,CAAC,MAAM,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;QACvF,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;QAC5E,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;QAC3E,GAAG,CAAC,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { initSentry } from './init-sentry.js';
|
|
2
|
+
export type { InitSentryOptions } from './init-sentry-options.js';
|
|
3
|
+
export { scrubEvent, type ScrubOptions } from './scrubbing/scrub-event.js';
|
|
4
|
+
export { scrubRequest } from './scrubbing/scrub-request.js';
|
|
5
|
+
export { SentryErrorReporter, type SentryErrorReporterOptions } from './sentry-error-reporter.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,KAAK,0BAA0B,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { initSentry } from './init-sentry.js';
|
|
2
|
+
export { scrubEvent } from './scrubbing/scrub-event.js';
|
|
3
|
+
export { scrubRequest } from './scrubbing/scrub-request.js';
|
|
4
|
+
export { SentryErrorReporter } from './sentry-error-reporter.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAqB,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAmC,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ErrorEvent, EventHint, NodeOptions } from '@sentry/node';
|
|
2
|
+
export interface InitSentryOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Where the events go: a Sentry or a GlitchTip project. Without it, or empty, nothing is
|
|
5
|
+
* initialised and the answer reports nothing, so a project starts with none configured.
|
|
6
|
+
* The `SENTRY_DSN` variable is not read behind the back of the configuration.
|
|
7
|
+
*/
|
|
8
|
+
readonly dsn?: string;
|
|
9
|
+
readonly environment?: string;
|
|
10
|
+
readonly release?: string;
|
|
11
|
+
/** `false` reports nothing, whatever the DSN. Default `true`. */
|
|
12
|
+
readonly enabled?: boolean;
|
|
13
|
+
/** Share of the error events sent, 0 to 1. Default 1. */
|
|
14
|
+
readonly sampleRate?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Share of the spans started through the Sentry API that are sent as performance data.
|
|
17
|
+
* Default: none. The spans of `@ddd-ts-kit/tracing` never go there: they belong to the
|
|
18
|
+
* tracing backend, and an event leads to them by its trace id.
|
|
19
|
+
*/
|
|
20
|
+
readonly tracesSampleRate?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Replaces the message of every error that is not a `DomainError` before it leaves the
|
|
23
|
+
* process. Default `false`: see "Privacy" in the README for the trade-off.
|
|
24
|
+
*/
|
|
25
|
+
readonly scrubMessages?: boolean;
|
|
26
|
+
/** Tags every event with `tenant_id`. Default `false`. */
|
|
27
|
+
readonly tagTenant?: boolean;
|
|
28
|
+
/** Runs last, on the event the kit already scrubbed. Answer `null` to drop the event. */
|
|
29
|
+
readonly beforeSend?: (event: ErrorEvent, hint: EventHint) => ErrorEvent | null | PromiseLike<ErrorEvent | null>;
|
|
30
|
+
/** Added to the two the kit installs (linked errors, source context lines). None of the SDK defaults is installed. */
|
|
31
|
+
readonly integrations?: Extract<NodeOptions['integrations'], readonly unknown[]>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=init-sentry-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-sentry-options.d.ts","sourceRoot":"","sources":["../src/init-sentry-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEvE,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,yFAAyF;IACzF,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,KAAK,UAAU,GAAG,IAAI,GAAG,WAAW,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACjH,sHAAsH;IACtH,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC;CAClF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-sentry-options.js","sourceRoot":"","sources":["../src/init-sentry-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ErrorReporter } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { InitSentryOptions } from './init-sentry-options.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `ErrorReporter` of the application, on Sentry or GlitchTip. Without a DSN it reports
|
|
5
|
+
* nothing and the SDK is not started. With one, the SDK is started for errors only: none of
|
|
6
|
+
* its default integrations, so no instrumentation of `http` or of a driver, no console or
|
|
7
|
+
* request breadcrumbs, no handler of uncaught errors on the process, no local variables; no OpenTelemetry setup,
|
|
8
|
+
* so the tracer provider, the context manager and the propagator stay those of
|
|
9
|
+
* `@ddd-ts-kit/tracing`; no performance data unless `tracesSampleRate` is given.
|
|
10
|
+
*/
|
|
11
|
+
export declare function initSentry(options?: InitSentryOptions): ErrorReporter;
|
|
12
|
+
//# sourceMappingURL=init-sentry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-sentry.d.ts","sourceRoot":"","sources":["../src/init-sentry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAO3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAqBlE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,aAAa,CAUzE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { NoopErrorReporter } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { contextLinesIntegration, initWithoutDefaultIntegrations, linkedErrorsIntegration, } from '@sentry/node';
|
|
3
|
+
import { scrubEvent } from './scrubbing/scrub-event.js';
|
|
4
|
+
import { SentryErrorReporter } from './sentry-error-reporter.js';
|
|
5
|
+
/*
|
|
6
|
+
* The SDK collects all of this unless told not to (`dataCollection` replaced `sendDefaultPii`
|
|
7
|
+
* and defaults to collecting). Nothing here is on: the kit says what an event carries.
|
|
8
|
+
*/
|
|
9
|
+
const NOTHING_COLLECTED = {
|
|
10
|
+
userInfo: false,
|
|
11
|
+
cookies: false,
|
|
12
|
+
httpHeaders: false,
|
|
13
|
+
httpBodies: [],
|
|
14
|
+
urlQueryParams: false,
|
|
15
|
+
graphQL: { document: false, variables: false },
|
|
16
|
+
genAI: { inputs: false, outputs: false },
|
|
17
|
+
databaseQueryData: false,
|
|
18
|
+
queues: false,
|
|
19
|
+
stackFrameVariables: false,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The `ErrorReporter` of the application, on Sentry or GlitchTip. Without a DSN it reports
|
|
23
|
+
* nothing and the SDK is not started. With one, the SDK is started for errors only: none of
|
|
24
|
+
* its default integrations, so no instrumentation of `http` or of a driver, no console or
|
|
25
|
+
* request breadcrumbs, no handler of uncaught errors on the process, no local variables; no OpenTelemetry setup,
|
|
26
|
+
* so the tracer provider, the context manager and the propagator stay those of
|
|
27
|
+
* `@ddd-ts-kit/tracing`; no performance data unless `tracesSampleRate` is given.
|
|
28
|
+
*/
|
|
29
|
+
export function initSentry(options = {}) {
|
|
30
|
+
if (options.enabled === false || options.dsn === undefined || options.dsn === '') {
|
|
31
|
+
return new NoopErrorReporter();
|
|
32
|
+
}
|
|
33
|
+
const client = initWithoutDefaultIntegrations(sdkOptionsOf(options, options.dsn));
|
|
34
|
+
return client === undefined
|
|
35
|
+
? new NoopErrorReporter()
|
|
36
|
+
: new SentryErrorReporter(client, { tagTenant: options.tagTenant === true });
|
|
37
|
+
}
|
|
38
|
+
function sdkOptionsOf(options, dsn) {
|
|
39
|
+
const { environment, release, sampleRate, tracesSampleRate } = options;
|
|
40
|
+
return {
|
|
41
|
+
dsn,
|
|
42
|
+
...(environment === undefined ? {} : { environment }),
|
|
43
|
+
...(release === undefined ? {} : { release }),
|
|
44
|
+
...(sampleRate === undefined ? {} : { sampleRate }),
|
|
45
|
+
...(tracesSampleRate === undefined ? {} : { tracesSampleRate }),
|
|
46
|
+
integrations: [linkedErrorsIntegration(), contextLinesIntegration(), ...(options.integrations ?? [])],
|
|
47
|
+
enableOpenTelemetrySetup: false,
|
|
48
|
+
enableRuntimeChannelInjection: false,
|
|
49
|
+
includeLocalVariables: false,
|
|
50
|
+
sendClientReports: false,
|
|
51
|
+
dataCollection: NOTHING_COLLECTED,
|
|
52
|
+
beforeSend: beforeSendOf(options),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function beforeSendOf(options) {
|
|
56
|
+
const scrubbing = { scrubMessages: options.scrubMessages === true };
|
|
57
|
+
return (event, hint) => {
|
|
58
|
+
const scrubbed = scrubEvent(event, hint, scrubbing);
|
|
59
|
+
return options.beforeSend === undefined ? scrubbed : options.beforeSend(scrubbed, hint);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=init-sentry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-sentry.js","sourceRoot":"","sources":["../src/init-sentry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAsB,MAAM,oBAAoB,CAAC;AAC3E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{ ErrorEvent, EventHint } from '@sentry/node';
|
|
2
|
+
export interface ScrubOptions {
|
|
3
|
+
/** Replaces the message of every error that is not a `DomainError`. */
|
|
4
|
+
readonly scrubMessages: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
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. With
|
|
9
|
+
* `scrubMessages`, an exception keeps its message only when a `DomainError` of that class is
|
|
10
|
+
* in the chain of the reported error: those messages are written by the project, the others
|
|
11
|
+
* come from drivers and libraries and quote the data they choked on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function scrubEvent(event: ErrorEvent, hint: EventHint, options: ScrubOptions): ErrorEvent;
|
|
14
|
+
//# sourceMappingURL=scrub-event.d.ts.map
|
|
@@ -0,0 +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;AAG1D,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CACjC;AAID;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU,CAchG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DomainError, SCRUBBED_MESSAGE } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { scrubRequest } from './scrub-request.js';
|
|
3
|
+
const DEEPEST_CAUSE = 8;
|
|
4
|
+
/**
|
|
5
|
+
* 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. With
|
|
7
|
+
* `scrubMessages`, an exception keeps its message only when a `DomainError` of that class is
|
|
8
|
+
* in the chain of the reported error: those messages are written by the project, the others
|
|
9
|
+
* come from drivers and libraries and quote the data they choked on.
|
|
10
|
+
*/
|
|
11
|
+
export function scrubEvent(event, hint, options) {
|
|
12
|
+
if (event.request !== undefined) {
|
|
13
|
+
event.request = scrubRequest(event.request);
|
|
14
|
+
}
|
|
15
|
+
if (event.user !== undefined) {
|
|
16
|
+
event.user = event.user.id === undefined ? {} : { id: event.user.id };
|
|
17
|
+
}
|
|
18
|
+
if (options.scrubMessages) {
|
|
19
|
+
scrubMessages(event, domainErrorNames(hint.originalException, DEEPEST_CAUSE));
|
|
20
|
+
}
|
|
21
|
+
return event;
|
|
22
|
+
}
|
|
23
|
+
function domainErrorNames(error, depth) {
|
|
24
|
+
if (typeof error !== 'object' || error === null || depth === 0) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
return [
|
|
28
|
+
...(error instanceof DomainError ? [error.name, error.constructor.name] : []),
|
|
29
|
+
...innerErrors(error).flatMap((one) => domainErrorNames(one, depth - 1)),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
function innerErrors(error) {
|
|
33
|
+
const aggregated = error instanceof AggregateError ? error.errors : [];
|
|
34
|
+
return 'cause' in error ? [error.cause, ...aggregated] : aggregated;
|
|
35
|
+
}
|
|
36
|
+
function scrubMessages(event, kept) {
|
|
37
|
+
for (const exception of event.exception?.values ?? []) {
|
|
38
|
+
if (exception.type === undefined || !kept.includes(exception.type)) {
|
|
39
|
+
exception.value = SCRUBBED_MESSAGE;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (event.message !== undefined) {
|
|
43
|
+
event.message = SCRUBBED_MESSAGE;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=scrub-event.js.map
|
|
@@ -0,0 +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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,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,MAAM,UAAU,GAAc,KAAK,YAAY,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAElF,OAAO,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AACtE,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,8 @@
|
|
|
1
|
+
import type { RequestEventData } from '@sentry/node';
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the method, the URL without query string or fragment, and the headers that carry
|
|
4
|
+
* neither a credential nor the address of the caller. The body, the cookies, the query string
|
|
5
|
+
* and the environment are dropped.
|
|
6
|
+
*/
|
|
7
|
+
export declare function scrubRequest(request: RequestEventData): RequestEventData;
|
|
8
|
+
//# sourceMappingURL=scrub-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub-request.d.ts","sourceRoot":"","sources":["../../src/scrubbing/scrub-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAQxE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const CREDENTIAL_HEADER = /auth|cookie|token|secret|password|session|signature|api-?key|csrf|forwarded|real-ip|client-ip/i;
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the method, the URL without query string or fragment, and the headers that carry
|
|
4
|
+
* neither a credential nor the address of the caller. The body, the cookies, the query string
|
|
5
|
+
* and the environment are dropped.
|
|
6
|
+
*/
|
|
7
|
+
export function scrubRequest(request) {
|
|
8
|
+
const headers = Object.entries(request.headers ?? {}).filter(([name]) => !CREDENTIAL_HEADER.test(name));
|
|
9
|
+
return {
|
|
10
|
+
...(request.method === undefined ? {} : { method: request.method }),
|
|
11
|
+
...(request.url === undefined ? {} : { url: withoutQuery(request.url) }),
|
|
12
|
+
...(headers.length === 0 ? {} : { headers: Object.fromEntries(headers) }),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function withoutQuery(url) {
|
|
16
|
+
return url.replace(/[?#].*$/s, '');
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=scrub-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub-request.js","sourceRoot":"","sources":["../../src/scrubbing/scrub-request.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GACrB,gGAAgG,CAAC;AAEnG;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAyB;IACpD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAExG,OAAO;QACL,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QACnE,GAAG,CAAC,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACxE,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes the fields an instance holds so far out of enumeration: `Object.keys`, a spread and a
|
|
3
|
+
* comparison no longer reach the client or the connection behind them, whose options carry
|
|
4
|
+
* credentials. Called last in a constructor, next to a `toJSON` and an inspection method that
|
|
5
|
+
* answer a name: nothing the instance is shown through leads to what it holds.
|
|
6
|
+
*/
|
|
7
|
+
export declare function conceal(instance: object): void;
|
|
8
|
+
//# sourceMappingURL=conceal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conceal.d.ts","sourceRoot":"","sources":["../../src/secrecy/conceal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAI9C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes the fields an instance holds so far out of enumeration: `Object.keys`, a spread and a
|
|
3
|
+
* comparison no longer reach the client or the connection behind them, whose options carry
|
|
4
|
+
* credentials. Called last in a constructor, next to a `toJSON` and an inspection method that
|
|
5
|
+
* answer a name: nothing the instance is shown through leads to what it holds.
|
|
6
|
+
*/
|
|
7
|
+
export function conceal(instance) {
|
|
8
|
+
for (const field of Object.keys(instance)) {
|
|
9
|
+
Object.defineProperty(instance, field, { enumerable: false });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=conceal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conceal.js","sourceRoot":"","sources":["../../src/secrecy/conceal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,QAAgB;IACtC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import type { ErrorReport, ErrorReporter } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { type NodeClient } from '@sentry/node';
|
|
4
|
+
export interface SentryErrorReporterOptions {
|
|
5
|
+
/** Tags every event with `tenant_id`. Default `false`. */
|
|
6
|
+
readonly tagTenant?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Sends reports to Sentry, or to GlitchTip, which speaks the same protocol: only the DSN
|
|
10
|
+
* differs. Each report is an event of its own scope: the tags of the report, the actor id as
|
|
11
|
+
* the only thing known of the user, a fingerprint that ignores the message, and the trace of
|
|
12
|
+
* the active OpenTelemetry span, so the event leads to the trace in the tracing backend.
|
|
13
|
+
* `initSentry` builds it; build it yourself around a client you initialised.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SentryErrorReporter implements ErrorReporter {
|
|
16
|
+
private readonly client;
|
|
17
|
+
private readonly options;
|
|
18
|
+
constructor(client: NodeClient, options?: SentryErrorReporterOptions);
|
|
19
|
+
report(error: unknown, report: ErrorReport): void;
|
|
20
|
+
flush(timeoutMs: number): Promise<boolean>;
|
|
21
|
+
/** What a serialisation shows: a name, never the client, whose options carry the DSN. */
|
|
22
|
+
toJSON(): string;
|
|
23
|
+
/** What `console.log` and `util.inspect` show: the same. */
|
|
24
|
+
[inspect.custom](): string;
|
|
25
|
+
private scopeOf;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=sentry-error-reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry-error-reporter.d.ts","sourceRoot":"","sources":["../src/sentry-error-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAiB,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAS,KAAK,UAAU,EAAsB,MAAM,cAAc,CAAC;AAM1E,MAAM,WAAW,0BAA0B;IACzC,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAUD;;;;;;GAMG;AACH,qBAAa,mBAAoB,YAAW,aAAa;IAErD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF1B,YACmB,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,0BAA+B,EAG1D;IAED,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAUhD;IAEK,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAM/C;IAED,yFAAyF;IACzF,MAAM,IAAI,MAAM,CAEf;IAED,4DAA4D;IAC5D,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAEzB;IAED,OAAO,CAAC,OAAO;CA0BhB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import { Scope } from '@sentry/node';
|
|
3
|
+
import { activeTrace } from './event/active-trace.js';
|
|
4
|
+
import { fingerprintOf } from './event/fingerprint-of.js';
|
|
5
|
+
import { tagsOf } from './event/tags-of.js';
|
|
6
|
+
import { conceal } from './secrecy/conceal.js';
|
|
7
|
+
const LEVELS = {
|
|
8
|
+
fatal: 'fatal',
|
|
9
|
+
error: 'error',
|
|
10
|
+
warning: 'warning',
|
|
11
|
+
};
|
|
12
|
+
const DESCRIPTION = 'SentryErrorReporter [client concealed]';
|
|
13
|
+
/**
|
|
14
|
+
* Sends reports to Sentry, or to GlitchTip, which speaks the same protocol: only the DSN
|
|
15
|
+
* differs. Each report is an event of its own scope: the tags of the report, the actor id as
|
|
16
|
+
* the only thing known of the user, a fingerprint that ignores the message, and the trace of
|
|
17
|
+
* the active OpenTelemetry span, so the event leads to the trace in the tracing backend.
|
|
18
|
+
* `initSentry` builds it; build it yourself around a client you initialised.
|
|
19
|
+
*/
|
|
20
|
+
export class SentryErrorReporter {
|
|
21
|
+
client;
|
|
22
|
+
options;
|
|
23
|
+
constructor(client, options = {}) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
this.options = options;
|
|
26
|
+
conceal(this);
|
|
27
|
+
}
|
|
28
|
+
report(error, report) {
|
|
29
|
+
try {
|
|
30
|
+
this.client.captureException(error, { originalException: error, mechanism: { type: 'generic', handled: report.severity !== 'fatal' } }, this.scopeOf(error, report));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async flush(timeoutMs) {
|
|
37
|
+
try {
|
|
38
|
+
return await this.client.flush(timeoutMs);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** What a serialisation shows: a name, never the client, whose options carry the DSN. */
|
|
45
|
+
toJSON() {
|
|
46
|
+
return DESCRIPTION;
|
|
47
|
+
}
|
|
48
|
+
/** What `console.log` and `util.inspect` show: the same. */
|
|
49
|
+
[inspect.custom]() {
|
|
50
|
+
return DESCRIPTION;
|
|
51
|
+
}
|
|
52
|
+
scopeOf(error, report) {
|
|
53
|
+
const scope = new Scope();
|
|
54
|
+
const traced = activeTrace(report.traceId);
|
|
55
|
+
scope.setLevel(LEVELS[report.severity]);
|
|
56
|
+
scope.setTags(tagsOf(report, this.options.tagTenant === true));
|
|
57
|
+
scope.setFingerprint(fingerprintOf(error, report));
|
|
58
|
+
if (report.actorId !== undefined) {
|
|
59
|
+
scope.setUser({ id: report.actorId });
|
|
60
|
+
}
|
|
61
|
+
if (report.extensions !== undefined) {
|
|
62
|
+
scope.setContext('report', { ...report.extensions });
|
|
63
|
+
}
|
|
64
|
+
if (traced !== undefined) {
|
|
65
|
+
scope.setPropagationContext({
|
|
66
|
+
traceId: traced.traceId,
|
|
67
|
+
sampleRand: Math.random(),
|
|
68
|
+
...(traced.spanId === undefined ? {} : { propagationSpanId: traced.spanId }),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return scope;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=sentry-error-reporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry-error-reporter.js","sourceRoot":"","sources":["../src/sentry-error-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAuC,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAO/C,MAAM,MAAM,GAAmD;IAC7D,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,MAAM,WAAW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,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC;QAC/D,KAAK,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;QAEnD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACjC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,KAAK,CAAC,qBAAqB,CAAC;gBAC1B,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE;gBACzB,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;aAC7E,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/sentry",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Error reporting to Sentry or GlitchTip behind the kernel ErrorReporter port: unexpected failures only, correlated with traces, scrubbed before sending.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/gbourgeat/ddd-ts-kit.git",
|
|
9
|
+
"directory": "packages/sentry"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/gbourgeat/ddd-ts-kit/tree/main/packages/sentry#readme",
|
|
12
|
+
"bugs": "https://github.com/gbourgeat/ddd-ts-kit/issues",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"provenance": true
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@ddd-ts-kit/kernel": "0.1.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@ddd-ts-kit/di": "0.1.1",
|
|
33
|
+
"@ddd-ts-kit/http": "0.1.1",
|
|
34
|
+
"@ddd-ts-kit/tracing": "0.1.1",
|
|
35
|
+
"@opentelemetry/api": "^1.9.1",
|
|
36
|
+
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
37
|
+
"@sentry/node": "^11.6.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@opentelemetry/api": "^1.9.0",
|
|
41
|
+
"@sentry/node": "^11.6.0"
|
|
42
|
+
}
|
|
43
|
+
}
|