@nestjs/observe 0.2.2 → 0.3.0
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 +38 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/agent/detached-observe-worker.assembly.d.ts +18 -0
- package/dist/agent/detached-observe-worker.assembly.js +29 -0
- package/dist/agent/detached-observe-worker.d.ts +21 -0
- package/dist/agent/detached-observe-worker.js +74 -24
- package/dist/agent/observe-agent.shared-buffer.js +7 -5
- package/dist/agent/observe-agent.worker.js +17 -21
- package/dist/agent/telemetry-wire-contract.js +1 -0
- package/dist/encoders/remap-keys.util.js +6 -0
- package/dist/encoders/request-snapshot.encoder.d.ts +1 -0
- package/dist/encoders/request-snapshot.encoder.js +1 -0
- package/dist/instrument/create-instance-decorator.instrument.js +2 -2
- package/dist/interfaces/observe-options.interface.d.ts +97 -9
- package/dist/interfaces/request-snapshot.interface.d.ts +8 -0
- package/dist/observe.constants.d.ts +16 -0
- package/dist/observe.constants.js +16 -0
- package/dist/observe.module.js +55 -6
- package/dist/outgoing/http.integration.d.ts +36 -0
- package/dist/outgoing/http.integration.js +127 -0
- package/dist/outgoing/mongodb.integration.d.ts +38 -0
- package/dist/outgoing/mongodb.integration.js +141 -0
- package/dist/outgoing/mysql2.integration.d.ts +20 -0
- package/dist/outgoing/mysql2.integration.js +89 -0
- package/dist/outgoing/outgoing-observe-agent.service.d.ts +17 -0
- package/dist/outgoing/outgoing-observe-agent.service.js +123 -0
- package/dist/outgoing/outgoing-span.recorder.d.ts +54 -0
- package/dist/outgoing/outgoing-span.recorder.js +94 -0
- package/dist/outgoing/patch-method.util.d.ts +15 -0
- package/dist/outgoing/patch-method.util.js +29 -0
- package/dist/outgoing/pg.integration.d.ts +22 -0
- package/dist/outgoing/pg.integration.js +66 -0
- package/dist/outgoing/sql-statement.util.d.ts +21 -0
- package/dist/outgoing/sql-statement.util.js +48 -0
- package/dist/protocols/bull-observe-agent.service.d.ts +28 -0
- package/dist/protocols/bull-observe-agent.service.js +130 -0
- package/dist/protocols/graphql-observe-agent.service.js +5 -2
- package/dist/protocols/graphql-operation-parser.d.ts +6 -4
- package/dist/protocols/graphql-operation-parser.js +61 -6
- package/dist/protocols/http-observe-agent.service.js +26 -7
- package/dist/protocols/job-trace-runner.d.ts +77 -0
- package/dist/protocols/job-trace-runner.js +196 -0
- package/dist/protocols/queue-observe-agent.service.d.ts +9 -4
- package/dist/protocols/queue-observe-agent.service.js +36 -95
- package/dist/protocols/ws-observe-agent.service.d.ts +39 -0
- package/dist/protocols/ws-observe-agent.service.js +180 -0
- package/dist/services/operation-trace.registry.d.ts +35 -1
- package/dist/services/operation-trace.registry.js +68 -5
- package/dist/services/trace-sampler.service.d.ts +4 -0
- package/dist/services/tracer.service.js +5 -3
- package/dist/utils/capture-request.util.d.ts +57 -0
- package/dist/utils/capture-request.util.js +116 -0
- package/dist/utils/default-trace-id-generator.util.d.ts +12 -0
- package/dist/utils/default-trace-id-generator.util.js +12 -1
- package/dist/utils/log-redactor.d.ts +20 -1
- package/dist/utils/log-redactor.js +54 -38
- package/dist/utils/optional-peer.util.d.ts +13 -0
- package/dist/utils/optional-peer.util.js +30 -0
- package/dist/utils/redact-url-query.d.ts +10 -1
- package/dist/utils/redact-url-query.js +16 -37
- package/dist/utils/sensitive-keys.d.ts +15 -0
- package/dist/utils/sensitive-keys.js +76 -0
- package/dist/utils/source-context.util.d.ts +6 -0
- package/dist/utils/source-context.util.js +121 -15
- package/dist/utils/source-map-resolver.util.js +12 -0
- 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
|