@nestjs/observe 0.3.11 → 0.3.13

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.
Files changed (39) hide show
  1. package/README.md +71 -2
  2. package/dist/agent/degraded-ingest.protocol.d.ts +87 -16
  3. package/dist/agent/degraded-ingest.protocol.js +62 -17
  4. package/dist/agent/detached-observe-worker.assembly.d.ts +1 -0
  5. package/dist/agent/detached-observe-worker.assembly.js +1 -0
  6. package/dist/agent/detached-observe-worker.d.ts +5 -0
  7. package/dist/agent/detached-observe-worker.js +129 -63
  8. package/dist/agent/observe-agent.shared-buffer.d.ts +54 -1
  9. package/dist/agent/observe-agent.shared-buffer.js +127 -22
  10. package/dist/agent/observe-agent.worker.d.ts +38 -1
  11. package/dist/agent/observe-agent.worker.js +134 -23
  12. package/dist/agent/telemetry-wire-contract.js +11 -1
  13. package/dist/encoders/request-snapshot.encoder.d.ts +1 -0
  14. package/dist/encoders/request-snapshot.encoder.js +1 -0
  15. package/dist/interfaces/observe-options.interface.d.ts +17 -2
  16. package/dist/interfaces/request-snapshot.interface.d.ts +13 -0
  17. package/dist/objectives/objectives.registry.d.ts +1 -0
  18. package/dist/objectives/objectives.registry.js +12 -0
  19. package/dist/outgoing/mssql.integration.d.ts +12 -0
  20. package/dist/outgoing/mssql.integration.js +248 -0
  21. package/dist/outgoing/mysql2.integration.js +1 -1
  22. package/dist/outgoing/outgoing-observe-agent.service.js +46 -8
  23. package/dist/outgoing/outgoing-span.recorder.d.ts +7 -0
  24. package/dist/outgoing/outgoing-span.recorder.js +15 -0
  25. package/dist/outgoing/pg.integration.js +1 -1
  26. package/dist/outgoing/sql-statement.util.d.ts +5 -1
  27. package/dist/outgoing/sql-statement.util.js +83 -10
  28. package/dist/protocols/http-observe-agent.service.js +9 -2
  29. package/dist/protocols/job-trace-runner.js +5 -0
  30. package/dist/services/node-runtime-metrics.service.js +1 -1
  31. package/dist/services/operation-trace.registry.d.ts +11 -0
  32. package/dist/services/operation-trace.registry.js +37 -1
  33. package/dist/services/stdout-forwarder.service.js +1 -1
  34. package/dist/services/trace-sampler.service.js +5 -0
  35. package/dist/services/tracer.service.d.ts +19 -0
  36. package/dist/services/tracer.service.js +61 -3
  37. package/dist/utils/ingest-refusal.util.d.ts +8 -3
  38. package/dist/utils/ingest-refusal.util.js +24 -3
  39. package/package.json +9 -4
