@nestjs/observe 0.3.4 → 0.3.5

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
@@ -245,7 +245,7 @@ Once the module and the instrument are in place, the agent reports, with no furt
245
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.
246
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.
247
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.
248
- - **The release it is running**, so Releases, regressions and fix verification work without a version threaded through the build: `OBSERVE_SERVICE_VERSION` if the environment sets it, else the commit a platform or CI job exposes (Vercel, Render, Railway, Heroku, GitHub Actions, GitLab CI and others), else the commit checked out where the process runs, else a Cloud Run or Azure Container Apps revision. A container image usually carries none of these, so hand it the commit at build time - `ARG GIT_SHA` then `ENV OBSERVE_SERVICE_VERSION=$GIT_SHA`. `serviceVersion` names the release yourself; `serviceVersion: false` reports none.
248
+ - **The release it is running**, so Releases, regressions and fix verification work without a version threaded through the build: `OBSERVE_SERVICE_VERSION` if the environment sets it, else the commit a platform or CI job exposes (Vercel, Render, Railway, Heroku, GitHub Actions, GitLab CI and others), else the commit checked out where the process runs, else a Cloud Run or Azure Container Apps revision. A container image usually carries none of these, so hand it the commit at build time - `ARG GIT_SHA` then `ENV OBSERVE_SERVICE_VERSION=$GIT_SHA`. `serviceVersion` names the release yourself, in at most 50 characters - a longer one is cut to fit, with a warning at startup; `serviceVersion: false` reports none.
249
249
 
250
250
  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 }`.
251
251
 
@@ -274,6 +274,37 @@ ObserveModule.forRoot({
274
274
 
275
275
  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]`.
276
276
 
277
+ ## Declaring objectives in code
278
+
279
+ `@Objective()` states what a route promises, next to the handler that has to keep it, and Observe turns each promise into an [SLO](https://www.observe.nestjs.com/documentation/slos). The objective is written, reviewed and versioned with the route it covers:
280
+
281
+ ```ts
282
+ import { Objective } from "@nestjs/observe";
283
+
284
+ @Controller("orders")
285
+ export class OrdersController {
286
+ @Post()
287
+ @Objective({ availability: 99.9, latency: { underMs: 300, target: 99 } })
288
+ create(@Body() dto: CreateOrderDto) {
289
+ return this.ordersService.create(dto);
290
+ }
291
+ }
292
+ ```
293
+
294
+ - `availability` - the percentage of requests that don't fail with an unhandled error: `99.9` for three nines.
295
+ - `latency` - `{ underMs, target }`: `target` percent of requests finish in under `underMs` milliseconds.
296
+ - `windowDays` - the rolling window it is judged over: 7, 14, 28 (the default) or 30 days.
297
+ - `name` - what the dashboard calls it, instead of the route and the promise.
298
+
299
+ Each promise becomes its own SLO, scoped to the application and the route: `POST /orders availability` and `POST /orders under 300ms` above. The route is read from the first request the handler serves, so a global prefix, URI versioning and `RouterModule` paths come out right, and the SLO appears once the route has had traffic. From then on:
300
+
301
+ - **The code owns it.** Change a target, a window or a name and deploy, and the same SLO follows. The dashboard marks it **in code**, names the handler and the release that last declared it, and doesn't edit it. A new latency threshold is a new promise, so it becomes a new SLO.
302
+ - **A delete in the dashboard doesn't last** while the decorator is there: the agent restates each route's objectives hourly, and a missing SLO is made again. To retire one, remove the decorator, then delete the SLO.
303
+
304
+ Declarations are checked when the application starts, and whatever fails is logged rather than sent. Targets run from 90 to 99.999, `underMs` is whole milliseconds up to 600000, and a handler carries at most ten objectives; a field other than these four is left out. A handler mounted on several routes - `@Get(["catalog", "products"])`, or a controller answering two versions - isn't declared at all, because an SLO watches one route: give each route a handler of its own.
305
+
306
+ SLOs need a plan that has them - Scale or Enterprise. On any other plan, declarations are sent and ignored. The [documentation](https://www.observe.nestjs.com/documentation/sdk#declaring-objectives-in-code) has the rest.
307
+
277
308
  ## Optional peer dependencies
278
309
 
279
310
  Protocol integrations are only loaded when you use them, and their packages are optional peers: