@nestjs/observe 0.3.27 → 0.3.28

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.
@@ -150,6 +150,21 @@ function isCryptoHandle(instance) {
150
150
  * - `@nestjs/config`'s `ConfigService` keeps what an application calls. Each
151
151
  * `get` made four or five more spans of its private helpers - 2.7M of its
152
152
  * 4.6M a day, in 220 projects.
153
+ * - `@nestjs/throttler`'s `ThrottlerGuard` keeps `canActivate`, and its
154
+ * in-memory `ThrottlerStorageService` nothing. Per named throttler, every
155
+ * request made 19 more spans: `resolveValue` and `toNumber` three times
156
+ * each, `handleRequest`, `getRequestResponse`, `setResponseHeader` three
157
+ * times, and `increment` with seven calls of the store's helpers - with
158
+ * `shouldSkip`, 40 a request for two throttlers where one is kept now. They
159
+ * were in 61 to 77 of 187 active projects, about 1.5M a week, and up to ~50
160
+ * of the events a health-check-only app was billed for each probe.
161
+ * The store is a `Map` and a timer: `increment` does no I/O, so its time is
162
+ * all in the `canActivate` span already. A store that does, such as a Redis
163
+ * one, is another class and keeps its own spans and its client's.
164
+ *
165
+ * An application's subclass - a `GqlThrottlerGuard` overriding
166
+ * `getRequestResponse`, a guard overriding `getTracker` or `shouldSkip` -
167
+ * keeps a span for each method it overrides.
153
168
  *
154
169
  * Folding cannot reach any of them (`collapseRepeatedSpans`), because each
155
170
  * repeats only a few times under its parent.
@@ -178,6 +193,17 @@ const PARTLY_TRACED_CLASSES = new Map([
178
193
  traced: new Set(["get", "getOrThrow", "set", "setEnvFilePaths"]),
179
194
  },
180
195
  ],
196
+ // `throwThrottlingException` is on every ThrottlerGuard from 4.x to 6.8,
197
+ // and `fireHitCount` on every ThrottlerStorageService since 6.0, which
198
+ // covers every release that supports Nest 11 and 12.
199
+ [
200
+ "ThrottlerGuard",
201
+ {
202
+ marker: "throwThrottlingException",
203
+ traced: new Set(["canActivate"]),
204
+ },
205
+ ],
206
+ ["ThrottlerStorageService", { marker: "fireHitCount", traced: new Set() }],
181
207
  ]);
182
208
  /**
183
209
  * The methods a prototype's class keeps traced, if it is one of those.
@@ -26,7 +26,9 @@ export function patchMysql2(mysql2, recorder) {
26
26
  args[last] = AsyncResource.bind(args[last]);
27
27
  }
28
28
  const sql = typeof first === "string" ? first : first?.sql;
29
- if (typeof sql !== "string") {
29
+ // Asked before the statement is described: an untraced or sampled-out
30
+ // call should not pay for tokenizing it.
31
+ if (typeof sql !== "string" || !recorder.isRecording()) {
30
32
  return original.apply(this, args);
31
33
  }
32
34
  const { operation, statement } = describeSqlStatement(sql, "mysql");
@@ -29,6 +29,11 @@ export function patchPg(pg, recorder) {
29
29
  if (typeof text !== "string" || typeof config?.submit === "function") {
30
30
  return original.apply(this, args);
31
31
  }
32
+ // Asked before the statement is described: an untraced or sampled-out
33
+ // call should not pay for tokenizing it.
34
+ if (!recorder.isRecording()) {
35
+ return original.apply(this, args);
36
+ }
32
37
  const { operation, statement } = describeSqlStatement(text, "postgresql");
33
38
  const span = recorder.open("pg", operation, {
34
39
  "db.system": "postgresql",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/observe",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "description": "Observability and APM agent for NestJS - traces, runtime metrics and custom metrics",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://observe.nestjs.com",
@@ -125,7 +125,7 @@
125
125
  }
126
126
  },
127
127
  "devDependencies": {
128
- "@apollo/server": "5.5.1",
128
+ "@apollo/server": "5.5.2",
129
129
  "@as-integrations/express5": "1.1.2",
130
130
  "@commitlint/cli": "21.2.4",
131
131
  "@commitlint/config-angular": "21.2.4",
@@ -148,6 +148,7 @@
148
148
  "@nestjs/platform-ws": "12.3.3",
149
149
  "@nestjs/schedule": "12.0.1",
150
150
  "@nestjs/testing": "12.3.3",
151
+ "@nestjs/throttler": "6.8.0",
151
152
  "@nestjs/websockets": "12.3.3",
152
153
  "@opentelemetry/api": "1.9.1",
153
154
  "@opentelemetry/auto-instrumentations-node": "0.81.0",
@@ -175,7 +176,7 @@
175
176
  "husky": "9.1.7",
176
177
  "ioredis": "6.0.0",
177
178
  "kafkajs": "2.2.4",
178
- "lint-staged": "17.6.0",
179
+ "lint-staged": "17.6.1",
179
180
  "mongodb": "7.6.0",
180
181
  "mongoose": "9.10.1",
181
182
  "mssql": "12.7.13",