@nestjs/observe 0.2.3 → 0.3.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.
Files changed (62) hide show
  1. package/README.md +38 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/agent/telemetry-wire-contract.js +1 -0
  4. package/dist/encoders/request-snapshot.encoder.d.ts +1 -0
  5. package/dist/encoders/request-snapshot.encoder.js +1 -0
  6. package/dist/instrument/create-instance-decorator.instrument.js +2 -2
  7. package/dist/interfaces/observe-options.interface.d.ts +90 -4
  8. package/dist/interfaces/request-snapshot.interface.d.ts +8 -0
  9. package/dist/observe.constants.d.ts +16 -0
  10. package/dist/observe.constants.js +16 -0
  11. package/dist/observe.module.js +48 -4
  12. package/dist/outgoing/http.integration.d.ts +36 -0
  13. package/dist/outgoing/http.integration.js +127 -0
  14. package/dist/outgoing/mongodb.integration.d.ts +38 -0
  15. package/dist/outgoing/mongodb.integration.js +141 -0
  16. package/dist/outgoing/mysql2.integration.d.ts +20 -0
  17. package/dist/outgoing/mysql2.integration.js +89 -0
  18. package/dist/outgoing/outgoing-observe-agent.service.d.ts +17 -0
  19. package/dist/outgoing/outgoing-observe-agent.service.js +123 -0
  20. package/dist/outgoing/outgoing-span.recorder.d.ts +54 -0
  21. package/dist/outgoing/outgoing-span.recorder.js +94 -0
  22. package/dist/outgoing/patch-method.util.d.ts +15 -0
  23. package/dist/outgoing/patch-method.util.js +29 -0
  24. package/dist/outgoing/pg.integration.d.ts +22 -0
  25. package/dist/outgoing/pg.integration.js +66 -0
  26. package/dist/outgoing/sql-statement.util.d.ts +21 -0
  27. package/dist/outgoing/sql-statement.util.js +48 -0
  28. package/dist/protocols/bull-observe-agent.service.d.ts +28 -0
  29. package/dist/protocols/bull-observe-agent.service.js +130 -0
  30. package/dist/protocols/graphql-observe-agent.service.js +5 -2
  31. package/dist/protocols/graphql-operation-parser.d.ts +4 -4
  32. package/dist/protocols/graphql-operation-parser.js +28 -4
  33. package/dist/protocols/http-observe-agent.service.js +26 -7
  34. package/dist/protocols/job-trace-runner.d.ts +77 -0
  35. package/dist/protocols/job-trace-runner.js +196 -0
  36. package/dist/protocols/queue-observe-agent.service.d.ts +9 -4
  37. package/dist/protocols/queue-observe-agent.service.js +36 -95
  38. package/dist/protocols/ws-observe-agent.service.d.ts +39 -0
  39. package/dist/protocols/ws-observe-agent.service.js +180 -0
  40. package/dist/services/logger-patcher.service.js +18 -5
  41. package/dist/services/operation-trace.registry.d.ts +17 -1
  42. package/dist/services/operation-trace.registry.js +39 -7
  43. package/dist/services/stdout-forwarder.service.d.ts +14 -4
  44. package/dist/services/stdout-forwarder.service.js +49 -25
  45. package/dist/services/trace-sampler.service.d.ts +4 -0
  46. package/dist/services/tracer.service.js +5 -3
  47. package/dist/utils/capture-request.util.d.ts +57 -0
  48. package/dist/utils/capture-request.util.js +116 -0
  49. package/dist/utils/default-trace-id-generator.util.d.ts +12 -0
  50. package/dist/utils/default-trace-id-generator.util.js +12 -1
  51. package/dist/utils/log-redactor.d.ts +20 -1
  52. package/dist/utils/log-redactor.js +54 -38
  53. package/dist/utils/optional-peer.util.d.ts +13 -0
  54. package/dist/utils/optional-peer.util.js +30 -0
  55. package/dist/utils/redact-url-query.d.ts +10 -1
  56. package/dist/utils/redact-url-query.js +16 -37
  57. package/dist/utils/sensitive-keys.d.ts +15 -0
  58. package/dist/utils/sensitive-keys.js +76 -0
  59. package/dist/utils/source-context.util.d.ts +6 -0
  60. package/dist/utils/source-context.util.js +113 -15
  61. package/dist/utils/source-map-resolver.util.js +12 -0
  62. package/package.json +35 -2
package/README.md CHANGED
@@ -201,6 +201,42 @@ children, `s` spanId and `so` startOffset. A collector that does not know the
201
201
  tag stores it like any other and attributes the node as one call of its class
202
202
  rather than as the number it carries.
203
203
 
204
+ ## What it records without any code
205
+
206
+ Once the module and the instrument are in place, the agent reports, with no further changes to your application:
207
+
208
+ - **Requests, GraphQL operations, RPC messages, WebSocket gateway messages, queue jobs and scheduled jobs**, each with its tree of provider method calls.
209
+ - **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
+ - **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.
212
+
213
+ 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
+
215
+ ## Capturing failed and slow requests
216
+
217
+ The inputs behind a failing request are usually the fastest way to reproduce it. The agent keeps them only for the requests worth it - never for ordinary traffic:
218
+
219
+ ```ts
220
+ ObserveModule.forRoot({
221
+ // ...
222
+ http: {
223
+ capture: {
224
+ // Also capture requests that took at least this long, failed or not.
225
+ slowerThanMs: 2000,
226
+ // Off by default: a body is your users' data. Capped at 2 KB unless
227
+ // you pass `{ maxBytes }` (at most 16 KB).
228
+ body: true,
229
+ // Defaults to a short list with nothing that authenticates or
230
+ // identifies anyone: accept, content-type, user-agent, ...
231
+ // Pass your own list, or `false` for none.
232
+ headers: ["content-type", "user-agent", "x-tenant-id"],
233
+ },
234
+ },
235
+ });
236
+ ```
237
+
238
+ 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]`.
239
+
204
240
  ## Optional peer dependencies
205
241
 
206
242
  Protocol integrations are only loaded when you use them, and their packages are optional peers:
@@ -208,6 +244,8 @@ Protocol integrations are only loaded when you use them, and their packages are
208
244
  - `@nestjs/microservices` - RPC/microservice instrumentation
209
245
  - `@nestjs/graphql` - GraphQL operation instrumentation
210
246
  - `@nestjs/bullmq` and `bullmq` - queue/job instrumentation
247
+ - `@nestjs/bull` and `bull` - the same, for legacy Bull
248
+ - `@nestjs/websockets` - WebSocket gateway instrumentation (`ws` and socket.io adapters)
211
249
  - `@nestjs/schedule` - scheduled job (`@Cron`, `@Interval`, `@Timeout`) instrumentation
212
250
 
213
251
  ## Test