package/README.md CHANGED
@@ -80,6 +80,28 @@ OBSERVE_APP_SECRET=...
80
80
  ```
81
81
 
82
82
  Without valid credentials the collector answers `401` and telemetry is dropped.
83
+ The agent says so once, then backs off - one flush interval, then two, then
84
+ four, up to one attempt an hour - until the credentials are fixed. They are
85
+ read at startup, so that takes a restart. Leave `appKey` or `appSecret` unset
86
+ and nothing is sent to the hosted collector at all, with a warning at startup
87
+ instead; a collector of your own at `endpoint` still receives batches without
88
+ them.
89
+
90
+ To keep an environment from reporting - local development, say - switch the
91
+ agent off rather than supplying fake credentials, which are sent and refused:
92
+
93
+ ```ts
94
+ ObserveModule.forRoot({
95
+ enabled: process.env.NODE_ENV === "production",
96
+ appKey: process.env.OBSERVE_APP_KEY ?? "",
97
+ appSecret: process.env.OBSERVE_APP_SECRET ?? "",
98
+ serviceId: "my-service",
99
+ });
100
+ ```
101
+
102
+ With `enabled: false` the module stays imported - `TracerService` still
103
+ resolves, and calling it is harmless - but nothing is recorded or sent, and the
104
+ only trace of it is one line at startup.
83
105
 
84
106
  ## Quick start
85
107
 
@@ -248,7 +270,7 @@ is told `protocol`, `operationId`, `method`, `statusCode`, `duration` and
248
270
  Once the module and the instrument are in place, the agent reports, with no further changes to your application:
249
271
 
250
272
  - **Requests, GraphQL operations, RPC messages, WebSocket gateway messages, queue jobs and scheduled jobs**, each with its tree of provider method calls.
251
- - **Database queries**, as a span under the method that ran them, for `pg`, `mysql2` and `mongodb`. Anything built on those drivers is covered without being known by name: TypeORM, Drizzle, MikroORM and Mongoose are tested in this repository, and others (Knex, Sequelize) go through the same driver calls. The statement is recorded with every value removed (`SELECT "o"."id" FROM "orders" "o" WHERE "o"."customer_id" = $1`). Prisma's Rust query engine does not go through these drivers and is not covered yet.
273
+ - **Database queries**, as a span under the method that ran them, for `pg`, `mysql2`, `mssql` and `mongodb`. Anything built on those drivers is covered without being known by name: TypeORM, Drizzle, MikroORM and Mongoose are tested in this repository, and others (Knex, Sequelize) go through the same driver calls. SQL Server is the exception: `mssql` is what TypeORM and Prisma's SQL Server adapter run on, but Knex, Sequelize and MikroORM talk to SQL Server through `tedious` directly, which is not covered yet (nor is `mssql/msnodesqlv8`). The statement is recorded with every value removed (`SELECT "o"."id" FROM "orders" "o" WHERE "o"."customer_id" = $1`). Prisma's Rust query engine does not go through these drivers and is not covered yet.
252
274
  - **Outbound HTTP calls** made with `fetch`/`undici` or `node:http`/`https` (so Axios too), as `POST api.stripe.com`. The current trace id is forwarded as `x-request-id` - by `fetch` on every supported Node version, by `node:http`/`https` from Node 22.12, the first to let a request's headers still be set at that point - so a service that also runs the agent continues the same trace; a header you set yourself is never overwritten.
253
275
  - **Trace ids across queues**: a BullMQ (Pro included) or Bull job enqueued while handling a request carries that request's trace id, so the request and its job show up as one trace. Repeatable (cron) jobs start their own.
254
276
  - **The code around an error's throw site**: for each in-app frame of a captured error, a few lines of source either side, read from the running process, so the dashboard shows the failing code next to the stack. This sends fragments of your application's source to Observe, stored with the error. Frames in `node_modules` and Node internals are never read. `createObserveModule({ sourceContext: false })` turns it off; the [documentation](https://www.observe.nestjs.com/documentation/sdk#error-source-context) covers tuning it instead.
@@ -281,6 +303,52 @@ ObserveModule.forRoot({
281
303
 
282
304
  A failed request is always captured (headers only, unless `body` is on); `capture: false` turns the feature off. Everything captured goes through the same redaction as error messages and logs before it leaves the process - sensitive keys by name, secrets by pattern - so naming `authorization` in `headers` records `[REDACTED]`.
283
305
 
306
+ ## Custom request operation IDs
307
+
308
+ HTTP requests are grouped by their route path by default. If you want to report
309
+ a different operation name for a request, inject `TracerService` and call
310
+ `setOperationId()` while the request is in flight - from the handler, or from a
311
+ guard, interceptor or middleware:
312
+
313
+ ```ts
314
+ import { TracerService } from "@nestjs/observe";
315
+
316
+ // Inject TracerService in your controller's constructor:
317
+ constructor(private readonly tracerService: TracerService) {}
318
+
319
+ // Choose any naming scheme that suits your application. `body.method` comes
320
+ // from the client, so name only the methods you serve:
321
+ const RPC_METHODS = new Set(["orders.list", "orders.create", "customers.get"]);
322
+
323
+ this.tracerService.setOperationId(
324
+ RPC_METHODS.has(body.method) ? `/rpc/${body.method}` : "/rpc/unknown",
325
+ );
326
+ ```
327
+
328
+ For example, an RPC handler could distinguish `orders.list` from `orders.create`,
329
+ even when both requests use the same route. This changes only the operation ID,
330
+ not the URL, HTTP method, tags, or spans. The name replaces the route or GraphQL
331
+ name; a later call replaces an earlier one.
332
+
333
+ The operation ID is an application-defined name; choose any scheme that fits
334
+ your use case. Use stable, bounded names rather than per-request values such as
335
+ user IDs or request IDs to avoid high-cardinality groups, and don't pass a
336
+ client-supplied value through unchecked: that lets any caller create new groups.
337
+ Names are trimmed and cut to 255 characters, and anything other than a non-blank
338
+ string is ignored. The method is a no-op outside an active trace and for ignored
339
+ or sampled-out requests.
340
+
341
+ Observe keeps up to 100 custom names per project in any 30 days. A request
342
+ renamed to a name past that is reported under the route it replaced, and a name
343
+ gives its place up once no request has used it for 30 days.
344
+
345
+ Everything keyed on the operation ID sees the new name: a drop filter on
346
+ `http.route` (one on `http.url` still matches the URL),
347
+ [`skipSpans`](#skipping-spans-for-expected-outcomes), alerts and SLOs. Rules
348
+ and history recorded under the old name don't carry over to the new one.
349
+ `@Objective()` is not declared for renamed requests: an SLO watches one route,
350
+ and each name is a route of its own.
351
+
284
352
  ## Declaring objectives in code
285
353
 
286
354
  `@Objective()` states what a route promises, next to the handler that has to keep it, and Observe turns each promise into an [SLO](https://www.observe.nestjs.com/documentation/slos). The objective is written, reviewed and versioned with the route it covers:
@@ -320,6 +388,7 @@ Every option, with its default. The [documentation](https://www.observe.nestjs.c
320
388
 
321
389
  | Option | Default | What it does |
322
390
  | ------------------------ | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
391
+ | `enabled` | `true` | `false` records and sends nothing, and needs no credentials - see [Getting credentials](#getting-credentials). |
323
392
  | `appKey`, `appSecret` | required | The credentials the dashboard issues - see [Getting credentials](#getting-credentials). |
324
393
  | `serviceId` | required | Names the service in the dashboard, in at most 100 characters - a longer one is cut to fit, with a warning at startup. |
325
394
  | `serviceVersion` | inferred | The release the process runs, at most 50 characters - see [What it records without any code](#what-it-records-without-any-code). `false` reports none. |
@@ -382,7 +451,7 @@ $ npm run typecheck
382
451
  $ npm run test:int
383
452
  ```
