Skip to content

Release 0.3.0

Choose a tag to compare

@kamilmysliwiec kamilmysliwiec released this 21 Sep 08:19
· 380 commits to master since this release
4e3b524

What's new?

Database queries and outbound HTTP, with no code changes

  • Queries made through pg, mysql2 and mongodb are recorded as spans under the provider method that ran them. The drivers are instrumented rather than the ORMs, so anything built on them is covered: TypeORM, Drizzle, MikroORM and Mongoose are tested in this repository, and Knex and Sequelize go through the same calls. Spans are named after the verb and table (SELECT users) and carry the statement with every literal removed. Bound parameters are never read.
  • Outbound calls made with fetch/undici or node:http/https (so Axios too) are recorded as POST api.stripe.com, with sensitive query parameters masked.
  • The current trace id is forwarded as x-request-id, so a downstream service running the agent continues the same trace. A header you set yourself is never overwritten.
  • Query and outbound-HTTP spans are not billed as events. Turn them off with outgoing: false, or one side with outgoing: { database: false } or outgoing: { http: false }.

WebSocket gateways

  • Each message handled by a @SubscribeMessage() method is reported as an operation (GatewayClass:pattern), on both the ws and socket.io adapters.
  • New ws options: ignore, tags, setAttributes, getUserId.
  • @nestjs/websockets is an optional peer.

One trace across queues and services

  • 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 jobs start their own.
  • Legacy Bull (@nestjs/bull and bull) is now supported alongside BullMQ, as an optional peer.
  • Microservice handlers adopt the x-request-id the calling service attached to the packet metadata. It is validated the same way as the HTTP header.

Capture for failed and slow requests

  • http.capture records the inputs of a request that failed, or one slower than slowerThanMs. It never records ordinary traffic.
  • By default it records a short allow-list of headers that neither authenticate nor identify the caller, and no body.
  • body: true adds the body, capped at 2 KB (configurable up to 16 KB).
  • Everything recorded goes through redaction first. capture: false turns the feature off.

Security

  • Source context: forged stack frames.
    • An error message containing a newline followed by a frame-shaped line was read as a real stack frame.
    • A request parameter interpolated into a validation or driver error could therefore choose which application file had its source attached to the error.
    • Frames are now read only from the lines that follow the error's own message.
    • Code-frame lines now go through the redactor before they are sent.
  • Source context: event-loop blocking. The frame-matching pattern was quadratic on a crafted line: a 100 KB line took about 3 s. It is replaced with a linear parser, and line length and frame count are capped.
  • The source-map cache is now bounded.
  • Symlinks are resolved before the containment check, so a symlink under the app root can no longer point the reader at a file outside it.
  • Redaction: credential key names.
    • Credential keys are now matched by what the name ends in, so resetToken, client_secret, X-Amz-Signature, x-api-key and jwt are masked in URLs, log attributes, and captured headers and bodies.
    • One shared list replaces two that had drifted apart.
    • redaction.keys now applies to URL query strings as well.
  • GraphQL number literals are blanked from the recorded document the same way string literals already were.

If you run with sourceContext enabled (the default), upgrading is recommended.

Behaviour changes to be aware of

  • Recorded GraphQL documents now show _ in place of inline numbers, so orders(first: 10) and orders(first: 20) group as one shape. Existing groupings for such queries will shift once.
  • More URL parameters are masked than before. Any key ending in token, secret, signature and similar is masked, which includes pagination params such as pageToken.
  • An error whose message is reassigned after construction no longer gets code frames.

Full Changelog: 0.2.3...0.3.0