@nestjs/observe 0.3.22 → 0.3.24
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 +79 -16
- package/dist/agent/degraded-ingest.protocol.d.ts +2 -8
- package/dist/agent/degraded-ingest.protocol.js +2 -8
- package/dist/agent/detached-observe-worker.assembly.d.ts +2 -0
- package/dist/agent/detached-observe-worker.assembly.js +3 -0
- package/dist/agent/detached-observe-worker.d.ts +8 -0
- package/dist/agent/detached-observe-worker.js +20 -2
- package/dist/agent/observe-agent.shared-buffer.d.ts +71 -23
- package/dist/agent/observe-agent.shared-buffer.js +126 -38
- package/dist/agent/observe-agent.worker.d.ts +19 -23
- package/dist/agent/observe-agent.worker.js +79 -78
- package/dist/agent/observe-reporting.util.d.ts +35 -0
- package/dist/agent/observe-reporting.util.js +69 -0
- package/dist/instrument/create-instance-decorator.instrument.js +34 -2
- package/dist/interfaces/observe-options.interface.d.ts +71 -13
- package/dist/observe.constants.d.ts +7 -0
- package/dist/observe.constants.js +7 -0
- package/dist/observe.module.js +50 -4
- package/dist/otlp/otlp-encoders.d.ts +26 -0
- package/dist/otlp/otlp-encoders.js +296 -0
- package/dist/otlp/otlp-export-grant.d.ts +34 -0
- package/dist/otlp/otlp-export-grant.js +22 -0
- package/dist/otlp/otlp-options.interface.d.ts +59 -0
- package/dist/otlp/otlp-options.interface.js +1 -0
- package/dist/otlp/otlp-settings.util.d.ts +38 -0
- package/dist/otlp/otlp-settings.util.js +154 -0
- package/dist/otlp/otlp-span.mapper.d.ts +73 -0
- package/dist/otlp/otlp-span.mapper.js +345 -0
- package/dist/otlp/otlp-trace-exporter.service.d.ts +130 -0
- package/dist/otlp/otlp-trace-exporter.service.js +497 -0
- package/dist/outgoing/http.integration.d.ts +5 -4
- package/dist/outgoing/http.integration.js +3 -3
- package/dist/outgoing/outgoing-observe-agent.service.d.ts +2 -2
- package/dist/outgoing/outgoing-observe-agent.service.js +3 -3
- package/dist/outgoing/sql-statement.util.js +2 -2
- package/dist/protocols/http-observe-agent.service.d.ts +1 -8
- package/dist/protocols/http-observe-agent.service.js +29 -22
- package/dist/protocols/job-trace-runner.d.ts +11 -0
- package/dist/protocols/job-trace-runner.js +42 -8
- package/dist/protocols/rpc-observe-agent.service.d.ts +5 -0
- package/dist/protocols/rpc-observe-agent.service.js +43 -3
- package/dist/services/operation-trace.registry.d.ts +29 -1
- package/dist/services/operation-trace.registry.js +46 -5
- package/dist/utils/default-trace-id-generator.util.js +6 -2
- package/dist/utils/opentelemetry.util.d.ts +26 -0
- package/dist/utils/opentelemetry.util.js +48 -0
- package/dist/utils/trace-handoff.util.d.ts +51 -0
- package/dist/utils/trace-handoff.util.js +98 -0
- package/package.json +14 -12
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CALLER_METADATA_KEY, TRACE_CONTEXT_KEY, } from "../observe.constants.js";
|
|
2
|
+
import { activeOpenTelemetrySpanContext, withRemoteOpenTelemetryParent, } from "./opentelemetry.util.js";
|
|
3
|
+
import { formatTraceparent, randomSpanId, readTraceContext, w3cSpanIdOf, w3cTraceIdOf, } from "./trace-context.util.js";
|
|
4
|
+
/**
|
|
5
|
+
* W3C Trace Context for work an operation hands on where no OpenTelemetry
|
|
6
|
+
* instrumentation carries it - a queue job it enqueues, a microservice
|
|
7
|
+
* message it sends - with `openTelemetry` on.
|
|
8
|
+
*
|
|
9
|
+
* Observe carries its own trace id across those hops already: in a job's
|
|
10
|
+
* options (`observeTraceId`) and in a message's `x-request-id` metadata. An
|
|
11
|
+
* OpenTelemetry SDK in the process that runs the job or handles the message
|
|
12
|
+
* has nothing to go on, though, so the spans it opens there - and the
|
|
13
|
+
* `traceparent` on every call they make - would start a trace of their own,
|
|
14
|
+
* which every service further down then follows. So the hop carries a
|
|
15
|
+
* `traceparent` too, and the other side hands it to the SDK.
|
|
16
|
+
*/
|
|
17
|
+
/** A span id the spec accepts: 16 lowercase hex digits, not all zeros. */
|
|
18
|
+
const SPAN_ID_PATTERN = /^(?![0]{16})[0-9a-f]{16}$/;
|
|
19
|
+
/**
|
|
20
|
+
* The `traceparent` an operation hands on with work it starts elsewhere,
|
|
21
|
+
* beside the Observe trace id `traceId` that the work inherits.
|
|
22
|
+
*
|
|
23
|
+
* Its trace is the W3C form of `traceId`, so the work has one trace id in
|
|
24
|
+
* both tools whatever side runs it. Its parent is the span an OpenTelemetry
|
|
25
|
+
* SDK in this process has open, when that span is in the same trace - so
|
|
26
|
+
* the SDK's spans for the work nest under the request's in its backend -
|
|
27
|
+
* and its sampled flag is that span's. Otherwise it is the span Observe has
|
|
28
|
+
* open, as on an outbound HTTP call, with the sampled flag the operation
|
|
29
|
+
* arrived with, else whether Observe is recording it.
|
|
30
|
+
*
|
|
31
|
+
* `store` is the operation's async store.
|
|
32
|
+
*/
|
|
33
|
+
export function traceparentToHandOn(store, traceId) {
|
|
34
|
+
const w3cTraceId = w3cTraceIdOf(traceId);
|
|
35
|
+
const active = activeOpenTelemetrySpanContext();
|
|
36
|
+
if (active?.traceId === w3cTraceId &&
|
|
37
|
+
typeof active.spanId === "string" &&
|
|
38
|
+
SPAN_ID_PATTERN.test(active.spanId)) {
|
|
39
|
+
return formatTraceparent(w3cTraceId, active.spanId, (active.traceFlags & 0x01) === 0x01);
|
|
40
|
+
}
|
|
41
|
+
const caller = store?.get(CALLER_METADATA_KEY);
|
|
42
|
+
const received = store?.get(TRACE_CONTEXT_KEY);
|
|
43
|
+
const recorded = typeof caller === "string";
|
|
44
|
+
return formatTraceparent(w3cTraceId, recorded ? w3cSpanIdOf(caller) : randomSpanId(), received?.traceId === w3cTraceId ? received.sampled : recorded);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Runs `run` in the trace a `traceparent` handed on with the work names -
|
|
48
|
+
* see `traceparentToHandOn` - for an OpenTelemetry SDK in this process: the
|
|
49
|
+
* spans it opens inside `run` join that trace, under the span that handed
|
|
50
|
+
* the work on, and the calls they cover carry the trace on.
|
|
51
|
+
*
|
|
52
|
+
* Only a `traceparent` the spec accepts, and only in the trace `traceId` -
|
|
53
|
+
* the Observe trace id the work runs under - maps onto: job options and
|
|
54
|
+
* packet metadata are writable by anything that reaches Redis or the
|
|
55
|
+
* socket, and a span from another trace would put the work under one it
|
|
56
|
+
* never ran beside. Anything else runs `run` as it is.
|
|
57
|
+
*
|
|
58
|
+
* So does work an OpenTelemetry instrumentation has already taken up, with
|
|
59
|
+
* a span of that trace open for it - BullMQ's `bullmq-otel` opens one for
|
|
60
|
+
* each job, and OpenTelemetry's Kafka and RabbitMQ instrumentations one for
|
|
61
|
+
* each message they deliver. The work's spans belong under that span, which
|
|
62
|
+
* the handed-on parent would put them beside.
|
|
63
|
+
*/
|
|
64
|
+
export function continueHandedOnTrace(traceparent, traceId, run) {
|
|
65
|
+
const parent = typeof traceparent === "string"
|
|
66
|
+
? readTraceContext({ traceparent })
|
|
67
|
+
: undefined;
|
|
68
|
+
if (!parent ||
|
|
69
|
+
parent.traceId !== w3cTraceIdOf(traceId) ||
|
|
70
|
+
activeOpenTelemetrySpanContext()?.traceId === parent.traceId) {
|
|
71
|
+
return run();
|
|
72
|
+
}
|
|
73
|
+
return withRemoteOpenTelemetryParent({
|
|
74
|
+
traceId: parent.traceId,
|
|
75
|
+
spanId: parent.parentSpanId,
|
|
76
|
+
sampled: parent.sampled,
|
|
77
|
+
}, run);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether OpenTelemetry interop runs now - `openTelemetry` on, beside
|
|
81
|
+
* reporting to NestJS Observe (see `ObserveAgentSharedBuffer.isReporting`) -
|
|
82
|
+
* for what is set up before the module's options resolve: the microservice
|
|
83
|
+
* dispatch hook, which a client is handed as it is instantiated. Off until
|
|
84
|
+
* the module configures it.
|
|
85
|
+
*/
|
|
86
|
+
export class OpenTelemetryInteropGate {
|
|
87
|
+
options;
|
|
88
|
+
buffer;
|
|
89
|
+
configure(options, buffer) {
|
|
90
|
+
this.options = options;
|
|
91
|
+
this.buffer = buffer;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
isOn() {
|
|
95
|
+
return (this.options?.openTelemetry === true &&
|
|
96
|
+
this.buffer?.isReporting() === true);
|
|
97
|
+
}
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/observe",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.24",
|
|
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",
|
|
@@ -137,18 +137,18 @@
|
|
|
137
137
|
"@nestjs/apollo": "14.1.1",
|
|
138
138
|
"@nestjs/bull": "12.0.0",
|
|
139
139
|
"@nestjs/bullmq": "12.0.0",
|
|
140
|
-
"@nestjs/common": "12.
|
|
141
|
-
"@nestjs/core": "12.
|
|
140
|
+
"@nestjs/common": "12.3.3",
|
|
141
|
+
"@nestjs/core": "12.3.3",
|
|
142
142
|
"@nestjs/graphql": "14.0.0",
|
|
143
|
-
"@nestjs/microservices": "12.
|
|
144
|
-
"@nestjs/platform-express": "12.
|
|
145
|
-
"@nestjs/platform-fastify": "12.
|
|
146
|
-
"@nestjs/platform-node": "12.3.
|
|
147
|
-
"@nestjs/platform-socket.io": "12.
|
|
148
|
-
"@nestjs/platform-ws": "12.
|
|
143
|
+
"@nestjs/microservices": "12.3.3",
|
|
144
|
+
"@nestjs/platform-express": "12.3.3",
|
|
145
|
+
"@nestjs/platform-fastify": "12.3.3",
|
|
146
|
+
"@nestjs/platform-node": "12.3.3",
|
|
147
|
+
"@nestjs/platform-socket.io": "12.3.3",
|
|
148
|
+
"@nestjs/platform-ws": "12.3.3",
|
|
149
149
|
"@nestjs/schedule": "12.0.1",
|
|
150
|
-
"@nestjs/testing": "12.
|
|
151
|
-
"@nestjs/websockets": "12.
|
|
150
|
+
"@nestjs/testing": "12.3.3",
|
|
151
|
+
"@nestjs/websockets": "12.3.3",
|
|
152
152
|
"@opentelemetry/api": "1.9.1",
|
|
153
153
|
"@opentelemetry/auto-instrumentations-node": "0.81.0",
|
|
154
154
|
"@opentelemetry/context-async-hooks": "2.12.0",
|
|
@@ -165,6 +165,7 @@
|
|
|
165
165
|
"@vitest/coverage-v8": "4.1.11",
|
|
166
166
|
"bull": "4.16.5",
|
|
167
167
|
"bullmq": "6.2.0",
|
|
168
|
+
"bullmq-otel": "2.0.1",
|
|
168
169
|
"dd-trace": "6.23.0",
|
|
169
170
|
"drizzle-orm": "0.45.4",
|
|
170
171
|
"express": "5.2.1",
|
|
@@ -174,13 +175,14 @@
|
|
|
174
175
|
"lint-staged": "17.6.0",
|
|
175
176
|
"mongodb": "7.6.0",
|
|
176
177
|
"mongoose": "9.10.1",
|
|
177
|
-
"mssql": "12.7.
|
|
178
|
+
"mssql": "12.7.13",
|
|
178
179
|
"mysql2": "3.24.6",
|
|
179
180
|
"nestjs-cls": "6.2.1",
|
|
180
181
|
"oxlint": "1.79.0",
|
|
181
182
|
"oxlint-tsgolint": "7.0.2001",
|
|
182
183
|
"pg": "8.23.0",
|
|
183
184
|
"prettier": "3.2.5",
|
|
185
|
+
"protobufjs": "7.6.5",
|
|
184
186
|
"reflect-metadata": "0.2.2",
|
|
185
187
|
"release-it": "21.0.2",
|
|
186
188
|
"rimraf": "6.1.3",
|