384
453
 
385
- The queue suites need a Redis, and the query-span suites a PostgreSQL, MySQL and MongoDB. Each suite skips itself when its server does not answer, so without them `test:int` passes having tested less. CI starts them with these ports and credentials, which the suites default to:
454
+ The MSSQL unit suite uses the real driver's public request APIs with stubbed transport methods and needs no SQL Server. The queue suites need a Redis, and the query-span integration suites a PostgreSQL, MySQL and MongoDB. Each integration suite skips itself when its server does not answer, so without them `test:int` passes having tested less. CI starts them with these ports and credentials, which the suites default to:
386
455
 
387
456
  ```bash
388
457
  $ docker run -d -p 6379:6379 redis:7-alpine
@@ -7,7 +7,10 @@
7
7
  * parent logs - and a second message shape would have to be threaded through
8
8
  * the same handler anyway. Parsed in exactly one place on each side.
9
9
  *
10
- * The value after it is `false`, `true`, or `trimmed` - see `IngestMode`.
10
+ * The value after it is `false`, `true`, `trimmed`, `paced` or `errors-only` -
11
+ * see `IngestMode` - and an `errors-only` value carries the pause's reason
12
+ * after a colon when the collector gave one this agent can word:
13
+ * `errors-only:spike` or `errors-only:budget` (see `OveragePauseReason`).
11
14
  */
12
15
  export declare const DEGRADED_MESSAGE_PREFIX = "observe:degraded=";
13
16
  /**
@@ -18,19 +21,57 @@ export declare const DEGRADED_MESSAGE_PREFIX = "observe:degraded=";
18
21
  * ingest - and only notable traces keep their spans.
19
22
  * - `trimmed`: a paying account past its threshold has its traces trimmed by
20
23
  * the same rule, to keep its bill down.
24
+ * - `paced`: a Free account still inside its allowance whose UTC day passed a
25
+ * tenth of it has its traces held back by the same rule until 00:00 UTC, so
26
+ * one busy day cannot spend the month.
27
+ * - `errors-only`: a paying account's overage is paused - by spike protection,
28
+ * or because its monthly overage budget is spent - and the collector keeps
29
+ * its server errors (`isServerErrorSnapshot`) and nothing else: not their
30
+ * trees, no other request or job, no log record. Runtime and custom metrics
31
+ * and objectives are kept as ever.
21
32
  *
22
- * Both of the last two withhold exactly the same trees; they differ only in
23
- * why, which is what the operator is told and what they can do about it.
33
+ * `reduced`, `trimmed` and `paced` withhold exactly the same trees; they
34
+ * differ only in why, which is what the operator is told and what they can do
35
+ * about it. `errors-only` withholds far more, and only the dashboard or the
36
+ * turn of the month ends it.
37
+ *
38
+ * Every batch says which of them this agent can tell apart, in the request
39
+ * header `x-observe-ingest-modes: reduced, trimmed, paced, errors-only` (set
40
+ * where the worker builds its headers, credentials or not). The collector
41
+ * reads only `paced` and `errors-only`. Agents up to 0.3.11 send no header and
42
+ * take any `degraded: true` for a spent allowance, so a paced account's
43
+ * batches from them are answered `{ degraded: false }` and the collector trims
44
+ * the trees itself: the waterfalls are still held back, and nobody is told
45
+ * their month is gone. Only an agent that lists `paced` is answered
46
+ * `{ degraded: true, paced: true }`, and can stop sending those trees in the
47
+ * first place.
48
+ *
49
+ * A paused account's batches are answered `{ degraded: true }` when the agent
50
+ * does not list `errors-only`, as no agent up to 0.3.12 does, and the
51
+ * collector keeps only the server errors of whatever arrives. Only an agent
52
+ * that lists it is answered `{ degraded: true, errorsOnly: true, reason }`,
53
+ * and can stop sending the rest - and say why.
54
+ */
55
+ export type IngestMode = "full" | "reduced" | "trimmed" | "paced" | "errors-only";
56
+ /**
57
+ * Why a paying account's overage is paused, as an `errors-only` reply says
58
+ * it: `spike` when spike protection paused it - a day far past the account's
59
+ * usual volume, while it was already in overage - and `budget` when its
60
+ * monthly overage budget is spent.
61
+ *
62
+ * Only the operator's notice reads it. What is withheld is the same either
63
+ * way, and so is a reason this agent has no words for, or none at all.
24
64
  */
25
- export type IngestMode = "full" | "reduced" | "trimmed";
65
+ export type OveragePauseReason = "spike" | "budget";
26
66
  /**
27
67
  * How long the main thread keeps withholding spans after the last batch that
28
68
  * reported degradation.
29
69
  *
30
70
  * The state is advisory and the collector never announces the end of it: an
31
- * upgrade or the turn of the billing period simply starts keeping spans
32
- * again. So it expires on its own, and the cost of it being briefly stale is
33
- * one flush of spans sent and discarded - against a restart being required to
71
+ * upgrade, the turn of the billing period, an overage pause resumed in the
72
+ * dashboard or, for a paced day, 00:00 UTC simply starts keeping spans again.
73
+ * So it expires on its own, and the cost of it being briefly stale is one
74
+ * flush of spans sent and discarded - against a restart being required to
34
75
  * recover, which is what a sticky flag would have cost.
35
76
  */
36
77
  export declare const DEGRADED_TTL_MS: number;
@@ -38,14 +79,23 @@ export declare const DEGRADED_TTL_MS: number;
38
79
  * The worker's line for one batch, or null if this is not that line.
39
80
  *
40
81
  * `true` and `false` are what the line has always carried, and they mean what
41
- * they always did; `trimmed` is the one addition. Anything else reads as
82
+ * they always did; `trimmed`, `paced` and `errors-only` are the additions. An
83
+ * `errors-only` line reads as one whatever follows its colon: the reason only
84
+ * words the notice (`parseOveragePauseReason`), and one this agent cannot word
85
+ * must not send a paused account's every request. Anything else reads as
42
86
  * `full`, as every value but `true` always has.
43
87
  */
44
88
  export declare function parseDegradedMessage(msg: string): IngestMode | null;
89
+ /**
90
+ * Why the worker's line says the account's overage is paused, or null when it
91
+ * is not an `errors-only` line, or gives no reason, or one this agent has no
92
+ * words for - read beside `parseDegradedMessage`, from the same line.
93
+ */
94
+ export declare function parseOveragePauseReason(msg: string): OveragePauseReason | null;
45
95
  /**
46
96
  * How the detached worker tells the main thread it will send nothing until a
47
- * given time (epoch milliseconds): after a 429, until the pause lapses; after
48
- * rejected credentials, never.
97
+ * given time (epoch milliseconds): after a 429 or rejected credentials, until
98
+ * that pause lapses.
49
99
  *
50
100
  * Only the final flush reads it. A paused worker leaves the shared slot
51
101
  * untouched, so without this a shutdown would wait out its whole deadline for
@@ -72,12 +122,8 @@ export declare const NOTABLE_DURATION_MS = 1000;
72
122
  * anything, or an account past its allowance loses exactly the waterfalls the
73
123
  * collector was still willing to store - and loses them silently.
74
124
  *
75
- * The rule mirrors the collector's, including the part that looks wrong:
76
- * where there is a status code it decides alone, and the error object is not
77
- * consulted beside it. An expected 401 carries an error exactly like a 500
78
- * does, and on that platform 401s and 429s are most of the daily error count -
79
- * so consulting the error first would send a tree for every unauthenticated
80
- * probe, which is the traffic this exists to stop sending.
125
+ * A server error (`isServerErrorSnapshot`, whose rule this shares), or
126
+ * anything slow.
81
127
  */
82
128
  export declare function isNotableSnapshot(snapshot: {
83
129
  d?: number;
@@ -86,6 +132,31 @@ export declare function isNotableSnapshot(snapshot: {
86
132
  sc?: number;
87
133
  };
88
134
  }): boolean;
135
+ /**
136
+ * Whether an execution is a server error: what the collector still keeps of
137
+ * an account whose overage is paused (`errors-only`), and half of what makes
138
+ * an execution notable.
139
+ *
140
+ * Mirrors the collector's `isServerErrorExecution` - its notable rule without
141
+ * the duration half - for the reason `isNotableSnapshot` mirrors the rest: an
142
+ * agent that withholds what the collector would have kept loses a paused
143
+ * account the one stream it was promised, and loses it silently. A slow
144
+ * success is notable and still not one of these.
145
+ *
146
+ * The rule includes the part that looks wrong: where there is a status code
147
+ * it decides alone, and the error object is not consulted beside it. An
148
+ * expected 401 carries an error exactly like a 500 does, and on that platform
149
+ * 401s and 429s are most of the daily error count - so consulting the error
150
+ * first would send a tree for every unauthenticated probe, which is the
151
+ * traffic degraded ingest exists to stop sending, and would keep every one of
152
+ * them through a pause, when a 4xx flood is a common cause of the spike.
153
+ */
154
+ export declare function isServerErrorSnapshot(snapshot: {
155
+ e?: unknown;
156
+ a?: {
157
+ sc?: number;
158
+ };
159
+ }): boolean;
89
160
  /**
90
161
  * Nodes in an encoded trace tree, counted the way the collector counts them.
91
162
  *
@@ -7,7 +7,10 @@
7
7
  * parent logs - and a second message shape would have to be threaded through
8
8
  * the same handler anyway. Parsed in exactly one place on each side.
9
9
  *
10
- * The value after it is `false`, `true`, or `trimmed` - see `IngestMode`.
10
+ * The value after it is `false`, `true`, `trimmed`, `paced` or `errors-only` -
11
+ * see `IngestMode` - and an `errors-only` value carries the pause's reason
12
+ * after a colon when the collector gave one this agent can word:
13
+ * `errors-only:spike` or `errors-only:budget` (see `OveragePauseReason`).
11
14
  */
12
15
  export const DEGRADED_MESSAGE_PREFIX = "observe:degraded=";
13
16
  /**
@@ -15,9 +18,10 @@ export const DEGRADED_MESSAGE_PREFIX = "observe:degraded=";
15
18
  * reported degradation.
16
19
  *
17
20
  * The state is advisory and the collector never announces the end of it: an
18
- * upgrade or the turn of the billing period simply starts keeping spans
19
- * again. So it expires on its own, and the cost of it being briefly stale is
20
- * one flush of spans sent and discarded - against a restart being required to
21
+ * upgrade, the turn of the billing period, an overage pause resumed in the
22
+ * dashboard or, for a paced day, 00:00 UTC simply starts keeping spans again.
23
+ * So it expires on its own, and the cost of it being briefly stale is one
24
+ * flush of spans sent and discarded - against a restart being required to
21
25
  * recover, which is what a sticky flag would have cost.
22
26
  */
23
27
  export const DEGRADED_TTL_MS = 5 * 60 * 1000;
@@ -25,26 +29,49 @@ export const DEGRADED_TTL_MS = 5 * 60 * 1000;
25
29
  * The worker's line for one batch, or null if this is not that line.
26
30
  *
27
31
  * `true` and `false` are what the line has always carried, and they mean what
28
- * they always did; `trimmed` is the one addition. Anything else reads as
32
+ * they always did; `trimmed`, `paced` and `errors-only` are the additions. An
33
+ * `errors-only` line reads as one whatever follows its colon: the reason only
34
+ * words the notice (`parseOveragePauseReason`), and one this agent cannot word
35
+ * must not send a paused account's every request. Anything else reads as
29
36
  * `full`, as every value but `true` always has.
30
37
  */
31
38
  export function parseDegradedMessage(msg) {
32
39
  if (!msg.startsWith(DEGRADED_MESSAGE_PREFIX)) {
33
40
  return null;
34
41
  }
35
- switch (msg.slice(DEGRADED_MESSAGE_PREFIX.length)) {
42
+ const value = msg.slice(DEGRADED_MESSAGE_PREFIX.length);
43
+ switch (value) {
36
44
  case "true":
37
45
  return "reduced";
38
46
  case "trimmed":
39
47
  return "trimmed";
48
+ case "paced":
49
+ return "paced";
50
+ case "errors-only":
51
+ return "errors-only";
40
52
  default:
41
- return "full";
53
+ return value.startsWith("errors-only:") ? "errors-only" : "full";
54
+ }
55
+ }
56
+ /**
57
+ * Why the worker's line says the account's overage is paused, or null when it
58
+ * is not an `errors-only` line, or gives no reason, or one this agent has no
59
+ * words for - read beside `parseDegradedMessage`, from the same line.
60
+ */
61
+ export function parseOveragePauseReason(msg) {
62
+ switch (msg) {
63
+ case `${DEGRADED_MESSAGE_PREFIX}errors-only:spike`:
64
+ return "spike";
65
+ case `${DEGRADED_MESSAGE_PREFIX}errors-only:budget`:
66
+ return "budget";
67
+ default:
68
+ return null;
42
69
  }
43
70
  }
44
71
  /**
45
72
  * How the detached worker tells the main thread it will send nothing until a
46
- * given time (epoch milliseconds): after a 429, until the pause lapses; after
47
- * rejected credentials, never.
73
+ * given time (epoch milliseconds): after a 429 or rejected credentials, until
74
+ * that pause lapses.
48
75
  *
49
76
  * Only the final flush reads it. A paused worker leaves the shared slot
50
77
  * untouched, so without this a shutdown would wait out its whole deadline for
@@ -78,22 +105,40 @@ const SERVER_ERROR_FLOOR = 500;
78
105
  * anything, or an account past its allowance loses exactly the waterfalls the
79
106
  * collector was still willing to store - and loses them silently.
80
107
  *
81
- * The rule mirrors the collector's, including the part that looks wrong:
82
- * where there is a status code it decides alone, and the error object is not
83
- * consulted beside it. An expected 401 carries an error exactly like a 500
84
- * does, and on that platform 401s and 429s are most of the daily error count -
85
- * so consulting the error first would send a tree for every unauthenticated
86
- * probe, which is the traffic this exists to stop sending.
108
+ * A server error (`isServerErrorSnapshot`, whose rule this shares), or
109
+ * anything slow.
87
110
  */
88
111
  export function isNotableSnapshot(snapshot) {
89
112
  const slow = typeof snapshot.d === "number" && snapshot.d > NOTABLE_DURATION_MS;
113
+ return slow || isServerErrorSnapshot(snapshot);
114
+ }
115
+ /**
116
+ * Whether an execution is a server error: what the collector still keeps of
117
+ * an account whose overage is paused (`errors-only`), and half of what makes
118
+ * an execution notable.
119
+ *
120
+ * Mirrors the collector's `isServerErrorExecution` - its notable rule without
121
+ * the duration half - for the reason `isNotableSnapshot` mirrors the rest: an
122
+ * agent that withholds what the collector would have kept loses a paused
123
+ * account the one stream it was promised, and loses it silently. A slow
124
+ * success is notable and still not one of these.
125
+ *
126
+ * The rule includes the part that looks wrong: where there is a status code
127
+ * it decides alone, and the error object is not consulted beside it. An
128
+ * expected 401 carries an error exactly like a 500 does, and on that platform
129
+ * 401s and 429s are most of the daily error count - so consulting the error
130
+ * first would send a tree for every unauthenticated probe, which is the
131
+ * traffic degraded ingest exists to stop sending, and would keep every one of
132
+ * them through a pause, when a 4xx flood is a common cause of the spike.
133
+ */
134
+ export function isServerErrorSnapshot(snapshot) {
90
135
  const statusCode = snapshot.a?.sc;
91
136
  if (typeof statusCode === "number") {
92
- return statusCode >= SERVER_ERROR_FLOOR || slow;
137
+ return statusCode >= SERVER_ERROR_FLOOR;
93
138
  }
94
139
  // No status code: a job, or a non-HTTP entry point. Nothing grades these but
95
140
  // the error, so here it is the signal rather than the noise.
96
- return Boolean(snapshot.e) || slow;
141
+ return Boolean(snapshot.e);
97
142
  }
98
143
  /**
99
144
  * Nodes in an encoded trace tree, counted the way the collector counts them.
@@ -15,4 +15,5 @@ export declare function detachedWorkerData(input: {
15
15
  endpoint: string;
16
16
  appKey?: string;
17
17
  appSecret?: string;
18
+ flushInterval: number;
18
19
  }): DetachedWorkerData;
@@ -22,6 +22,7 @@ export function detachedWorkerData(input) {
22
22
  endpoint: input.endpoint,
23
23
  appKey: input.appKey,
24
24
  appSecret: input.appSecret,
25
+ flushInterval: input.flushInterval,
25
26
  wireShapes: SECTION_SHAPES,
26
27
  degradedPrefix: DEGRADED_MESSAGE_PREFIX,
27
28
  pausedPrefix: PAUSED_MESSAGE_PREFIX,
@@ -12,6 +12,11 @@ export interface DetachedWorkerConfig {
12
12
  endpoint: string;
13
13
  appKey?: string;
14
14
  appSecret?: string;
15
+ /**
16
+ * Milliseconds between the main thread's flushes, as clamped there: the
17
+ * first pause after rejected credentials, which then doubles.
18
+ */
19
+ flushInterval: number;
15
20
  /** Plain JSON, so it travels as data; the sanitizer that reads it travels as source. */
16
21
  wireShapes: Parameters<typeof createTelemetrySanitizer>[0];
17
22
  /** `DEGRADED_MESSAGE_PREFIX`, as data - see where it is read below. */