@nestjs/observe 0.3.12 → 0.3.14
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 +65 -2
- package/dist/agent/degraded-ingest.protocol.d.ts +82 -26
- package/dist/agent/degraded-ingest.protocol.js +60 -19
- package/dist/agent/detached-observe-worker.js +31 -16
- package/dist/agent/observe-agent.shared-buffer.d.ts +54 -1
- package/dist/agent/observe-agent.shared-buffer.js +127 -22
- package/dist/agent/observe-agent.worker.d.ts +29 -0
- package/dist/agent/observe-agent.worker.js +80 -10
- package/dist/agent/telemetry-wire-contract.js +11 -1
- package/dist/encoders/request-snapshot.encoder.d.ts +1 -0
- package/dist/encoders/request-snapshot.encoder.js +1 -0
- package/dist/interfaces/observe-options.interface.d.ts +13 -1
- package/dist/interfaces/request-snapshot.interface.d.ts +13 -0
- package/dist/objectives/objectives.registry.d.ts +1 -0
- package/dist/objectives/objectives.registry.js +12 -0
- package/dist/outgoing/mssql.integration.d.ts +12 -0
- package/dist/outgoing/mssql.integration.js +248 -0
- package/dist/outgoing/mysql2.integration.js +1 -1
- package/dist/outgoing/outgoing-observe-agent.service.js +46 -8
- package/dist/outgoing/outgoing-span.recorder.d.ts +7 -0
- package/dist/outgoing/outgoing-span.recorder.js +15 -0
- package/dist/outgoing/pg.integration.js +1 -1
- package/dist/outgoing/sql-statement.util.d.ts +5 -1
- package/dist/outgoing/sql-statement.util.js +83 -10
- package/dist/protocols/http-observe-agent.service.js +9 -2
- package/dist/protocols/job-trace-runner.js +5 -0
- package/dist/services/node-runtime-metrics.service.js +1 -1
- package/dist/services/operation-trace.registry.d.ts +11 -0
- package/dist/services/operation-trace.registry.js +37 -1
- package/dist/services/stdout-forwarder.service.js +1 -1
- package/dist/services/trace-sampler.service.js +5 -0
- package/dist/services/tracer.service.d.ts +19 -0
- package/dist/services/tracer.service.js +61 -3
- package/dist/utils/ingest-refusal.util.d.ts +7 -5
- package/dist/utils/ingest-refusal.util.js +17 -5
- package/package.json +9 -4
|
@@ -18,6 +18,11 @@ let TraceSamplerService = class TraceSamplerService {
|
|
|
18
18
|
this.options = options;
|
|
19
19
|
}
|
|
20
20
|
shouldCapture(protocol, attributes) {
|
|
21
|
+
// Ahead of the sample rate: a disabled agent records nothing, whatever
|
|
22
|
+
// share of traces it was told to keep.
|
|
23
|
+
if (this.options.enabled === false) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
21
26
|
if (!this.options.tracesSampleRate) {
|
|
22
27
|
return true; // Always capture if sample rate is not set
|
|
23
28
|
}
|
|
@@ -15,6 +15,8 @@ export declare class TracerService<Store extends Record<string | symbol, unknown
|
|
|
15
15
|
private readonly counters;
|
|
16
16
|
private readonly gauges;
|
|
17
17
|
private readonly summaries;
|
|
18
|
+
private readonly logger;
|
|
19
|
+
private hasReportedUnusableOperationId;
|
|
18
20
|
constructor(operationTraceRegistry: OperationTraceRegistry, als: AsyncLocalStorage<Map<KeyOf<Store> | TraceKey, any>>, observeAgentSharedBuffer: ObserveAgentSharedBuffer, options: ObserveModuleOptionsWithDefaults);
|
|
19
21
|
/**
|
|
20
22
|
* Creates a new trace span with the given name and executes the provided callback within that span.
|
|
@@ -113,6 +115,23 @@ export declare class TracerService<Store extends Record<string | symbol, unknown
|
|
|
113
115
|
* propagate an id that simply isn't there yet.
|
|
114
116
|
*/
|
|
115
117
|
currentTraceId(): string | null;
|
|
118
|
+
/**
|
|
119
|
+
* Sets the operation id reported for the current request trace, in place of
|
|
120
|
+
* its route path, GraphQL root field or message pattern. Works from anywhere
|
|
121
|
+
* in the request - middleware, guard, interceptor or handler - and a later
|
|
122
|
+
* call replaces an earlier one.
|
|
123
|
+
*
|
|
124
|
+
* Use a stable, bounded name, not a per-request value, so requests aggregate
|
|
125
|
+
* together. The name is trimmed and cut to 255 characters, and anything but
|
|
126
|
+
* a non-blank string is ignored. Does nothing when there is no active trace
|
|
127
|
+
* or the request is not recorded.
|
|
128
|
+
*/
|
|
129
|
+
setOperationId(operationId: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* An unusable name comes from the same call site on every request, so it is
|
|
132
|
+
* reported once rather than once per request.
|
|
133
|
+
*/
|
|
134
|
+
private reportUnusableOperationId;
|
|
116
135
|
/**
|
|
117
136
|
* Sets an attribute on the current trace.
|
|
118
137
|
* For example, you can use this to add metadata to the current request trace for later use and retrieval.
|
|
@@ -10,7 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
var TracerService_1;
|
|
14
|
+
import { Inject, Injectable, Logger } from "@nestjs/common";
|
|
14
15
|
import { AsyncLocalStorage } from "async_hooks";
|
|
15
16
|
import { ObserveAgentSharedBuffer } from "../agent/observe-agent.shared-buffer.js";
|
|
16
17
|
import { Gauge, Summary } from "../custom-metrics/index.js";
|
|
@@ -18,7 +19,13 @@ import { Counter } from "../custom-metrics/counter.js";
|
|
|
18
19
|
import { TraceSpanDelegate } from "../trace-span.delegate.js";
|
|
19
20
|
import { CALLER_METADATA_KEY, OBSERVE_OPTIONS, TRACE_REGISTRY_KEY, } from "../observe.constants.js";
|
|
20
21
|
import { OperationTraceRegistry } from "./operation-trace.registry.js";
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Longest operation id the collector stores, counted by code point as it
|
|
24
|
+
* counts. A longer one is cut there anyway; cut here, a name built from a
|
|
25
|
+
* request body cannot grow the batch it rides in without bound.
|
|
26
|
+
*/
|
|
27
|
+
const MAX_OPERATION_ID_LENGTH = 255;
|
|
28
|
+
let TracerService = TracerService_1 = class TracerService {
|
|
22
29
|
operationTraceRegistry;
|
|
23
30
|
als;
|
|
24
31
|
observeAgentSharedBuffer;
|
|
@@ -29,6 +36,8 @@ let TracerService = class TracerService {
|
|
|
29
36
|
counters = new Map();
|
|
30
37
|
gauges = new Map();
|
|
31
38
|
summaries = new Map();
|
|
39
|
+
logger = new Logger(TracerService_1.name);
|
|
40
|
+
hasReportedUnusableOperationId = false;
|
|
32
41
|
constructor(operationTraceRegistry, als, observeAgentSharedBuffer, options) {
|
|
33
42
|
this.operationTraceRegistry = operationTraceRegistry;
|
|
34
43
|
this.als = als;
|
|
@@ -102,6 +111,11 @@ let TracerService = class TracerService {
|
|
|
102
111
|
// in this case anyway, so the outcome is unchanged.
|
|
103
112
|
return;
|
|
104
113
|
}
|
|
114
|
+
if (this.options.enabled === false) {
|
|
115
|
+
// A disabled agent opens no traces, and the registry warns about every
|
|
116
|
+
// error it is handed without one.
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
105
119
|
const callerId = store.get(CALLER_METADATA_KEY);
|
|
106
120
|
this.operationTraceRegistry.captureError(traceId, callerId, error, tags ?? {});
|
|
107
121
|
}
|
|
@@ -182,6 +196,50 @@ let TracerService = class TracerService {
|
|
|
182
196
|
const traceId = store?.get(this.options.traceIdKey);
|
|
183
197
|
return typeof traceId === "string" ? traceId : null;
|
|
184
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Sets the operation id reported for the current request trace, in place of
|
|
201
|
+
* its route path, GraphQL root field or message pattern. Works from anywhere
|
|
202
|
+
* in the request - middleware, guard, interceptor or handler - and a later
|
|
203
|
+
* call replaces an earlier one.
|
|
204
|
+
*
|
|
205
|
+
* Use a stable, bounded name, not a per-request value, so requests aggregate
|
|
206
|
+
* together. The name is trimmed and cut to 255 characters, and anything but
|
|
207
|
+
* a non-blank string is ignored. Does nothing when there is no active trace
|
|
208
|
+
* or the request is not recorded.
|
|
209
|
+
*/
|
|
210
|
+
setOperationId(operationId) {
|
|
211
|
+
// Typed, but often read off a request body, which nothing checks at
|
|
212
|
+
// runtime: a number would have the collector refuse the batch it rides in,
|
|
213
|
+
// and a blank name would have the agent drop the request, error and all.
|
|
214
|
+
const name = typeof operationId === "string" ? operationId.trim() : "";
|
|
215
|
+
if (!name) {
|
|
216
|
+
this.reportUnusableOperationId(operationId);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const store = this.als.getStore();
|
|
220
|
+
const traceId = store?.get(TRACE_REGISTRY_KEY) ?? store?.get(this.options.traceIdKey);
|
|
221
|
+
if (typeof traceId === "string") {
|
|
222
|
+
this.operationTraceRegistry.setOperationId(traceId, name.length > MAX_OPERATION_ID_LENGTH
|
|
223
|
+
? Array.from(name).slice(0, MAX_OPERATION_ID_LENGTH).join("")
|
|
224
|
+
: name);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* An unusable name comes from the same call site on every request, so it is
|
|
229
|
+
* reported once rather than once per request.
|
|
230
|
+
*/
|
|
231
|
+
reportUnusableOperationId(value) {
|
|
232
|
+
if (this.hasReportedUnusableOperationId) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
this.hasReportedUnusableOperationId = true;
|
|
236
|
+
const given = value === null || value === undefined
|
|
237
|
+
? String(value)
|
|
238
|
+
: typeof value === "string"
|
|
239
|
+
? "a blank string"
|
|
240
|
+
: `a value of type ${typeof value}`;
|
|
241
|
+
this.logger.warn(`setOperationId ignored ${given}: an operation id is a non-blank string. Later ones are not reported.`);
|
|
242
|
+
}
|
|
185
243
|
/**
|
|
186
244
|
* Sets an attribute on the current trace.
|
|
187
245
|
* For example, you can use this to add metadata to the current request trace for later use and retrieval.
|
|
@@ -239,7 +297,7 @@ let TracerService = class TracerService {
|
|
|
239
297
|
};
|
|
240
298
|
}
|
|
241
299
|
};
|
|
242
|
-
TracerService = __decorate([
|
|
300
|
+
TracerService = TracerService_1 = __decorate([
|
|
243
301
|
Injectable(),
|
|
244
302
|
__param(3, Inject(OBSERVE_OPTIONS)),
|
|
245
303
|
__metadata("design:paramtypes", [OperationTraceRegistry,
|
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
* declined to the pricing page, and one whose rate cap had engaged to their
|
|
8
8
|
* invoices. The body tells them apart: a quota refusal carries
|
|
9
9
|
* `code: "USAGE_LIMIT_REACHED"` with the plan and the counts, and a quota
|
|
10
|
-
* refusal caused by a declined payment adds `reason: "payment_failed"
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* refusal caused by a declined payment adds `reason: "payment_failed"` - or
|
|
11
|
+
* `reason: "overage_budget"` when the account's own $0 overage budget stopped
|
|
12
|
+
* collection once its included events were spent. Credentials the collector
|
|
13
|
+
* has already rejected carry `code: "CREDENTIALS_REJECTED"` - a 429 rather
|
|
14
|
+
* than another 401, so that agents which pause only on a 429 stop retrying
|
|
15
|
+
* them. A rate cap, and any older collector, sends none of these and gets the
|
|
16
|
+
* old sentence.
|
|
15
17
|
*
|
|
16
18
|
* Written self-contained on purpose - no imports, no module-scope constants -
|
|
17
19
|
* because the telemetry worker is a stringified function and this travels
|
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
* declined to the pricing page, and one whose rate cap had engaged to their
|
|
8
8
|
* invoices. The body tells them apart: a quota refusal carries
|
|
9
9
|
* `code: "USAGE_LIMIT_REACHED"` with the plan and the counts, and a quota
|
|
10
|
-
* refusal caused by a declined payment adds `reason: "payment_failed"
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* refusal caused by a declined payment adds `reason: "payment_failed"` - or
|
|
11
|
+
* `reason: "overage_budget"` when the account's own $0 overage budget stopped
|
|
12
|
+
* collection once its included events were spent. Credentials the collector
|
|
13
|
+
* has already rejected carry `code: "CREDENTIALS_REJECTED"` - a 429 rather
|
|
14
|
+
* than another 401, so that agents which pause only on a 429 stop retrying
|
|
15
|
+
* them. A rate cap, and any older collector, sends none of these and gets the
|
|
16
|
+
* old sentence.
|
|
15
17
|
*
|
|
16
18
|
* Written self-contained on purpose - no imports, no module-scope constants -
|
|
17
19
|
* because the telemetry worker is a stringified function and this travels
|
|
@@ -48,6 +50,16 @@ export const describeIngestRefusal = (body) => {
|
|
|
48
50
|
(counts ? ` (${counts})` : "") +
|
|
49
51
|
"; update the payment method in the dashboard to resume");
|
|
50
52
|
}
|
|
53
|
+
if (detail.reason === "overage_budget") {
|
|
54
|
+
// The account asked for nothing past its plan - a $0 overage budget - and
|
|
55
|
+
// the plan's events are spent. Nothing is wrong with the plan or the
|
|
56
|
+
// card, so neither an upgrade nor a payment is the fix: raising the
|
|
57
|
+
// budget is, or the turn of the month, which the operator would otherwise
|
|
58
|
+
// not know is coming.
|
|
59
|
+
return ("the account's overage budget is $0 and its included events for this period are used" +
|
|
60
|
+
(counts ? ` (${counts})` : "") +
|
|
61
|
+
", so collection is stopped until the 1st (UTC) or until the overage budget is raised on the dashboard's Usage page");
|
|
62
|
+
}
|
|
51
63
|
return ("the account has used its included events for this period" +
|
|
52
64
|
(counts ? ` (${counts})` : "") +
|
|
53
65
|
"; upgrade the plan or wait for the period to reset");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/observe",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
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",
|
|
@@ -140,14 +140,15 @@
|
|
|
140
140
|
"@nestjs/testing": "12.0.1",
|
|
141
141
|
"@nestjs/websockets": "12.0.3",
|
|
142
142
|
"@swc/core": "1.16.1",
|
|
143
|
-
"@types/
|
|
143
|
+
"@types/mssql": "12.3.0",
|
|
144
|
+
"@types/node": "22.20.5",
|
|
144
145
|
"@types/pg": "8.23.1",
|
|
145
146
|
"@types/supertest": "7.2.1",
|
|
146
147
|
"@types/ws": "8.18.1",
|
|
147
148
|
"@vitest/coverage-v8": "4.1.11",
|
|
148
149
|
"bull": "4.16.5",
|
|
149
150
|
"bullmq": "6.2.0",
|
|
150
|
-
"drizzle-orm": "0.45.
|
|
151
|
+
"drizzle-orm": "0.45.4",
|
|
151
152
|
"express": "5.2.1",
|
|
152
153
|
"graphql": "16.14.2",
|
|
153
154
|
"husky": "9.1.7",
|
|
@@ -155,7 +156,8 @@
|
|
|
155
156
|
"lint-staged": "17.6.0",
|
|
156
157
|
"mongodb": "7.6.0",
|
|
157
158
|
"mongoose": "9.10.1",
|
|
158
|
-
"
|
|
159
|
+
"mssql": "12.7.9",
|
|
160
|
+
"mysql2": "3.24.6",
|
|
159
161
|
"nestjs-cls": "6.2.1",
|
|
160
162
|
"oxlint": "1.79.0",
|
|
161
163
|
"oxlint-tsgolint": "7.0.2001",
|
|
@@ -174,6 +176,9 @@
|
|
|
174
176
|
"ws": "8.21.3"
|
|
175
177
|
},
|
|
176
178
|
"overrides": {
|
|
179
|
+
"mssql": {
|
|
180
|
+
"tedious": "19.2.2"
|
|
181
|
+
},
|
|
177
182
|
"nestjs-cls": {
|
|
178
183
|
"@nestjs/common": "$@nestjs/common",
|
|
179
184
|
"@nestjs/core": "$@nestjs/core"
|