@nestjs/observe 0.3.20 → 0.3.22
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/LICENSE +105 -22
- package/NOTICE +31 -0
- package/README.md +138 -21
- package/dist/agent/degraded-ingest.protocol.d.ts +20 -0
- package/dist/agent/degraded-ingest.protocol.js +25 -0
- package/dist/agent/detached-observe-worker.assembly.js +2 -1
- package/dist/agent/detached-observe-worker.d.ts +2 -0
- package/dist/agent/detached-observe-worker.js +7 -0
- package/dist/agent/observe-agent.shared-buffer.d.ts +36 -0
- package/dist/agent/observe-agent.shared-buffer.js +56 -1
- package/dist/agent/observe-agent.worker.d.ts +12 -0
- package/dist/agent/observe-agent.worker.js +63 -8
- package/dist/instrument/create-instance-decorator.instrument.js +99 -86
- package/dist/interfaces/observe-options.interface.d.ts +42 -3
- package/dist/interfaces/trace-events.interfaces.d.ts +11 -5
- package/dist/observe.constants.d.ts +15 -5
- package/dist/observe.constants.js +15 -5
- package/dist/observe.module.js +3 -0
- package/dist/outgoing/http.integration.d.ts +34 -3
- package/dist/outgoing/http.integration.js +84 -17
- package/dist/outgoing/outgoing-observe-agent.service.d.ts +14 -1
- package/dist/outgoing/outgoing-observe-agent.service.js +24 -9
- package/dist/outgoing/outgoing-span.recorder.d.ts +11 -1
- package/dist/outgoing/outgoing-span.recorder.js +8 -2
- package/dist/protocols/deferred-trace-completion.d.ts +13 -2
- package/dist/protocols/deferred-trace-completion.js +27 -4
- package/dist/protocols/graphql-observe-agent.service.js +1 -1
- package/dist/protocols/http-observe-agent.service.js +45 -30
- package/dist/protocols/job-trace-runner.js +2 -2
- package/dist/protocols/rpc-observe-agent.service.js +19 -10
- package/dist/protocols/ws-observe-agent.service.js +1 -1
- package/dist/services/collapse-repeated-spans.util.js +41 -37
- package/dist/services/operation-trace.registry.d.ts +32 -11
- package/dist/services/operation-trace.registry.js +102 -33
- package/dist/services/tracer.service.d.ts +6 -0
- package/dist/services/tracer.service.js +11 -2
- package/dist/utils/default-trace-id-generator.util.d.ts +18 -0
- package/dist/utils/default-trace-id-generator.util.js +33 -0
- package/dist/utils/opentelemetry.util.d.ts +31 -0
- package/dist/utils/opentelemetry.util.js +52 -0
- package/dist/utils/trace-context.util.d.ts +91 -0
- package/dist/utils/trace-context.util.js +219 -0
- package/dist/utils/trace-id-generator-origin.util.d.ts +11 -0
- package/dist/utils/trace-id-generator-origin.util.js +26 -0
- package/dist/utils/uuid-v7.util.js +53 -15
- package/package.json +18 -4
package/LICENSE
CHANGED
|
@@ -1,22 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Copyright (c)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
NestJS Observe Agent License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present NestJS Kamil Mysliwiec <https://nestjs.com>
|
|
4
|
+
|
|
5
|
+
This license applies to this repository as published after the release of
|
|
6
|
+
@nestjs/observe 0.3.20, and to every version of @nestjs/observe released
|
|
7
|
+
after 0.3.20. Version 0.3.20 and earlier were released under the MIT License
|
|
8
|
+
and remain available under it (see NOTICE).
|
|
9
|
+
|
|
10
|
+
DEFINITIONS
|
|
11
|
+
|
|
12
|
+
"Licensor" or "NestJS" means NestJS Kamil Mysliwiec (https://nestjs.com).
|
|
13
|
+
|
|
14
|
+
"Software" means the source code, object code and documentation this license
|
|
15
|
+
applies to, and any modified version, part or derivative work of them.
|
|
16
|
+
|
|
17
|
+
"Service" means NestJS Observe, the hosted service the Licensor operates at
|
|
18
|
+
observe.nestjs.com, together with the collector endpoints the Licensor
|
|
19
|
+
operates for it.
|
|
20
|
+
|
|
21
|
+
"Telemetry" means the data the Software records about the applications it
|
|
22
|
+
instruments, such as traces, spans, errors, logs, metrics and profiles.
|
|
23
|
+
|
|
24
|
+
"You" means the individual or entity exercising rights under this license.
|
|
25
|
+
|
|
26
|
+
1. GRANT
|
|
27
|
+
|
|
28
|
+
Subject to the conditions of this license, the Licensor grants You a
|
|
29
|
+
worldwide, royalty-free, non-exclusive, non-transferable license to use,
|
|
30
|
+
copy, modify and distribute the Software, solely to:
|
|
31
|
+
|
|
32
|
+
(a) instrument Your applications and send their Telemetry to the Service,
|
|
33
|
+
directly or through proxies and gateways that forward it to the
|
|
34
|
+
Service;
|
|
35
|
+
|
|
36
|
+
(b) develop, build, test, deploy and run those applications, including
|
|
37
|
+
with the Software disabled; and
|
|
38
|
+
|
|
39
|
+
(c) develop and test changes to the Software that You submit to the
|
|
40
|
+
Licensor.
|
|
41
|
+
|
|
42
|
+
2. LIMITATIONS
|
|
43
|
+
|
|
44
|
+
You may not:
|
|
45
|
+
|
|
46
|
+
(a) use the Software to send Telemetry to any collector, backend or
|
|
47
|
+
service other than the Service, or a proxy or gateway that forwards
|
|
48
|
+
it to the Service;
|
|
49
|
+
|
|
50
|
+
(b) use the Software, including its source code, to develop, test,
|
|
51
|
+
document or operate a collector, backend or service that receives
|
|
52
|
+
Telemetry from the Software, or that substitutes for the Service;
|
|
53
|
+
|
|
54
|
+
(c) remove, disable or circumvent any part of the Software that limits
|
|
55
|
+
where it sends Telemetry; or
|
|
56
|
+
|
|
57
|
+
(d) remove or obscure any licensing, copyright or trademark notice in the
|
|
58
|
+
Software.
|
|
59
|
+
|
|
60
|
+
Exporting Telemetry through an export option included in a version of the
|
|
61
|
+
Software the Licensor released, such as OpenTelemetry (OTLP) export, as
|
|
62
|
+
documented for that version, does not violate (a).
|
|
63
|
+
|
|
64
|
+
Passing trace context, such as traceparent or x-request-id headers, between
|
|
65
|
+
Your applications and the services they call does not violate (a) or (b).
|
|
66
|
+
|
|
67
|
+
A collector used solely to test the Software or Your applications, that does
|
|
68
|
+
not store, display or provide monitoring of Telemetry for anyone, does not
|
|
69
|
+
violate (a) or (b).
|
|
70
|
+
|
|
71
|
+
3. DISTRIBUTION
|
|
72
|
+
|
|
73
|
+
You may distribute the Software, modified or not, including as part of Your
|
|
74
|
+
applications, but only under this license. This license covers only the
|
|
75
|
+
Software, not the rest of Your applications. Every copy You distribute must
|
|
76
|
+
include this license and the NOTICE file. Recipients receive their rights
|
|
77
|
+
from the Licensor under this license, not from You.
|
|
78
|
+
|
|
79
|
+
4. TERMINATION
|
|
80
|
+
|
|
81
|
+
If You use the Software in violation of this license, Your rights under it
|
|
82
|
+
end. If the Licensor notifies You of a violation and You stop it within 30
|
|
83
|
+
days of that notice, Your rights are reinstated, unless You have been
|
|
84
|
+
notified of a violation before.
|
|
85
|
+
|
|
86
|
+
5. TRADEMARKS
|
|
87
|
+
|
|
88
|
+
This license grants no rights to use the names "NestJS" or "NestJS Observe",
|
|
89
|
+
or any related logos or trademarks, except to state that Your application
|
|
90
|
+
uses the Software.
|
|
91
|
+
|
|
92
|
+
6. OTHER USES
|
|
93
|
+
|
|
94
|
+
Uses this license does not allow require a separate written agreement with
|
|
95
|
+
the Licensor.
|
|
96
|
+
|
|
97
|
+
7. NO WARRANTY; LIMITATION OF LIABILITY
|
|
98
|
+
|
|
99
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
100
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
101
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
102
|
+
LICENSOR OR ANY CONTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
103
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
104
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
105
|
+
DEALINGS IN THE SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@nestjs/observe version 0.3.20 and earlier were released under the MIT
|
|
2
|
+
License and remain available under it. Later versions are released under
|
|
3
|
+
the NestJS Observe Agent License (see LICENSE).
|
|
4
|
+
|
|
5
|
+
Portions of this Software were contributed under the MIT License. For those
|
|
6
|
+
portions, the following notice applies:
|
|
7
|
+
|
|
8
|
+
--------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
(The MIT License)
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2017-present Kamil Mysliwiec <https://kamilmysliwiec.com>
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
15
|
+
a copy of this software and associated documentation files (the
|
|
16
|
+
'Software'), to deal in the Software without restriction, including
|
|
17
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
18
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
19
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
20
|
+
the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be
|
|
23
|
+
included in all copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
26
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
27
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
28
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
29
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
30
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
31
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/@nestjs/observe"><img src="https://img.shields.io/npm/v/@nestjs/observe.svg" alt="NPM Version" /></a>
|
|
9
9
|
<a href="https://www.npmjs.com/package/@nestjs/observe"><img src="https://img.shields.io/npm/dm/@nestjs/observe.svg" alt="NPM Downloads" /></a>
|
|
10
|
-
<a href="
|
|
10
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Observe%20Agent-blue.svg" alt="License: NestJS Observe Agent License" /></a>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
@@ -38,19 +38,48 @@ Install it, set two environment variables, and the application starts reporting:
|
|
|
38
38
|
[custom metrics](https://www.observe.nestjs.com/documentation/sdk#custom-metrics)
|
|
39
39
|
your code reports through `TracerService`.
|
|
40
40
|
|
|
41
|
-
Telemetry is
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
Telemetry is compressed and sent from a detached worker thread, so a slow or
|
|
42
|
+
unreachable collector never holds a request up. Recording it does cost the
|
|
43
|
+
request path a microsecond or two per traced call - [Overhead](#overhead) has
|
|
44
|
+
the numbers.
|
|
45
|
+
|
|
46
|
+
### Observe and OpenTelemetry
|
|
47
|
+
|
|
48
|
+
OpenTelemetry is the vendor-neutral standard across a polyglot estate, and
|
|
49
|
+
this agent isn't a replacement for it: it works on its own, or beside the
|
|
50
|
+
OpenTelemetry you already have. What it brings to a Nest service is no
|
|
51
|
+
collector to run, no exporter pipeline to configure, no manual instrumentation
|
|
52
|
+
for the framework's own lifecycle — and spans named after your Nest classes
|
|
53
|
+
and methods, which generic Node.js instrumentation cannot produce because it
|
|
54
|
+
cannot see them. If you would otherwise spend a week wiring a collector and
|
|
55
|
+
still not know which provider spent the time, this is the shortcut.
|
|
56
|
+
|
|
57
|
+
It also runs beside OpenTelemetry, with `openTelemetry: true`. The agent then
|
|
58
|
+
continues and sends W3C `traceparent`, so a trace that runs through services
|
|
59
|
+
instrumented with OpenTelemetry stays one trace. In a Nest service that already
|
|
60
|
+
starts the OpenTelemetry Node SDK, it reports each request under the trace id
|
|
61
|
+
the SDK gave it - also when the request started the trace - and leaves
|
|
62
|
+
`traceparent` to the SDK on calls out of the service, so a request has one
|
|
63
|
+
trace id in both tools and every call carries one `traceparent`. The SDK keeps
|
|
64
|
+
its own spans, the agent adds the class-level ones. This is tested against the
|
|
65
|
+
SDK with its auto-instrumentations, on Express and Fastify, over `fetch`,
|
|
66
|
+
`node:http`, `pg` and Nest's own instrumentation. Without the option, the agent
|
|
67
|
+
speaks `x-request-id` alone and leaves any OpenTelemetry SDK in the process
|
|
68
|
+
alone.
|
|
69
|
+
|
|
70
|
+
It works only beside reporting to NestJS Observe. It turns on with the first
|
|
71
|
+
batch the collector accepts, and pauses - saying so in the log - while the
|
|
72
|
+
collector refuses the app's credentials, once batches have failed to get in
|
|
73
|
+
for a minute, or while the agent's worker is down, resuming with the next batch
|
|
74
|
+
the collector accepts. With `enabled: false`, or without credentials for the
|
|
75
|
+
hosted collector, it never turns on.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
ObserveModule.forRoot({
|
|
79
|
+
serviceId: "orders-api",
|
|
80
|
+
openTelemetry: true,
|
|
81
|
+
});
|
|
82
|
+
```
|
|
54
83
|
|
|
55
84
|
## Seeing it before installing
|
|
56
85
|
|
|
@@ -105,8 +134,8 @@ The agent says so once, then backs off - one flush interval, then two, then
|
|
|
105
134
|
four, up to one attempt an hour - until the credentials are fixed. They are
|
|
106
135
|
read at startup, so that takes a restart. Leave `appKey` or `appSecret` unset,
|
|
107
136
|
with nothing in `OBSERVE_APP_KEY` or `OBSERVE_APP_SECRET` either, and nothing
|
|
108
|
-
is sent to the hosted collector at all, with a warning at startup instead; a
|
|
109
|
-
them.
|
|
137
|
+
is sent to the hosted collector at all, with a warning at startup instead; a proxy at `endpoint` that adds them on the way to NestJS Observe still
|
|
138
|
+
receives batches without them.
|
|
110
139
|
|
|
111
140
|
To keep an environment from reporting - local development, say - switch the
|
|
112
141
|
agent off rather than supplying fake credentials, which are sent and refused:
|
|
@@ -194,6 +223,92 @@ export class ObserveConfig implements ObserveOptionsFactory {
|
|
|
194
223
|
}
|
|
195
224
|
```
|
|
196
225
|
|
|
226
|
+
## Overhead
|
|
227
|
+
|
|
228
|
+
What the agent costs an application is mostly the spans it records: every
|
|
229
|
+
provider method a request calls passes through the instrumentation, on the
|
|
230
|
+
thread serving the request. Measured in October 2026 with
|
|
231
|
+
[the benchmark in `bench/`](https://github.com/nestjs/observe/blob/master/bench/README.md),
|
|
232
|
+
the agent at its defaults against the same Nest 12 application without it, on
|
|
233
|
+
Express, Node 24 and an Apple M1 Pro:
|
|
234
|
+
|
|
235
|
+
| Per request | 1 traced call | 9 traced calls | 102 traced calls |
|
|
236
|
+
| -------------------------------------- | ------------- | -------------- | ---------------- |
|
|
237
|
+
| CPU added, process fully busy | +9 µs | +29 µs | +115 µs |
|
|
238
|
+
| Median latency added at 150 requests/s | +0.10 ms | +0.09 ms | +0.45 ms |
|
|
239
|
+
|
|
240
|
+
The nine calls are a guard, an interceptor, a pipe, a controller, a service and
|
|
241
|
+
two repositories awaiting their results; the 102 are a service calling another
|
|
242
|
+
provider in a loop, [collapsed](#repeated-spans) to six spans before shipping.
|
|
243
|
+
|
|
244
|
+
| Per process | Added |
|
|
245
|
+
| -------------------------- | ---------------------------------------------------- |
|
|
246
|
+
| Memory at boot | +11 MB RSS |
|
|
247
|
+
| Memory at 150 requests/s | +32 MB to +64 MB RSS |
|
|
248
|
+
| CPU while idle | 0.3-0.6% of one core, almost all off the main thread |
|
|
249
|
+
| Process start to listening | +30 to +40 ms, within run-to-run noise |
|
|
250
|
+
|
|
251
|
+
As a rule of thumb, **about 8 µs per request plus 1-2.5 µs per traced call**,
|
|
252
|
+
async methods at the dearer end. A traced provider reads its own fields -
|
|
253
|
+
`this.repository`, `this.config.rate` - through a proxy, at about 30 ns a read,
|
|
254
|
+
which a loop over thousands of items pays on every iteration.
|
|
255
|
+
|
|
256
|
+
Spans are recorded on the thread that serves the request. Every
|
|
257
|
+
`flushInterval` (5 s) that thread serialises the batch, and a worker thread
|
|
258
|
+
compresses and sends it. A batch holds at most `maxTracesPerBatch` traces
|
|
259
|
+
(1,000), which also caps what shipping costs: requests past it within a flush
|
|
260
|
+
interval are recorded but not sent. A lightly loaded process pays more CPU per
|
|
261
|
+
request than a busy one, with the agent or without, and the agent's share
|
|
262
|
+
grows with it: at 150 requests a second it added 3.5 to 4 points of one core on
|
|
263
|
+
the 1- and 9-call endpoints, and 10 on the 102-call one.
|
|
264
|
+
|
|
265
|
+
These endpoints do almost no work of their own, so in relative terms the
|
|
266
|
+
figures are a ceiling: an endpoint that spends a millisecond on a query pays
|
|
267
|
+
the same microseconds. They were taken on a development machine with other
|
|
268
|
+
work running, as medians of two runs, and moved by a third between runs - by
|
|
269
|
+
half for a lightly loaded process. The run behind them is in
|
|
270
|
+
[`bench/2026-10-30-results.md`](https://github.com/nestjs/observe/blob/master/bench/2026-10-30-results.md),
|
|
271
|
+
and `npm run bench` in a clone of this repository reproduces it on your own
|
|
272
|
+
hardware in about 8 minutes.
|
|
273
|
+
|
|
274
|
+
### Compared with other agents
|
|
275
|
+
|
|
276
|
+
We found no overhead figures published by the vendors below, so the table
|
|
277
|
+
takes third-party benchmarks, each measuring an agent on a near-empty endpoint
|
|
278
|
+
on its own hardware. It says which way things lean rather than ranking them:
|
|
279
|
+
|
|
280
|
+
| Agent | Benchmark | Throughput lost | Time added per request |
|
|
281
|
+
| ------------------------------------------- | ---------------------------------------------- | --------------- | ---------------------- |
|
|
282
|
+
| New Relic | [NodeSource][nodesource], Express, Node 22 | 72% | 200 µs |
|
|
283
|
+
| Datadog | [NodeSource][nodesource], Express, Node 22 | 63% | 130 µs |
|
|
284
|
+
| Sentry | [NodeSource][nodesource], Express, Node 22 | 37% | 45 µs |
|
|
285
|
+
| OpenTelemetry, all auto-instrumentations | [Platformatic][platformatic], Fastify, Node 24 | 81% | 77 µs |
|
|
286
|
+
| OpenTelemetry, Fastify instrumentation only | [Platformatic][platformatic], Fastify, Node 24 | 64% | 31 µs |
|
|
287
|
+
| `@nestjs/observe`, 1 traced call | this benchmark, Nest on Express, Node 24 | 22% | 7 µs |
|
|
288
|
+
| `@nestjs/observe`, 9 traced calls | this benchmark, Nest on Express, Node 24 | 33% | 20 µs |
|
|
289
|
+
| `@nestjs/observe`, 102 traced calls | this benchmark, Nest on Express, Node 24 | 69% | 110 µs |
|
|
290
|
+
|
|
291
|
+
Time added per request is what a fully busy process spends on each request with
|
|
292
|
+
the agent, minus without it - one second divided by the requests per second,
|
|
293
|
+
from each benchmark's own figures. It is the time of the thread that serves
|
|
294
|
+
requests, so it reads a little under the CPU added above, which counts every
|
|
295
|
+
thread of the process. Neither column ranks the agents. The machines differ:
|
|
296
|
+
NodeSource's run (July 2025) is on a 4-core 3.6 GHz Linux server where plain
|
|
297
|
+
Express answers 13,000 requests a second, so the same work takes longer there
|
|
298
|
+
than on this laptop, where the Nest application answers 20,000 to 38,000. And a
|
|
299
|
+
percentage depends on how fast the baseline is: the same microseconds are a
|
|
300
|
+
bigger share of a faster one.
|
|
301
|
+
|
|
302
|
+
What neither column shows is how much gets recorded. The agents above trace a
|
|
303
|
+
request, its middleware and its calls out of the process, and OpenTelemetry's
|
|
304
|
+
full set more kinds of call than its Fastify instrumentation alone - DNS
|
|
305
|
+
lookups and sockets among them. This one also traces every provider method the
|
|
306
|
+
request goes through: the class-level waterfall, and the reason an endpoint
|
|
307
|
+
making a hundred provider calls costs it more than it would them.
|
|
308
|
+
|
|
309
|
+
[nodesource]: https://benchmark.nodesource.com/
|
|
310
|
+
[platformatic]: https://blog.platformatic.dev/the-hidden-cost-of-context
|
|
311
|
+
|
|
197
312
|
## Repeated spans
|
|
198
313
|
|
|
199
314
|
Every provider is instrumented by default, framework-owned ones included, and
|
|
@@ -287,7 +402,8 @@ Once the module and the instrument are in place, the agent reports, with no furt
|
|
|
287
402
|
|
|
288
403
|
- **Requests, GraphQL operations, RPC messages, WebSocket gateway messages, queue jobs and scheduled jobs**, each with its tree of provider method calls.
|
|
289
404
|
- **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.
|
|
290
|
-
- **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.
|
|
405
|
+
- **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. With `openTelemetry: true`, a W3C `traceparent` goes with it, naming the trace and the call's span, so a service instrumented with OpenTelemetry - in Go, Python, Java or anything else - continues it too, as does a service running the agent behind it. When an OpenTelemetry SDK that propagates W3C Trace Context runs in the same process, `traceparent` is left to it: its instrumentations write the header on the calls they cover, and a request takes only one. `outgoing: { http: { traceContext: false } }` sends `x-request-id` alone even then, and `propagateTraceId: (url) => boolean` keeps both headers away from the URLs you name.
|
|
406
|
+
- **Trace context from OpenTelemetry**, with `openTelemetry: true`: a request arriving with a W3C `traceparent` - from a service instrumented with OpenTelemetry, a mesh, or a load balancer that starts traces - is reported under that trace id, written as a UUID (`4bf92f35-77b3-4da6-a3ce-929d0e0e4736`), so the same id finds it in both tools. With an OpenTelemetry SDK in the same process - or another tracer registered with the OpenTelemetry API, as dd-trace is once its `TracerProvider` is registered - the trace is the one the SDK's server span is in, so a request that starts a trace gets the SDK's id too. That holds when a mesh or router stamped an `x-request-id` of its own on the request too, as Envoy and Heroku's router do: an `x-request-id` is kept only when it names the same trace, which is what another service running the agent sends, so custom ids still carry from one such service to the next. Over HTTP only: microservice, gRPC and queue hops pass the trace id as `x-request-id` and job options, as before. Without the option, a request is named by its `x-request-id`, else by a UUIDv7 of its own, and no `traceparent` is read or sent.
|
|
291
407
|
- **Model calls**: a `fetch` to OpenAI, Azure OpenAI, Anthropic, Gemini or Vertex, Bedrock, Mistral, Groq, OpenRouter, Together, DeepSeek, xAI, Cohere or Perplexity also reports the model and the input, output and cached tokens its response states - read as the response passes through to your code, streams included, so it arrives exactly as it would have and a stream you cancel is cancelled at the provider too. That covers the official SDKs, the Vercel AI SDK and LangChain, which all use `fetch`; calls made through `node:http` (axios, the AWS SDK) keep their plain span. Prompts and completions are never reported. A gateway in front of the providers is added with `outgoing: { llm: { hosts: ['llm-gateway.internal:4000'] } }`, and `outgoing: { llm: false }` turns this off and leaves the global `fetch` as it was.
|
|
292
408
|
- **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.
|
|
293
409
|
- **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.
|
|
@@ -409,7 +525,7 @@ Every option, with its default. The [documentation](https://www.observe.nestjs.c
|
|
|
409
525
|
| `appKey`, `appSecret` | required | The credentials the dashboard issues - see [Getting credentials](#getting-credentials). |
|
|
410
526
|
| `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. |
|
|
411
527
|
| `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. |
|
|
412
|
-
| `endpoint` | `https://observe-api.nestjs.com` | The collector's base URL. `OBSERVE_ENDPOINT` in the environment changes the default without touching the config. |
|
|
528
|
+
| `endpoint` | `https://observe-api.nestjs.com` | The collector's base URL - NestJS Observe, or a proxy that forwards to it. `OBSERVE_ENDPOINT` in the environment changes the default without touching the config. |
|
|
413
529
|
| `flushInterval` | `5000` | Milliseconds between sends of buffered telemetry; at least `1000`. |
|
|
414
530
|
| `shutdownFlushTimeout` | `2000` | Milliseconds closing the app waits for buffered telemetry to reach the collector before stopping the agent. `0` skips the final send - for test suites that boot the app with real credentials. |
|
|
415
531
|
| `maxTracesPerBatch` | `1000` | The most traces one send carries. |
|
|
@@ -420,7 +536,8 @@ Every option, with its default. The [documentation](https://www.observe.nestjs.c
|
|
|
420
536
|
| `runtimeMetricsInterval` | `60000` | Milliseconds between runtime samples; at least `30000`. |
|
|
421
537
|
| `forwardLogs` | `false` | Sends the application's log lines, each correlated to the trace it was written in - see [Logs](https://www.observe.nestjs.com/documentation/sdk#logs). |
|
|
422
538
|
| `redaction` | on | How log lines, error messages and captured requests are scrubbed before they leave the process: `enabled`, `useDefaultPatterns`, `patterns`, `keys` and `replacement`. |
|
|
423
|
-
| `outgoing` | on | Query and outbound-HTTP spans. `false` turns both off; `{ database: false }` or `{ http: false }` one of them.
|
|
539
|
+
| `outgoing` | on | Query and outbound-HTTP spans. `false` turns both off; `{ database: false }` or `{ http: false }` one of them. `{ http: { propagateTraceId, traceContext } }` tunes the `x-request-id` and `traceparent` headers outbound calls carry - `traceparent` only with `openTelemetry`. |
|
|
540
|
+
| `openTelemetry` | `false` | Continues and sends W3C `traceparent`, names a request after the W3C trace it is in, and follows an OpenTelemetry SDK running in the same process - see [Observe and OpenTelemetry](#observe-and-opentelemetry). Works only while the agent is reporting to NestJS Observe. Off, the agent reads and sends `x-request-id` alone. |
|
|
424
541
|
| `http` | | `ignore`, `tags`, `setAttributes`, `getUserId`, `queryParamsObfuscateRegex`, `tracePreflights` and `capture` - see [Capturing failed and slow requests](#capturing-failed-and-slow-requests). |
|
|
425
542
|
| `rpc`, `grpc` | | `ignore`, `tags`, `setAttributes` and `getUserId` for microservice and gRPC handlers. |
|
|
426
543
|
| `graphql` | | The same four, once per GraphQL operation. |
|
|
@@ -435,7 +552,7 @@ Every option, with its default. The [documentation](https://www.observe.nestjs.c
|
|
|
435
552
|
| Option | Default | What it does |
|
|
436
553
|
| --------------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
437
554
|
| `sourceContext` | `true` | Attaches the source around each in-app frame of a captured error - see [What it records without any code](#what-it-records-without-any-code). `{ linesOfContext, maxFrames, sourceMaps }` tunes it. |
|
|
438
|
-
| `traceIdGenerator` | the `x-request-id` header, else a UUIDv7 | Gives each request its trace id.
|
|
555
|
+
| `traceIdGenerator` | the `x-request-id` header, else a UUIDv7 | Gives each request its trace id. With `openTelemetry` on, the default takes the W3C trace id first and keeps an `x-request-id` that names the same trace, and the W3C trace is still read beside whatever this returns, so outbound calls stay in the caller's trace. |
|
|
439
556
|
| `traceIdKey` | `'traceId'` | The key the trace id is stored under in the request context. |
|
|
440
557
|
| `attachTraceIdToLogs` | `true` | Adds the trace id to the `ConsoleLogger`'s own output, on Nest 11.2 and later. Sending lines to the dashboard is `forwardLogs`. |
|
|
441
558
|
| `skipInstrumentation` | `() => false` | Returns `true` for a provider instance that must not be instrumented. Nest's `Reflector` and the `mongodb` driver's `MongoClient` and `Db` never are, whatever this returns. |
|
|
@@ -500,4 +617,4 @@ const { createObserveModule } = require("@nestjs/observe");
|
|
|
500
617
|
|
|
501
618
|
## License
|
|
502
619
|
|
|
503
|
-
`@nestjs/observe` is [MIT licensed](
|
|
620
|
+
`@nestjs/observe` is source-available under the [NestJS Observe Agent License](LICENSE): free to use and modify to send your applications' telemetry to NestJS Observe. Version 0.3.20 and earlier remain [MIT licensed](NOTICE).
|
|
@@ -104,6 +104,26 @@ export declare function parseOveragePauseReason(msg: string): OveragePauseReason
|
|
|
104
104
|
export declare const PAUSED_MESSAGE_PREFIX = "observe:paused-until=";
|
|
105
105
|
/** The time sends are paused until, or null if this is not that line. */
|
|
106
106
|
export declare function parsePausedMessage(msg: string): number | null;
|
|
107
|
+
/**
|
|
108
|
+
* How the detached worker tells the main thread a batch did not get in:
|
|
109
|
+
* `refused` when the collector turned the credentials away (401 or 403), and
|
|
110
|
+
* `failed` for anything else that kept a batch out - a 429, an unreachable
|
|
111
|
+
* collector, any other status, a fault in the worker. A batch that got in
|
|
112
|
+
* says so with its degraded verdict instead.
|
|
113
|
+
*
|
|
114
|
+
* Read for OpenTelemetry interop, which runs only while the collector takes
|
|
115
|
+
* this app's telemetry - see `ObserveAgentSharedBuffer.isIngesting`.
|
|
116
|
+
*/
|
|
117
|
+
export declare const NOT_INGESTED_MESSAGE_PREFIX = "observe:not-ingested=";
|
|
118
|
+
export type NotIngestedReason = "refused" | "failed";
|
|
119
|
+
/** Why a batch did not get in, or null if this is not that line. */
|
|
120
|
+
export declare function parseNotIngestedMessage(msg: string): NotIngestedReason | null;
|
|
121
|
+
/**
|
|
122
|
+
* How long batches may keep failing to get in before the collector counts as
|
|
123
|
+
* no longer taking this app's telemetry - a collector restarting, a network
|
|
124
|
+
* blip, a short rate-limit pause. Refused credentials end it at once.
|
|
125
|
+
*/
|
|
126
|
+
export declare const NOT_INGESTED_GRACE_MS: number;
|
|
107
127
|
/**
|
|
108
128
|
* Duration past which the collector treats an execution as notable, in
|
|
109
129
|
* milliseconds.
|
|
@@ -86,6 +86,31 @@ export function parsePausedMessage(msg) {
|
|
|
86
86
|
const until = Number(msg.slice(PAUSED_MESSAGE_PREFIX.length));
|
|
87
87
|
return Number.isFinite(until) ? until : null;
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* How the detached worker tells the main thread a batch did not get in:
|
|
91
|
+
* `refused` when the collector turned the credentials away (401 or 403), and
|
|
92
|
+
* `failed` for anything else that kept a batch out - a 429, an unreachable
|
|
93
|
+
* collector, any other status, a fault in the worker. A batch that got in
|
|
94
|
+
* says so with its degraded verdict instead.
|
|
95
|
+
*
|
|
96
|
+
* Read for OpenTelemetry interop, which runs only while the collector takes
|
|
97
|
+
* this app's telemetry - see `ObserveAgentSharedBuffer.isIngesting`.
|
|
98
|
+
*/
|
|
99
|
+
export const NOT_INGESTED_MESSAGE_PREFIX = "observe:not-ingested=";
|
|
100
|
+
/** Why a batch did not get in, or null if this is not that line. */
|
|
101
|
+
export function parseNotIngestedMessage(msg) {
|
|
102
|
+
if (!msg.startsWith(NOT_INGESTED_MESSAGE_PREFIX)) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const reason = msg.slice(NOT_INGESTED_MESSAGE_PREFIX.length);
|
|
106
|
+
return reason === "refused" || reason === "failed" ? reason : null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* How long batches may keep failing to get in before the collector counts as
|
|
110
|
+
* no longer taking this app's telemetry - a collector restarting, a network
|
|
111
|
+
* blip, a short rate-limit pause. Refused credentials end it at once.
|
|
112
|
+
*/
|
|
113
|
+
export const NOT_INGESTED_GRACE_MS = 60 * 1000;
|
|
89
114
|
/**
|
|
90
115
|
* Duration past which the collector treats an execution as notable, in
|
|
91
116
|
* milliseconds.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEGRADED_MESSAGE_PREFIX, PAUSED_MESSAGE_PREFIX, } from "./degraded-ingest.protocol.js";
|
|
1
|
+
import { DEGRADED_MESSAGE_PREFIX, NOT_INGESTED_MESSAGE_PREFIX, PAUSED_MESSAGE_PREFIX, } from "./degraded-ingest.protocol.js";
|
|
2
2
|
import { detachedObserveWorker } from "./detached-observe-worker.js";
|
|
3
3
|
import { createTelemetrySanitizer, SECTION_SHAPES, } from "./telemetry-wire-contract.js";
|
|
4
4
|
import { describeIngestRefusal } from "../utils/ingest-refusal.util.js";
|
|
@@ -27,6 +27,7 @@ export function detachedWorkerData(input) {
|
|
|
27
27
|
wireShapes: SECTION_SHAPES,
|
|
28
28
|
degradedPrefix: DEGRADED_MESSAGE_PREFIX,
|
|
29
29
|
pausedPrefix: PAUSED_MESSAGE_PREFIX,
|
|
30
|
+
notIngestedPrefix: NOT_INGESTED_MESSAGE_PREFIX,
|
|
30
31
|
sdkVersion: readSdkVersion(),
|
|
31
32
|
};
|
|
32
33
|
return { sharedBuffer: input.sharedBuffer, config };
|
|
@@ -23,6 +23,8 @@ export interface DetachedWorkerConfig {
|
|
|
23
23
|
degradedPrefix: string;
|
|
24
24
|
/** `PAUSED_MESSAGE_PREFIX`, as data, for the same reason. */
|
|
25
25
|
pausedPrefix: string;
|
|
26
|
+
/** `NOT_INGESTED_MESSAGE_PREFIX`, as data, for the same reason. */
|
|
27
|
+
notIngestedPrefix: string;
|
|
26
28
|
/**
|
|
27
29
|
* This package's version (`readSdkVersion`), read on the main thread: the
|
|
28
30
|
* worker runs as eval'd source and cannot resolve a manifest of its own.
|
|
@@ -51,6 +51,7 @@ describeRefusal) => {
|
|
|
51
51
|
// that `parseDegradedMessage` still matches.
|
|
52
52
|
const degradedPrefix = config.degradedPrefix;
|
|
53
53
|
const pausedPrefix = config.pausedPrefix;
|
|
54
|
+
const notIngestedPrefix = config.notIngestedPrefix;
|
|
54
55
|
/**
|
|
55
56
|
* Built here, used only when the collector answers 400. The shapes travel
|
|
56
57
|
* through `workerData` (they are plain JSON); the factory travels as source.
|
|
@@ -367,6 +368,7 @@ describeRefusal) => {
|
|
|
367
368
|
const retryBody = await retry.text().catch(() => "");
|
|
368
369
|
parentPort.postMessage(`Error: Telemetry batch was rejected (400), repaired (${summary}), and rejected again ` +
|
|
369
370
|
`(${retry.status})${retryBody ? ` - ${retryBody.slice(0, 500)}` : ""}. The batch was dropped.`);
|
|
371
|
+
parentPort.postMessage(`${notIngestedPrefix}failed`);
|
|
370
372
|
}
|
|
371
373
|
return true;
|
|
372
374
|
}
|
|
@@ -431,6 +433,7 @@ describeRefusal) => {
|
|
|
431
433
|
: `Error: Could not reach the collector at ${telemetryUrl}` +
|
|
432
434
|
(reason ? ` (${reason})` : "") +
|
|
433
435
|
`. Check that it is running and that \`endpoint\` points at it.`);
|
|
436
|
+
parentPort.postMessage(`${notIngestedPrefix}failed`);
|
|
434
437
|
// Discarded rather than retried - `clearBuffer` in `finally` - which
|
|
435
438
|
// is the right call for a fixed-size buffer the application is still
|
|
436
439
|
// writing into: holding it for a retry would block every batch behind
|
|
@@ -451,6 +454,7 @@ describeRefusal) => {
|
|
|
451
454
|
// The slot is left alone until then, which a final flush would
|
|
452
455
|
// otherwise read as a send still in progress.
|
|
453
456
|
parentPort.postMessage(`${pausedPrefix}${pausedUntil}`);
|
|
457
|
+
parentPort.postMessage(`${notIngestedPrefix}refused`);
|
|
454
458
|
// Said plainly, and once. The batch is well-formed and the
|
|
455
459
|
// credentials are not accepted for this application; left as a
|
|
456
460
|
// generic transport failure this reads as a network problem, and the
|
|
@@ -476,6 +480,7 @@ describeRefusal) => {
|
|
|
476
480
|
// The slot is left alone until then, which a final flush would
|
|
477
481
|
// otherwise read as a send still in progress.
|
|
478
482
|
parentPort.postMessage(`${pausedPrefix}${pausedUntil}`);
|
|
483
|
+
parentPort.postMessage(`${notIngestedPrefix}failed`);
|
|
479
484
|
// The body says which refusal this is - a quota, a quota frozen by
|
|
480
485
|
// a declined payment, or a rate cap - and each needs a different
|
|
481
486
|
// fix from the operator. Parsed defensively: a rate-cap body is
|
|
@@ -501,6 +506,7 @@ describeRefusal) => {
|
|
|
501
506
|
const errorBody = await response.text().catch(() => "");
|
|
502
507
|
parentPort.postMessage(`Error: Failed to send data. ${response.statusText} (${response.status})` +
|
|
503
508
|
(errorBody ? ` - ${errorBody.slice(0, 500)}` : ""));
|
|
509
|
+
parentPort.postMessage(`${notIngestedPrefix}failed`);
|
|
504
510
|
return true;
|
|
505
511
|
}
|
|
506
512
|
// Accepted, so whatever refused these credentials no longer does: a
|
|
@@ -572,6 +578,7 @@ describeRefusal) => {
|
|
|
572
578
|
(causeText === undefined ? "" : ` (cause: ${causeText})`) +
|
|
573
579
|
`. This is most likely a fault in the observe agent rather than a ` +
|
|
574
580
|
`connectivity problem; please report it.`);
|
|
581
|
+
parentPort.postMessage(`${notIngestedPrefix}failed`);
|
|
575
582
|
return true;
|
|
576
583
|
}
|
|
577
584
|
finally {
|
|
@@ -84,6 +84,17 @@ export declare class ObserveAgentSharedBuffer {
|
|
|
84
84
|
* not a moment longer.
|
|
85
85
|
*/
|
|
86
86
|
private errorsOnly;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the collector is taking this app's telemetry - see `isIngesting`.
|
|
89
|
+
* False until it accepts a first batch: what has not been shown to reach
|
|
90
|
+
* NestJS Observe does not count as reaching it.
|
|
91
|
+
*/
|
|
92
|
+
private ingesting;
|
|
93
|
+
/**
|
|
94
|
+
* When batches began failing to get in, since the last one that did; zero
|
|
95
|
+
* while they get in.
|
|
96
|
+
*/
|
|
97
|
+
private failingSince;
|
|
87
98
|
/**
|
|
88
99
|
* Requests and jobs that errors-only ingest withheld from the batch being
|
|
89
100
|
* built, cleared with it.
|
|
@@ -115,6 +126,31 @@ export declare class ObserveAgentSharedBuffer {
|
|
|
115
126
|
isDegraded(): boolean;
|
|
116
127
|
/** Whether only server errors are being sent, until the same window lapses. */
|
|
117
128
|
isErrorsOnly(): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Whether the collector is taking this app's telemetry: from the first
|
|
131
|
+
* batch it accepts, until it refuses the app's credentials, the worker
|
|
132
|
+
* stops, or batches have kept failing to get in for
|
|
133
|
+
* `NOT_INGESTED_GRACE_MS` - and again from the next batch it accepts.
|
|
134
|
+
*
|
|
135
|
+
* OpenTelemetry interop runs on it (see `openTelemetry`): the agent reads
|
|
136
|
+
* and sends `traceparent`, and follows an OpenTelemetry SDK in the process,
|
|
137
|
+
* only while it is also reporting to NestJS Observe. So an agent that sends
|
|
138
|
+
* Observe nothing - `enabled: false`, no credentials, credentials the
|
|
139
|
+
* collector refuses - never turns it on.
|
|
140
|
+
*/
|
|
141
|
+
isIngesting(): boolean;
|
|
142
|
+
/** The collector accepted a batch, whatever it then kept of it. */
|
|
143
|
+
recordAccepted(): void;
|
|
144
|
+
/** The collector refused the app's credentials. */
|
|
145
|
+
recordRefused(): void;
|
|
146
|
+
/**
|
|
147
|
+
* A batch did not get in - see `NotIngestedReason`. `pausedUntil` is when a
|
|
148
|
+
* paused worker sends again: nothing gets in before then, so a pause longer
|
|
149
|
+
* than the grace ends ingesting at once rather than after it.
|
|
150
|
+
*/
|
|
151
|
+
recordFailed(pausedUntil?: number, now?: number): void;
|
|
152
|
+
/** The worker stopped; a restarted one has to get a batch in again. */
|
|
153
|
+
recordStopped(): void;
|
|
118
154
|
/**
|
|
119
155
|
* What errors-only ingest makes of one execution: whether it is sent.
|
|
120
156
|
*
|