@nestjs/observe 0.3.1 → 0.3.3

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
@@ -27,7 +27,8 @@ and methods, not just HTTP routes.
27
27
  Install it, set two environment variables, and the application starts reporting:
28
28
 
29
29
  - **Requests, jobs and RPC calls** — HTTP, GraphQL, microservices (RPC/gRPC),
30
- BullMQ consumers and `@nestjs/schedule` cron, interval and timeout jobs.
30
+ BullMQ (and BullMQ Pro) consumers and `@nestjs/schedule` cron, interval and
31
+ timeout jobs.
31
32
  - **Distributed traces** with per-span self time, correlated across services.
32
33
  - **Errors**, grouped by fingerprint, with the source frame and the trace that
33
34
  produced them.
@@ -201,6 +202,41 @@ children, `s` spanId and `so` startOffset. A collector that does not know the
201
202
  tag stores it like any other and attributes the node as one call of its class
202
203
  rather than as the number it carries.
203
204
 
205
+ ## Skipping spans for expected outcomes
206
+
207
+ Nest applications answer "not found", "not allowed" and "invalid input" by
208
+ throwing - `NotFoundException`, `ForbiddenException`, a `ValidationPipe`'s
209
+ `BadRequestException` - and every one of those requests ships the full tree of
210
+ calls it made, each span a metered event. `skipSpans` reports such requests
211
+ without their spans:
212
+
213
+ ```ts
214
+ ObserveModule.forRoot({
215
+ // ...
216
+ skipSpans: [400, 401, 403, 404],
217
+ // or decide per operation:
218
+ // skipSpans: ({ statusCode, duration }) => statusCode === 404 && duration < 1000,
219
+ });
220
+ ```
221
+
222
+ What stays and what goes:
223
+
224
+ - The request is still reported - route, status code, duration, user - so it
225
+ counts in every chart as before.
226
+ - Its error is still reported, stack included, so it appears on the Errors page
227
+ exactly as it did.
228
+ - The span tree underneath it is dropped before anything is serialized or
229
+ sent: the waterfall shows the request with nothing inside it, and its calls
230
+ are missing from the per-method numbers. A skipped request costs its own
231
+ event, plus its error's when it failed with one, and nothing more.
232
+
233
+ The status code is the one the request is reported with. Microservice, gRPC and
234
+ WebSocket handlers have no status of their own; they get one when they throw -
235
+ a Nest exception's own 4xx, or 500 - so `[404]` covers a message handler that
236
+ threw `NotFoundException` too. Jobs always keep their spans. The function form
237
+ is told `protocol`, `operationId`, `method`, `statusCode`, `duration` and
238
+ `errorClass`; if it throws, the spans are kept and the failure is logged once.
239
+
204
240
  ## What it records without any code
205
241
 
206
242
  Once the module and the instrument are in place, the agent reports, with no further changes to your application:
@@ -208,7 +244,7 @@ Once the module and the instrument are in place, the agent reports, with no furt
208
244
  - **Requests, GraphQL operations, RPC messages, WebSocket gateway messages, queue jobs and scheduled jobs**, each with its tree of provider method calls.
209
245
  - **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.
210
246
  - **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`, so a service that also runs the agent continues the same trace; a header you set yourself is never overwritten.
211
- - **Trace ids across queues**: a BullMQ 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.
247
+ - **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.
212
248
 
213
249
  Query and outbound-HTTP spans are not billed as events. Turn them off with `outgoing: false`, or one side with `outgoing: { database: false }` / `outgoing: { http: false }`.
214
250
 
@@ -244,6 +280,7 @@ Protocol integrations are only loaded when you use them, and their packages are
244
280
  - `@nestjs/microservices` - RPC/microservice instrumentation
245
281
  - `@nestjs/graphql` - GraphQL operation instrumentation
246
282
  - `@nestjs/bullmq` and `bullmq` - queue/job instrumentation
283
+ - `@taskforcesh/bullmq-pro` - the same, for BullMQ Pro, whether it is wired in through `@taskforcesh/nestjs-bullmq-pro` or through `@nestjs/bullmq` (`BullModule.workerClass = WorkerPro`)
247
284
  - `@nestjs/bull` and `bull` - the same, for legacy Bull
248
285
  - `@nestjs/websockets` - WebSocket gateway instrumentation (`ws` and socket.io adapters)
249
286
  - `@nestjs/schedule` - scheduled job (`@Cron`, `@Interval`, `@Timeout`) instrumentation