@nestjs/observe 0.1.10 → 0.2.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 CHANGED
@@ -1,23 +1,59 @@
1
1
  <p align="center">
2
- <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
2
+ <a href="https://observe.nestjs.com" target="_blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="NestJS Logo" /></a>
3
3
  </p>
4
4
 
5
- <p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
6
- <p align="center">
7
- <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/common.svg" alt="NPM Version" /></a>
8
- <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/common.svg" alt="Package License" /></a>
9
- <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
10
- <a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
11
- <a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
12
- <a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
13
- <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
14
- <a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
15
- <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
16
- <a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
5
+ <p align="center">Auto-instrumented observability for <a href="https://nestjs.com" target="_blank">NestJS</a> applications — traces, errors, logs, jobs and profiles, with no manual span wiring.</p>
17
6
 
18
- ## Description
7
+ <p align="center">
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
+ <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="https://www.npmjs.com/package/@nestjs/observe"><img src="https://img.shields.io/npm/l/@nestjs/observe.svg" alt="Package License" /></a>
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://observe-demo.nestjs.com"><b>Live demo</b></a> ·
15
+ <a href="https://observe.nestjs.com"><b>Website</b></a> ·
16
+ <a href="https://docs.nestjs.com">Documentation</a>
17
+ </p>
18
+
19
+ ## What it is
20
+
21
+ `@nestjs/observe` instruments a NestJS application from the inside. It hooks
22
+ into Nest's own request lifecycle — controllers, interceptors, guards, queue
23
+ consumers, resolvers — rather than wrapping a generic Node.js agent around the
24
+ framework, so a trace is named in the vocabulary you wrote the code in: classes
25
+ and methods, not just HTTP routes.
26
+
27
+ Install it, set two environment variables, and the application starts reporting:
28
+
29
+ - **Requests, jobs and RPC calls** — HTTP, GraphQL, microservices (RPC/gRPC),
30
+ BullMQ consumers and `@nestjs/schedule` cron, interval and timeout jobs.
31
+ - **Distributed traces** with per-span self time, correlated across services.
32
+ - **Errors**, grouped by fingerprint, with the source frame and the trace that
33
+ produced them.
34
+ - **Logs**, correlated to the request that wrote them.
35
+ - **Runtime and custom metrics**, plus on-demand **CPU profiles**.
36
+
37
+ Telemetry is serialised on a detached worker thread and shipped from there, so
38
+ the request path is untouched by the reporting.
39
+
40
+ ### Why not just OpenTelemetry?
41
+
42
+ OpenTelemetry is the right answer when you need vendor neutrality across a
43
+ polyglot estate, and this agent is not a replacement for it. It is a different
44
+ trade: no collector to run, no exporter pipeline to configure, no manual
45
+ instrumentation for the framework's own lifecycle — and spans named after your
46
+ Nest classes and methods, which generic Node.js instrumentation cannot produce
47
+ because it cannot see them. If you would otherwise spend a week wiring a
48
+ collector and still not know which provider spent the time, this is the
49
+ shortcut.
19
50
 
20
- `@nestjs/observe` is an observability module for [NestJS](https://nestjs.com) applications. It instruments HTTP, GraphQL, microservice (RPC), BullMQ queue handlers, and `@nestjs/schedule` cron/interval/timeout jobs, collects traces, runtime metrics, custom metrics, and CPU profiles, and ships them to a collector from a detached worker thread so the request path stays untouched.
51
+ ## Seeing it before installing
52
+
53
+ **[observe-demo.nestjs.com](https://observe-demo.nestjs.com)** is the whole
54
+ dashboard running over a generated dataset from a busy service — real request
55
+ volumes, traces with waterfalls, errors, jobs and alerts. No signup, nothing to
56
+ install.
21
57
 
22
58
  ```bash
23
59
  $ npm install @nestjs/observe
@@ -113,6 +149,58 @@ export class ObserveConfig implements ObserveOptionsFactory {
113
149
  }
114
150
  ```
115
151
 
152
+ ## Repeated spans
153
+
154
+ Every provider is instrumented by default, framework-owned ones included, and
155
+ some of them run in loops the application never wrote. A `ValidationPipe`
156
+ registered through `APP_PIPE` runs once per argument of every GraphQL field
157
+ resolver, so a single list query produces hundreds or thousands of identical
158
+ sibling spans under the operation - each of them a metered event, and together
159
+ saying nothing a count would not.
160
+
161
+ The agent collapses those before a trace leaves the process. When more than
162
+ `threshold` siblings under one parent share a class and method:
163
+
164
+ - the slowest `keepSlowest` of them stay as ordinary spans,
165
+ - any instance that errored stays as an ordinary span, whatever its duration,
166
+ - the rest are replaced by one node that carries how many calls it stands for
167
+ and the **sum** of their durations.
168
+
169
+ Nothing is skipped outright and no duration cut-off is involved: what
170
+ validation costs is specific to each application, and the calls that explain a
171
+ slow request are exactly the ones kept whole. The collapsed node is metered as
172
+ a single event.
173
+
174
+ ```ts
175
+ ObserveModule.forRoot({
176
+ // ...
177
+ spanCollapse: { threshold: 20, keepSlowest: 3 }, // the defaults
178
+ // spanCollapse: false, // ship every span
179
+ });
180
+ ```
181
+
182
+ What a collapsed node means:
183
+
184
+ - Its `observe.collapsed` tag is the number of calls it replaces, and its name
185
+ reads `ValidationPipe.transform ×27` so a waterfall shows an aggregate rather
186
+ than one more call.
187
+ - `duration` is the sum of the replaced calls' durations, not the wall-clock
188
+ span between the first and the last. That is what keeps the parent's self
189
+ time - its duration minus its children's - exactly what it was.
190
+ - `startOffset` is the earliest replaced call's, and the node sits where that
191
+ call sat among its siblings. Ordering _among_ the replaced calls is lost,
192
+ which is acceptable for calls that are identical by construction.
193
+ - The replaced calls' own children are carried onto the node, so the time of
194
+ whatever they called is still attributed to the class that spent it; a
195
+ repeated frame beneath them collapses in turn.
196
+ - Tags of the replaced calls are dropped. Manual spans are never collapsed.
197
+
198
+ The wire format is unchanged: the count travels inside `t` (tags), next to `n`
199
+ name, `o` origin, `d` duration, `e` error, `c` className, `m` methodKey, `ch`
200
+ children, `s` spanId and `so` startOffset. A collector that does not know the
201
+ tag stores it like any other and attributes the node as one call of its class
202
+ rather than as the number it carries.
203
+
116
204
  ## Optional peer dependencies
117
205
 
118
206
  Protocol integrations are only loaded when you use them, and their packages are optional peers:
@@ -146,9 +234,11 @@ const { createObserveModule } = require("@nestjs/observe");
146
234
 
147
235
  ## Stay in touch
148
236
 
149
- - Website - [https://nestjs.com](https://nestjs.com/)
150
- - Twitter - [@nestframework](https://twitter.com/nestframework)
237
+ - Dashboard — [observe.nestjs.com](https://observe.nestjs.com)
238
+ - Live demo — [observe-demo.nestjs.com](https://observe-demo.nestjs.com)
239
+ - Documentation — [docs.nestjs.com](https://docs.nestjs.com)
240
+ - Twitter — [@nestframework](https://twitter.com/nestframework)
151
241
 
152
242
  ## License
153
243
 
154
- Nest is [MIT licensed](LICENSE).
244
+ `@nestjs/observe` is [MIT licensed](LICENSE).