@nifrajs/otel 5.1.0 → 5.3.0
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/CHANGELOG.md +450 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +2 -4
- package/dist/cache.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lifecycle.d.ts +6 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +58 -29
- package/dist/lifecycle.js.map +1 -1
- package/dist/otlp.d.ts.map +1 -1
- package/dist/otlp.js +13 -9
- package/dist/otlp.js.map +1 -1
- package/package.json +4 -3
- package/src/cache.ts +5 -4
- package/src/index.ts +1 -0
- package/src/lifecycle.ts +75 -32
- package/src/otlp.ts +13 -9
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
# @nifrajs/otel
|
|
2
|
+
|
|
3
|
+
## 5.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7ab9692: Add build-time schema compilation that emits typed static validators without runtime code generation. Generated modules preserve strict validation and structured issues while avoiding the schema builder and dynamic compiler in deployed bundles.
|
|
8
|
+
|
|
9
|
+
A schema whose property key, `format` name or custom kind holds a quote, backslash or line break, or whose literal holds a backslash or line break, now validates on the eval-free checker and is refused by build-time compilation. TypeBox splices that text into generated source unescaped, so a quote could end the string and run the rest as code.
|
|
10
|
+
|
|
11
|
+
Prepare immutable route modules and layout chains in production while executing authorization gates and loaders for every request. Mutable manifests can disable module preparation with `cacheRouteModules: false`.
|
|
12
|
+
|
|
13
|
+
Reduce output projection bookkeeping for uniform subtrees, reuse request-bound cache views, and record completed cache spans without allocating an active observation. Span parentage, sampling, redaction, exporter isolation, and capability enforcement remain intact.
|
|
14
|
+
|
|
15
|
+
Keep custom start-only `ObservationLifecycle` implementations compatible. The factory returns the extended `RecordingObservationLifecycle` interface with the new `record` method.
|
|
16
|
+
|
|
17
|
+
Mark the migration parser's TypeScript keyword-kind comparison as syntax, so the security check does not mistake it for a secret comparison.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 3553267: `otlpExporter`'s `flush()` and `shutdown()` no longer resolve while a span queued before the call is still exporting. Settlement counted spans sent, failed or dropped, so a later span dropped on queue overflow counted toward an earlier flush and resolved it before its batch had settled; a flush now waits until every span queued before it has left the queue and the export in flight.
|
|
22
|
+
|
|
23
|
+
## 5.2.1
|
|
24
|
+
|
|
25
|
+
No changes in this release.
|
|
26
|
+
|
|
27
|
+
## 5.2.0
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 9498cf8: The package ships its `CHANGELOG.md`, so the installed package has the notes for every version, as the GitHub release does. Before, the tarball held only the code, `README.md`, `LICENSE` and `package.json`.
|
|
32
|
+
|
|
33
|
+
## 5.1.0
|
|
34
|
+
|
|
35
|
+
No changes in this release.
|
|
36
|
+
|
|
37
|
+
## 5.0.0
|
|
38
|
+
|
|
39
|
+
### Major Changes
|
|
40
|
+
|
|
41
|
+
- 2f09afb: `tracing()` now reports a matched request's route template as `url.path` (for example `/users/:id`), so an email, an id or a token in a path segment no longer reaches the trace backend. Pass `rawUrlPath: true` to report the raw path as before. Requests that match no route still report their raw path. DevTools installs its own tracing with `rawUrlPath: true`, so its local request log is unchanged.
|
|
42
|
+
|
|
43
|
+
### Minor Changes
|
|
44
|
+
|
|
45
|
+
- 9de83f4: `otlpExporter` sends one export at a time; spans that end meanwhile wait in the `maxQueue`-bounded queue instead of each opening another POST. A new `timeoutMs` option (default 30000) aborts and reports an export that takes too long. `flush()` resolves once every span queued before the call was sent, failed or dropped, and `shutdown()` waits for the export in flight.
|
|
46
|
+
- fc1a30e: `metrics()` takes an `authorize(req)` option that gates the scrape endpoint; a refused scrape answers 401 with an empty body. Without it the endpoint stays public, which the option's documentation now states.
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [a0a02f4]
|
|
51
|
+
- Updated dependencies [0aed425]
|
|
52
|
+
- Updated dependencies [eaf030b]
|
|
53
|
+
- Updated dependencies [7de0397]
|
|
54
|
+
- Updated dependencies [4199ff3]
|
|
55
|
+
- Updated dependencies [90d9ee6]
|
|
56
|
+
- Updated dependencies [364a234]
|
|
57
|
+
- Updated dependencies [c06cba5]
|
|
58
|
+
- Updated dependencies [f4d3852]
|
|
59
|
+
- Updated dependencies [4a82ae0]
|
|
60
|
+
- Updated dependencies [0ff867a]
|
|
61
|
+
- Updated dependencies [e7391bf]
|
|
62
|
+
- Updated dependencies [0b80a59]
|
|
63
|
+
- Updated dependencies [c64db12]
|
|
64
|
+
- Updated dependencies [3753104]
|
|
65
|
+
- Updated dependencies [4b3b1fa]
|
|
66
|
+
- Updated dependencies [3562557]
|
|
67
|
+
- Updated dependencies [53087f3]
|
|
68
|
+
- Updated dependencies [2def6c7]
|
|
69
|
+
- Updated dependencies [b5b5bc3]
|
|
70
|
+
- Updated dependencies [22e1777]
|
|
71
|
+
- Updated dependencies [3a483cd]
|
|
72
|
+
- Updated dependencies [35f52c7]
|
|
73
|
+
- Updated dependencies [343cb81]
|
|
74
|
+
- Updated dependencies [d91fd44]
|
|
75
|
+
- Updated dependencies [b13e071]
|
|
76
|
+
- Updated dependencies [077657f]
|
|
77
|
+
- Updated dependencies [a5963cb]
|
|
78
|
+
- Updated dependencies [05aac0e]
|
|
79
|
+
- Updated dependencies [1a6616f]
|
|
80
|
+
- Updated dependencies [7775c2b]
|
|
81
|
+
- Updated dependencies [846e2f6]
|
|
82
|
+
- Updated dependencies [aadd9fc]
|
|
83
|
+
- Updated dependencies [ea16748]
|
|
84
|
+
- Updated dependencies [fc0284a]
|
|
85
|
+
- Updated dependencies [5b22f4d]
|
|
86
|
+
- Updated dependencies [1b94593]
|
|
87
|
+
- Updated dependencies [9f58295]
|
|
88
|
+
- Updated dependencies [b9608ac]
|
|
89
|
+
- Updated dependencies [7a165de]
|
|
90
|
+
- Updated dependencies [4064f36]
|
|
91
|
+
- Updated dependencies [48aad8c]
|
|
92
|
+
- Updated dependencies [41050ed]
|
|
93
|
+
- Updated dependencies [fc837cb]
|
|
94
|
+
- Updated dependencies [b80ce77]
|
|
95
|
+
- Updated dependencies [9b1acc9]
|
|
96
|
+
- Updated dependencies [740109f]
|
|
97
|
+
- Updated dependencies [e0a25fe]
|
|
98
|
+
- Updated dependencies [3630b6e]
|
|
99
|
+
- Updated dependencies [1290c6d]
|
|
100
|
+
- Updated dependencies [d0a7d58]
|
|
101
|
+
- @nifrajs/core@5.0.0
|
|
102
|
+
|
|
103
|
+
## 4.0.2
|
|
104
|
+
|
|
105
|
+
## 4.0.1
|
|
106
|
+
|
|
107
|
+
## 4.0.0
|
|
108
|
+
|
|
109
|
+
### Minor Changes
|
|
110
|
+
|
|
111
|
+
- ac703a1: `cacheTracing()` from `@nifrajs/otel/cache` turns `@nifrajs/cache` operations into spans.
|
|
112
|
+
|
|
113
|
+
- Pass it as `createCache({ observer: cacheTracing({ exporter }) })`. Every operation on a view bound with `cache.for(c)` becomes a `cache <op>` child span of `c.trace`, with `nifra.cache.operation`, `nifra.cache.outcome` and `nifra.cache.tag_count`.
|
|
114
|
+
- Raw keys stay in the process. By default a span carries only the key prefix (`user:42` gives `nifra.cache.key_prefix = "user"`); `keyAttribute: "none"` drops it and a function exports its own value.
|
|
115
|
+
- The background refresh of a stale `wrap` is a `cache revalidate` span in its own trace, linked to the request span.
|
|
116
|
+
- `StartObservation.startTime` and `EndObservation.durationMs` record work after it settled.
|
|
117
|
+
|
|
118
|
+
- e1b89c0: `traceEventConsumer()` from `@nifrajs/otel/events` traces an `@nifrajs/events` consumer with one wrapper.
|
|
119
|
+
|
|
120
|
+
- `traceEventConsumer(contractOrRegistry, handler, { exporter })` returns `consume(input, parent?)`. Each envelope is one `process <type>` consumer span, linked to the producer's span through `causalitySpanLink(envelope.causality)`; with a `parent` trace (a webhook route's `c.trace`) the span is its child.
|
|
121
|
+
- Attributes: `nifra.event.type`, `nifra.event.version`, `messaging.message.id` (the envelope id), `messaging.operation.type`/`.name` = `process`, and `messaging.system` (`system` option, default `"nifra.events"`).
|
|
122
|
+
- Input that fails to parse never reaches the handler: it resolves `{ success: false, issueCount }` and records an error span carrying the issue count and, for a registry, its bounded reason. No payload is exported.
|
|
123
|
+
- The handler receives `{ trace }` for nested spans, and `scope` runs it inside an ambient context.
|
|
124
|
+
|
|
125
|
+
- 1afbe9f: `jobTracing()` from `@nifrajs/otel/jobs` traces `@nifrajs/jobs` with OpenTelemetry messaging spans.
|
|
126
|
+
|
|
127
|
+
- Pass it as `createQueue({ instrument: jobTracing({ exporter }) })`.
|
|
128
|
+
- Each enqueue is a `send <job>` producer span (a child of `c.trace` when enqueued through `job.for(c)`), and its context is stored with the job.
|
|
129
|
+
- Each attempt is a `process <job>` consumer span: a child of the send span, plus a link to it. Retries are separate spans; a failed attempt is an error span, and the one that dead-letters the job carries `nifra.job.dead_lettered = true`.
|
|
130
|
+
- Attributes: `messaging.system = "nifra.jobs"`, `messaging.operation.type`, `messaging.operation.name`, `messaging.destination.name`, `messaging.message.id`, `nifra.job.attempt`, `nifra.job.outcome`. Error text is never exported.
|
|
131
|
+
- A malformed stored traceparent starts a new trace; the sampled flag travels with a valid one.
|
|
132
|
+
- `scope` runs each attempt inside an ambient context, such as the OpenTelemetry SDK's.
|
|
133
|
+
|
|
134
|
+
- b8af5cf: `otelBridge()` from `@nifrajs/otel/sdk-bridge` connects nifra spans to the OpenTelemetry SDK. The app passes its own `@opentelemetry/api`; `@nifrajs/otel` adds no dependency.
|
|
135
|
+
|
|
136
|
+
- `bridge.plugin`: `app.use(bridge.plugin)` runs each subsequent route with its request span active in the OTel context, so the SDK's own instrumentations (pg, mysql2, ioredis, undici, prisma) nest under the request span. It costs one `around()` frame per request, only when installed.
|
|
137
|
+
- `bridge.adapter`: mirrors nifra spans into SDK spans (name, kind, parent, links, attributes, status, timing). Pass it in `tracing({ adapters })` and the other tracers' `adapters`.
|
|
138
|
+
- `bridge.idGenerator`: wired as the SDK provider's `idGenerator`, mirrored spans keep nifra's exact trace and span ids, so forwarded `traceparent` headers and the trace context stored with a job name real spans. Without it the adapter warns once.
|
|
139
|
+
- `bridge.scope`: runs code with a nifra span active in the OTel context; pass it as `jobTracing({ scope })` or `traceEventConsumer(..., { scope })` so spans inside a job or event handler nest under it.
|
|
140
|
+
- Context propagation needs the SDK's AsyncLocalStorage context manager. Verified on Node 26, Bun 1.4, Deno 2.9 and workerd with `nodejs_compat`. The SDK's undici instrumentation records `fetch` only on Node, where `fetch` is undici.
|
|
141
|
+
|
|
142
|
+
- 6d87951: Spans carry an OpenTelemetry span kind.
|
|
143
|
+
|
|
144
|
+
- `NifraSpan.kind` and `StartObservation.kind` take `"server" | "client" | "producer" | "consumer" | "internal"`.
|
|
145
|
+
- `otlpExporter()` sends each kind as its OTLP enum value. A span without a kind is sent as `SERVER`.
|
|
146
|
+
- `tracing()` request spans are `server` spans; `effectTracing()` capability spans are `internal` spans.
|
|
147
|
+
- `consoleSpanExporter()` logs the kind when a span has one.
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- 1b2d53a: `replacedRequestOf(request)` returns the request an `onRequest` hook replaced with this one. Response hooks receive the request the route ran with, so a middleware that keyed state on the request its `onRequest` saw can walk back to it. `idempotency()` uses this to keep its claim when a later hook such as `methodOverride()` rewrites the request: a retry replays the stored response instead of answering 409 and then running the handler a second time. `metrics()` uses it to count such requests and to decrement its in-flight gauge for them.
|
|
152
|
+
- 50e68d9: `metrics()` labels a request method outside HTTP's standard set as `_OTHER`, following OpenTelemetry's HTTP conventions. A runtime that accepts extension methods, such as Deno, can no longer be made to create a new series per request.
|
|
153
|
+
- 76b7aa8: `tracing()` names a request span `{method} {route template}` - `GET /users/:id`, not `GET /users/42` - and records the template as `http.route`, as OpenTelemetry's HTTP conventions describe. The raw path stays in `url.path`. A method outside HTTP's own set is recorded as `_OTHER`, with the original in `http.request.method_original`.
|
|
154
|
+
- Updated dependencies [dde125b]
|
|
155
|
+
- Updated dependencies [72b62fa]
|
|
156
|
+
- Updated dependencies [aa44e93]
|
|
157
|
+
- Updated dependencies [4a3ee60]
|
|
158
|
+
- Updated dependencies [aad6297]
|
|
159
|
+
- Updated dependencies [dad0d41]
|
|
160
|
+
- Updated dependencies [538adc2]
|
|
161
|
+
- Updated dependencies [f47edd1]
|
|
162
|
+
- Updated dependencies [df9530a]
|
|
163
|
+
- Updated dependencies [3e6973f]
|
|
164
|
+
- Updated dependencies [25e8edf]
|
|
165
|
+
- Updated dependencies [2b5e5fc]
|
|
166
|
+
- Updated dependencies [3b090de]
|
|
167
|
+
- Updated dependencies [da7d792]
|
|
168
|
+
- Updated dependencies [612a296]
|
|
169
|
+
- Updated dependencies [fb14dfa]
|
|
170
|
+
- Updated dependencies [8ae97f6]
|
|
171
|
+
- Updated dependencies [4af6f39]
|
|
172
|
+
- Updated dependencies [ca8b50d]
|
|
173
|
+
- Updated dependencies [b00a889]
|
|
174
|
+
- Updated dependencies [b53d64f]
|
|
175
|
+
- Updated dependencies [66fd712]
|
|
176
|
+
- Updated dependencies [9c3d524]
|
|
177
|
+
- Updated dependencies [738e7a1]
|
|
178
|
+
- Updated dependencies [4801cac]
|
|
179
|
+
- Updated dependencies [1b2d53a]
|
|
180
|
+
- Updated dependencies [25fe13d]
|
|
181
|
+
- Updated dependencies [0852290]
|
|
182
|
+
- Updated dependencies [0589dbe]
|
|
183
|
+
- Updated dependencies [2e2d8c0]
|
|
184
|
+
- Updated dependencies [856f5ce]
|
|
185
|
+
- Updated dependencies [18aa5aa]
|
|
186
|
+
- Updated dependencies [cfd86b3]
|
|
187
|
+
- Updated dependencies [8ff96c9]
|
|
188
|
+
- Updated dependencies [4c46199]
|
|
189
|
+
- Updated dependencies [eef4932]
|
|
190
|
+
- Updated dependencies [6de8686]
|
|
191
|
+
- Updated dependencies [d7892ea]
|
|
192
|
+
- Updated dependencies [4936309]
|
|
193
|
+
- Updated dependencies [ff5a779]
|
|
194
|
+
- Updated dependencies [bbdc5a1]
|
|
195
|
+
- Updated dependencies [10bc446]
|
|
196
|
+
- Updated dependencies [e8270d9]
|
|
197
|
+
- Updated dependencies [ff4a062]
|
|
198
|
+
- Updated dependencies [43ba944]
|
|
199
|
+
- Updated dependencies [46c741a]
|
|
200
|
+
- Updated dependencies [7bfa25e]
|
|
201
|
+
- Updated dependencies [4936309]
|
|
202
|
+
- Updated dependencies [6e257a6]
|
|
203
|
+
- Updated dependencies [4a03d30]
|
|
204
|
+
- Updated dependencies [8e30090]
|
|
205
|
+
- Updated dependencies [28f3aaf]
|
|
206
|
+
- Updated dependencies [6d20355]
|
|
207
|
+
- Updated dependencies [6907cbe]
|
|
208
|
+
- Updated dependencies [b64c3ee]
|
|
209
|
+
- Updated dependencies [bda9637]
|
|
210
|
+
- Updated dependencies [81c720e]
|
|
211
|
+
- Updated dependencies [ed60b23]
|
|
212
|
+
- Updated dependencies [a158b74]
|
|
213
|
+
- Updated dependencies [ff25d68]
|
|
214
|
+
- @nifrajs/core@4.0.0
|
|
215
|
+
|
|
216
|
+
## 3.5.0
|
|
217
|
+
|
|
218
|
+
## 3.4.0
|
|
219
|
+
|
|
220
|
+
## 3.3.0
|
|
221
|
+
|
|
222
|
+
## 3.2.0
|
|
223
|
+
|
|
224
|
+
## 3.1.0
|
|
225
|
+
|
|
226
|
+
## 3.0.0
|
|
227
|
+
|
|
228
|
+
### Patch Changes
|
|
229
|
+
|
|
230
|
+
- Updated dependencies [f3d2a35]
|
|
231
|
+
- Updated dependencies [6e43c15]
|
|
232
|
+
- Updated dependencies [f0fd370]
|
|
233
|
+
- Updated dependencies [86a555b]
|
|
234
|
+
- Updated dependencies [8c5f4cf]
|
|
235
|
+
- Updated dependencies [f0fd370]
|
|
236
|
+
- Updated dependencies [381bbf3]
|
|
237
|
+
- Updated dependencies [36801ae]
|
|
238
|
+
- Updated dependencies [9acadba]
|
|
239
|
+
- Updated dependencies [99fc683]
|
|
240
|
+
- Updated dependencies [73d894d]
|
|
241
|
+
- @nifrajs/core@3.0.0
|
|
242
|
+
|
|
243
|
+
## 2.14.1
|
|
244
|
+
|
|
245
|
+
## 2.14.0
|
|
246
|
+
|
|
247
|
+
## 2.13.0
|
|
248
|
+
|
|
249
|
+
## 2.12.1
|
|
250
|
+
|
|
251
|
+
## 2.12.0
|
|
252
|
+
|
|
253
|
+
### Minor Changes
|
|
254
|
+
|
|
255
|
+
- 0efacea: Add a generic server `onStop` lifecycle hook and have OTLP tracing exporters flush and shut down automatically when attached to a server. Manual OTLP lifecycle calls remain available for standalone exporters.
|
|
256
|
+
- 9a9346e: `app.use(plugin)` keeps the caller's server type. A plugin built with `definePlugin` whose input
|
|
257
|
+
server type is not pinned used to widen the app to `Server<any, any>`, so every route declared
|
|
258
|
+
before _and_ after the `use` lost its types and the typed client silently degraded to `any`. That
|
|
259
|
+
case is now a compile error at the `use` call site, naming the definer to switch to; the plugin is
|
|
260
|
+
unchanged at runtime.
|
|
261
|
+
|
|
262
|
+
Pick the definer that matches what the plugin does: `defineContextPlugin<D>` when it adds context
|
|
263
|
+
via `derive`/`decorate` (the registry threads through and `D` is added to every downstream handler
|
|
264
|
+
context), `defineRouterPlugin` when it mounts routes/hooks and adds no context (mount as a side
|
|
265
|
+
effect, return the app). `definePlugin` still works when its input type is pinned - annotate the
|
|
266
|
+
parameter (`(app: typeof api) => ...`) or pass explicit type arguments.
|
|
267
|
+
|
|
268
|
+
Every first-party plugin now threads: `jwt`, `tokenAuth`, `basicAuth`, `durableCommand`, `etag`,
|
|
269
|
+
`compression`, `problemDetails`, `prettyJson`, `methodOverride`, `trailingSlash`, `cacheControl`,
|
|
270
|
+
`devtools`, and `metrics` return an `IdentityPlugin`; `timing`, `language`, and `tracing` return a
|
|
271
|
+
`ContextPlugin` of what they add (`{ timing }`, `{ language, languageMatch }`, and
|
|
272
|
+
`{ trace, observation, causality }` respectively), so `c.timing` / `c.language` / `c.trace` are
|
|
273
|
+
typed without a manual annotation. `combine(...)` is typed as an identity bundle and
|
|
274
|
+
`namedCombine(name, ...)` is its deduped, named form.
|
|
275
|
+
|
|
276
|
+
A type-level test asserts the threading for each definer shape, so a regression fails `typecheck`
|
|
277
|
+
rather than surfacing as `any` in a downstream app.
|
|
278
|
+
|
|
279
|
+
## 2.11.0
|
|
280
|
+
|
|
281
|
+
## 2.10.0
|
|
282
|
+
|
|
283
|
+
## 2.9.1
|
|
284
|
+
|
|
285
|
+
## 2.9.0
|
|
286
|
+
|
|
287
|
+
## 2.8.2
|
|
288
|
+
|
|
289
|
+
## 2.8.1
|
|
290
|
+
|
|
291
|
+
## 2.8.0
|
|
292
|
+
|
|
293
|
+
## 2.7.1
|
|
294
|
+
|
|
295
|
+
## 2.7.0
|
|
296
|
+
|
|
297
|
+
## 2.6.1
|
|
298
|
+
|
|
299
|
+
## 2.6.0
|
|
300
|
+
|
|
301
|
+
## 2.5.0
|
|
302
|
+
|
|
303
|
+
## 2.4.0
|
|
304
|
+
|
|
305
|
+
## 2.3.0
|
|
306
|
+
|
|
307
|
+
## 2.2.0
|
|
308
|
+
|
|
309
|
+
## 2.1.0
|
|
310
|
+
|
|
311
|
+
### Minor Changes
|
|
312
|
+
|
|
313
|
+
- bd294bb: Add `executeCapability()` as a correlated, policy-aware effect boundary.
|
|
314
|
+
|
|
315
|
+
- Correlate intent and terminal evidence with a random `effectId`, record committed/failed outcomes
|
|
316
|
+
automatically, and combine request cancellation with bounded async `aroundCapability()` admission
|
|
317
|
+
policies while preserving the synchronous `useCapability()` path.
|
|
318
|
+
- Retain idempotency results for every completed response, including non-2xx outcomes, so a retry
|
|
319
|
+
cannot repeat an effect that succeeded before a later handler failure.
|
|
320
|
+
- Add durable approval, effect journal, saga/compensation, and reconciliation primitives behind the
|
|
321
|
+
`durable-execution` subpath, plus token-only OpenTelemetry effect spans from `@nifrajs/otel/effects`.
|
|
322
|
+
Reconciliation supports bounded cursor pages, approval resume tokens stay out of ordinary error
|
|
323
|
+
serialization, durable terminal states are monotonic, crash ambiguity has an effect-ID-bound operator
|
|
324
|
+
resolution API, and unmatched effect spans have bounded retention.
|
|
325
|
+
- Add one shared owned-effect scope across capabilities, saga execution, compensation, idempotency
|
|
326
|
+
evidence, durable transitions, and telemetry. An explicit `markIdempotencySafeToRetry()` outcome
|
|
327
|
+
releases a resolved 5xx only while the scope proves no effect began.
|
|
328
|
+
- Add negotiated, versioned transport codecs with bounded plain-JSON and rich-wire adapters for HTTP,
|
|
329
|
+
the typed client, loader NDJSON, and WebSocket frames.
|
|
330
|
+
- Add Postgres, SQLite, and Durable Object durable-execution adapters with one reusable conformance
|
|
331
|
+
suite, plus leased reconciliation workers with bounded pages/concurrency, durable cursors, filters,
|
|
332
|
+
cancellation, backpressure, and token-only metrics.
|
|
333
|
+
|
|
334
|
+
## 2.0.0
|
|
335
|
+
|
|
336
|
+
### Major Changes
|
|
337
|
+
|
|
338
|
+
- d91a45b: Remove Nifra's remaining deprecated and compatibility-only public surfaces for the 2.0 cutover.
|
|
339
|
+
|
|
340
|
+
- `@nifrajs/core` and `nifra` now expose only the lean HTTP server API at their package roots. Import
|
|
341
|
+
optional systems from their documented subpaths. The deprecated invariant runner and the
|
|
342
|
+
`@nifrajs/budget` compatibility package are removed; use `@nifrajs/testing` and
|
|
343
|
+
`@nifrajs/core/budget` respectively.
|
|
344
|
+
- Web redirects accept only an options object as their second argument, the prerender enumeration
|
|
345
|
+
wrapper is removed in favor of `enumerateStaticRoutes()`, and fragment navigation resolves IDs only.
|
|
346
|
+
- MCP Apps metadata uses only `_meta.ui.resourceUri`; the deprecated flat `ui/resourceUri` key is gone.
|
|
347
|
+
- Telemetry uses `ObservationAdapter` directly; the `AgentSpan`, `AgentSpanExporter`, and `SpanExporter`
|
|
348
|
+
aliases are removed.
|
|
349
|
+
- Invalid HTTP method overrides always fail closed with 400; the legacy ignore mode is removed.
|
|
350
|
+
- `nifra build` always emits a complete target deploy directory and defaults to Bun. The old
|
|
351
|
+
client-only build branch is removed; `nifra start` runs the generated Bun `server.js`.
|
|
352
|
+
|
|
353
|
+
### Minor Changes
|
|
354
|
+
|
|
355
|
+
- bc46cc9: Production observability: a batching OTLP span exporter and RED metrics.
|
|
356
|
+
|
|
357
|
+
- `otlpExporter({ url, headers?, batch?, onError? })` ships spans to any OpenTelemetry collector over OTLP/HTTP (JSON) with in-process batching - dependency-free and edge-safe, matching the package's no-SDK stance. `tracing({ exporter: otlpExporter({ url: "http://localhost:4318/v1/traces" }) })` is now production-usable without writing your own exporter. `flush()`/`shutdown()` drain on graceful stop.
|
|
358
|
+
- `.use(metrics())` from `@nifrajs/otel/metrics` records RED metrics - `nifra_http_requests_total`, `nifra_http_request_duration_seconds`, `nifra_http_requests_in_flight` - labeled by method, the matched route TEMPLATE (so `/users/:id` is one series, not one per id), and status, and exposes them in Prometheus text at `/metrics`. `createMetricsRegistry()` lets an app register custom counters/gauges/histograms that render at the same endpoint. Zero dependencies; the subpath keeps it out of tracing-only bundles.
|
|
359
|
+
|
|
360
|
+
### Patch Changes
|
|
361
|
+
|
|
362
|
+
- ade0c7a: Add a curated `@nifrajs/core/server` entry for the common HTTP runtime and dedicated subpaths for
|
|
363
|
+
contracts, classification, cookies, logging, routing, Standard Schema, SEO, SSE, and webhooks. The
|
|
364
|
+
package root remains backwards compatible, while new scaffolds and first-party runtime packages avoid
|
|
365
|
+
eagerly parsing opt-in causality, invariant, manifest, reflection, capability, and assurance tooling.
|
|
366
|
+
- Updated dependencies [a7b1d60]
|
|
367
|
+
- Updated dependencies [eaac3d7]
|
|
368
|
+
- Updated dependencies [ade0c7a]
|
|
369
|
+
- Updated dependencies [82676e0]
|
|
370
|
+
- Updated dependencies [1522d06]
|
|
371
|
+
- Updated dependencies [a7b1d60]
|
|
372
|
+
- Updated dependencies [a7b1d60]
|
|
373
|
+
- @nifrajs/core@2.0.0
|
|
374
|
+
|
|
375
|
+
## 1.13.0
|
|
376
|
+
|
|
377
|
+
## 1.12.0
|
|
378
|
+
|
|
379
|
+
### Minor Changes
|
|
380
|
+
|
|
381
|
+
- 63d3845: Add bounded execution-causality contracts and propagation, OpenTelemetry causal links, event-envelope lineage, and a deterministic durable failure laboratory. `nifra levels` L4 now uses the deep adversarial contract engine through its explicitly isolated executor. Also add hash-verifiable adapter certification profiles and duplicate physical Nifra/React install detection in `nifra doctor`/`nifra check`.
|
|
382
|
+
|
|
383
|
+
## 1.11.0
|
|
384
|
+
|
|
385
|
+
## 1.10.0
|
|
386
|
+
|
|
387
|
+
## 1.9.1
|
|
388
|
+
|
|
389
|
+
## 1.9.0
|
|
390
|
+
|
|
391
|
+
## 1.8.0
|
|
392
|
+
|
|
393
|
+
## 1.7.0
|
|
394
|
+
|
|
395
|
+
## 1.6.0
|
|
396
|
+
|
|
397
|
+
### Minor Changes
|
|
398
|
+
|
|
399
|
+
- d228ac4: `ActiveObservation.setAttributes(attributes)` - merge attributes onto the in-flight request span from a handler or later plugin (`c.observation.setAttributes({ "tenant.key": ... })`), for facts learned mid-request (authenticated principal, flag bucket, cache verdict). Silently a no-op once the observation has ended; the exported span stays immutable.
|
|
400
|
+
|
|
401
|
+
## 1.5.0
|
|
402
|
+
|
|
403
|
+
### Patch Changes
|
|
404
|
+
|
|
405
|
+
- bd3433f: Security + correctness hardening: `FileStorage` refuses paths that cross symbolic links (component-wise `lstat` walk + `O_NOFOLLOW` writes; `list()` skips symlinks) so a planted symlink can no longer redirect reads/writes outside the storage root. OTel spans no longer copy raw `Error.message` into exported attributes (exception text routinely carries credentials/URLs); spans record `error.recorded: true` instead. New `onResponseFinalized` terminal observer on the server (`Middleware.onResponseFinalized` / `ResponseFinalization`) runs after every transforming `onResponse` hook and is fail-open - tracing now records the true final status even when a later hook rewrites or throws. OpenAPI generation sanitizes URI-style `$id` values into valid component names/`$ref` pointers (hex-derived, collision-suffixed) and is immune to `__proto__` key pollution.
|
|
406
|
+
|
|
407
|
+
## 1.4.0
|
|
408
|
+
|
|
409
|
+
### Minor Changes
|
|
410
|
+
|
|
411
|
+
- 4d25970: Add one fail-open request-observation lifecycle shared by tracing, agent telemetry, and DevTools; secured development tooling; contract-based mock responses; validator-neutral schema/route reflection; executable render and storage adapter conformance modules; optional storage pagination/signing/copy capabilities; and metadata-preserving local file storage.
|
|
412
|
+
|
|
413
|
+
## 1.3.1
|
|
414
|
+
|
|
415
|
+
## 1.3.0
|
|
416
|
+
|
|
417
|
+
## 1.2.2
|
|
418
|
+
|
|
419
|
+
## 1.2.1
|
|
420
|
+
|
|
421
|
+
## 1.2.0
|
|
422
|
+
|
|
423
|
+
## 1.1.0
|
|
424
|
+
|
|
425
|
+
## 1.0.0
|
|
426
|
+
|
|
427
|
+
### Patch Changes
|
|
428
|
+
|
|
429
|
+
- Updated dependencies [f1f0e18]
|
|
430
|
+
- Updated dependencies [3efb7cd]
|
|
431
|
+
- Updated dependencies [de9675b]
|
|
432
|
+
- @nifrajs/core@1.0.0
|
|
433
|
+
|
|
434
|
+
## 1.0.0-beta.4
|
|
435
|
+
|
|
436
|
+
### Patch Changes
|
|
437
|
+
|
|
438
|
+
- @nifrajs/core@1.0.0-beta.4
|
|
439
|
+
|
|
440
|
+
## 1.0.0-beta.3
|
|
441
|
+
|
|
442
|
+
### Patch Changes
|
|
443
|
+
|
|
444
|
+
- @nifrajs/core@1.0.0-beta.3
|
|
445
|
+
|
|
446
|
+
## 0.1.0-beta.2
|
|
447
|
+
|
|
448
|
+
### Patch Changes
|
|
449
|
+
|
|
450
|
+
- @nifrajs/core@0.1.0-beta.2
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAEnE,yGAAyG;AACzG,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,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AC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,CAAA;AAEzF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAA;IACjD,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAA;CAC1C;AAED,2CAA2C;AAC3C,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAA;AAWrE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,oBAAoB,CAsDpF"}
|
package/dist/cache.js
CHANGED
|
@@ -62,8 +62,7 @@ export function cacheTracing(options = {}) {
|
|
|
62
62
|
if (event.tag !== undefined)
|
|
63
63
|
keyAttributes(attributes, event.tag, "nifra.cache.tag_prefix", "nifra.cache.tag");
|
|
64
64
|
const revalidation = event.op === "revalidate";
|
|
65
|
-
lifecycle
|
|
66
|
-
.start({
|
|
65
|
+
lifecycle.record({
|
|
67
66
|
name: `cache ${event.op}`,
|
|
68
67
|
kind: "internal",
|
|
69
68
|
startTime: event.startedAt,
|
|
@@ -71,8 +70,7 @@ export function cacheTracing(options = {}) {
|
|
|
71
70
|
...(revalidation
|
|
72
71
|
? { parent: null, links: [{ traceId: trace.traceId, spanId: trace.spanId }] }
|
|
73
72
|
: { parent: trace }),
|
|
74
|
-
})
|
|
75
|
-
.end({ status: event.outcome === "error" ? "error" : "ok", durationMs: event.durationMs });
|
|
73
|
+
}, { status: event.outcome === "error" ? "error" : "ok", durationMs: event.durationMs });
|
|
76
74
|
};
|
|
77
75
|
}
|
|
78
76
|
//# sourceMappingURL=cache.js.map
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAmC3D,MAAM,UAAU,GAAG,yBAAyB,CAAA;AAE5C,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,EAAE;QAAE,OAAO,SAAS,CAAA;IACzC,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAChC,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,UAA+B,EAAE;IAC5D,MAAM,QAAQ,GAAG;QACf,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7D,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;KAC5B,CAAA;IACD,MAAM,SAAS,GAAG,0BAA0B,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1D,MAAM,YAAY,GAAG,OAA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,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;gBAC7E,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;SACvB,EACD,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CACrF,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export { causalitySpanLink } from "./causality.js";
|
|
12
12
|
export { type EffectTracingOptions, type EffectTracingPlugin, effectTracing, } from "./effects.js";
|
|
13
|
-
export { type ActiveObservation, createObservationLifecycle, type EndObservation, type ObservationClock, type ObservationContext, type ObservationLifecycle, type ObservationLifecycleOptions, type ObservationParent, type ObservationScope, type StartObservation, } from "./lifecycle.js";
|
|
13
|
+
export { type ActiveObservation, createObservationLifecycle, type EndObservation, type ObservationClock, type ObservationContext, type ObservationLifecycle, type ObservationLifecycleOptions, type ObservationParent, type ObservationScope, type RecordingObservationLifecycle, type StartObservation, } from "./lifecycle.js";
|
|
14
14
|
export { type OtlpExporter, type OtlpExporterOptions, otlpExporter } from "./otlp.js";
|
|
15
15
|
export { type AttributeValue, combineObservationAdapters, consoleSpanExporter, type NifraSpan, type ObservationAdapter, type ObservationLink, type SpanKind, type SpanStatus, } from "./span.js";
|
|
16
16
|
export { formatTraceparent, generateSpanId, generateTraceId, type ParsedTraceparent, parseTraceparent, } from "./traceparent.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EACL,KAAK,o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MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACrF,OAAO,EACL,KAAK,cAAc,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,UAAU,GAChB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,KAAK,iBAAiB,EACtB,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAGL,aAAa,GACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAEL,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAGL,aAAa,GACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAEL,0BAA0B,GAU3B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAA+C,YAAY,EAAE,MAAM,WAAW,CAAA;AACrF,OAAO,EAEL,0BAA0B,EAC1B,mBAAmB,GAMpB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EAEf,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAA0C,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -66,6 +66,11 @@ export interface ActiveObservation {
|
|
|
66
66
|
export interface ObservationLifecycle {
|
|
67
67
|
start(input: StartObservation, additionalAdapters?: readonly ObservationAdapter[]): ActiveObservation;
|
|
68
68
|
}
|
|
69
|
+
/** Factory lifecycles can record completed work; custom start-only implementations remain valid. */
|
|
70
|
+
export interface RecordingObservationLifecycle extends ObservationLifecycle {
|
|
71
|
+
/** Record already-completed work without allocating an active observation. */
|
|
72
|
+
record(input: StartObservation, end: EndObservation): NifraSpan;
|
|
73
|
+
}
|
|
69
74
|
export interface ObservationClock {
|
|
70
75
|
/** Epoch milliseconds for interoperable start/end timestamps. */
|
|
71
76
|
wallTime(): number;
|
|
@@ -80,5 +85,5 @@ export interface ObservationLifecycleOptions {
|
|
|
80
85
|
readonly generateSpanId?: () => string;
|
|
81
86
|
}
|
|
82
87
|
/** Creates an independent lifecycle factory. Adapters are always called fail-open. */
|
|
83
|
-
export declare function createObservationLifecycle(options?: ObservationLifecycleOptions):
|
|
88
|
+
export declare function createObservationLifecycle(options?: ObservationLifecycleOptions): RecordingObservationLifecycle;
|
|
84
89
|
//# sourceMappingURL=lifecycle.d.ts.map
|
package/dist/lifecycle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,UAAU,EACX,MAAM,WAAW,CAAA;AAQlB,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,OAAO,EAAE,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WAAW,6BAA8B,SAAQ,oBAAoB;IACzE,8EAA8E;IAC9E,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,cAAc,GAAG,SAAS,CAAA;CAChE;AAED,MAAM,WAAW,gBAAgB;IAC/B,iEAAiE;IACjE,QAAQ,IAAI,MAAM,CAAA;IAClB,4CAA4C;IAC5C,aAAa,IAAI,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAA;IACjD,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAA;IACjC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,MAAM,CAAA;IACvC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,MAAM,CAAA;CACvC;AAOD,sFAAsF;AACtF,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,2BAAgC,GACxC,6BAA6B,CAsL/B"}
|
package/dist/lifecycle.js
CHANGED
|
@@ -11,6 +11,18 @@ const defaultClock = {
|
|
|
11
11
|
/** Creates an independent lifecycle factory. Adapters are always called fail-open. */
|
|
12
12
|
export function createObservationLifecycle(options = {}) {
|
|
13
13
|
const adapters = options.adapters ?? [];
|
|
14
|
+
let adapterSnapshot = [...adapters];
|
|
15
|
+
let recordedAdapters = [...new Set(adapterSnapshot)];
|
|
16
|
+
const adaptersForRecord = () => {
|
|
17
|
+
let changed = adapterSnapshot.length !== adapters.length;
|
|
18
|
+
for (let i = 0; !changed && i < adapters.length; i++)
|
|
19
|
+
changed = adapterSnapshot[i] !== adapters[i];
|
|
20
|
+
if (changed) {
|
|
21
|
+
adapterSnapshot = [...adapters];
|
|
22
|
+
recordedAdapters = [...new Set(adapterSnapshot)];
|
|
23
|
+
}
|
|
24
|
+
return recordedAdapters;
|
|
25
|
+
};
|
|
14
26
|
const clock = options.clock ?? defaultClock;
|
|
15
27
|
const newTraceId = options.generateTraceId ?? generateTraceId;
|
|
16
28
|
const newSpanId = options.generateSpanId ?? generateSpanId;
|
|
@@ -34,8 +46,7 @@ export function createObservationLifecycle(options = {}) {
|
|
|
34
46
|
}
|
|
35
47
|
}
|
|
36
48
|
};
|
|
37
|
-
const
|
|
38
|
-
const spanAdapters = new Set([...adapters, ...additionalAdapters]);
|
|
49
|
+
const makeSpan = (input) => {
|
|
39
50
|
const parent = input.parent === undefined ? parseTraceparent(input.traceparent ?? null) : input.parent;
|
|
40
51
|
const traceId = parent?.traceId ?? newTraceId();
|
|
41
52
|
const spanId = newSpanId();
|
|
@@ -43,8 +54,7 @@ export function createObservationLifecycle(options = {}) {
|
|
|
43
54
|
const startTime = input.startTime !== undefined && Number.isFinite(input.startTime)
|
|
44
55
|
? input.startTime
|
|
45
56
|
: clock.wallTime();
|
|
46
|
-
|
|
47
|
-
const span = {
|
|
57
|
+
return {
|
|
48
58
|
traceId,
|
|
49
59
|
spanId,
|
|
50
60
|
...(parent === null ? {} : { parentSpanId: parent.spanId }),
|
|
@@ -66,10 +76,38 @@ export function createObservationLifecycle(options = {}) {
|
|
|
66
76
|
}))),
|
|
67
77
|
}),
|
|
68
78
|
};
|
|
79
|
+
};
|
|
80
|
+
const finish = (span, endInput, monotonicStart, recordedError = false) => {
|
|
81
|
+
Object.assign(span.attributes, endInput.attributes);
|
|
82
|
+
if (endInput.durationMs !== undefined && Number.isFinite(endInput.durationMs)) {
|
|
83
|
+
span.durationMs = Math.max(0, endInput.durationMs);
|
|
84
|
+
span.endTime = span.startTime + span.durationMs;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
span.endTime = clock.wallTime();
|
|
88
|
+
span.durationMs = Math.max(0, clock.monotonicTime() - monotonicStart);
|
|
89
|
+
}
|
|
90
|
+
span.status =
|
|
91
|
+
endInput.status ??
|
|
92
|
+
(endInput.statusCode === undefined
|
|
93
|
+
? recordedError
|
|
94
|
+
? "error"
|
|
95
|
+
: "ok"
|
|
96
|
+
: endInput.statusCode >= 500
|
|
97
|
+
? "error"
|
|
98
|
+
: "ok");
|
|
99
|
+
Object.freeze(span.attributes);
|
|
100
|
+
return Object.freeze(span);
|
|
101
|
+
};
|
|
102
|
+
const start = (input, additionalAdapters = []) => {
|
|
103
|
+
const spanAdapters = new Set([...adapters, ...additionalAdapters]);
|
|
104
|
+
const span = makeSpan(input);
|
|
105
|
+
const { traceId, spanId, parentSpanId, sampled } = span;
|
|
106
|
+
const monotonicStart = clock.monotonicTime();
|
|
69
107
|
const context = {
|
|
70
108
|
traceId,
|
|
71
109
|
spanId,
|
|
72
|
-
...(
|
|
110
|
+
...(parentSpanId === undefined ? {} : { parentSpanId }),
|
|
73
111
|
sampled,
|
|
74
112
|
traceparent: formatTraceparent(traceId, spanId, sampled),
|
|
75
113
|
};
|
|
@@ -113,29 +151,7 @@ export function createObservationLifecycle(options = {}) {
|
|
|
113
151
|
if (ended)
|
|
114
152
|
return span;
|
|
115
153
|
ended = true;
|
|
116
|
-
|
|
117
|
-
if (endInput.durationMs !== undefined && Number.isFinite(endInput.durationMs)) {
|
|
118
|
-
span.durationMs = Math.max(0, endInput.durationMs);
|
|
119
|
-
span.endTime = span.startTime + span.durationMs;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
span.endTime = clock.wallTime();
|
|
123
|
-
span.durationMs = Math.max(0, clock.monotonicTime() - monotonicStart);
|
|
124
|
-
}
|
|
125
|
-
span.status =
|
|
126
|
-
endInput.status ??
|
|
127
|
-
(endInput.statusCode === undefined
|
|
128
|
-
? recordedError
|
|
129
|
-
? "error"
|
|
130
|
-
: "ok"
|
|
131
|
-
: endInput.statusCode >= 500
|
|
132
|
-
? "error"
|
|
133
|
-
: "ok");
|
|
134
|
-
// Publish an immutable completed span: a misbehaving adapter can no longer mutate the shared
|
|
135
|
-
// attributes bag and corrupt what other adapters (or the caller) observe. Adapters are fail-open,
|
|
136
|
-
// so a stray write throws into their own try/catch rather than changing request behavior.
|
|
137
|
-
Object.freeze(span.attributes);
|
|
138
|
-
Object.freeze(span);
|
|
154
|
+
finish(span, endInput, monotonicStart, recordedError);
|
|
139
155
|
notifyEnd(span, [...spanAdapters]);
|
|
140
156
|
return span;
|
|
141
157
|
},
|
|
@@ -143,6 +159,19 @@ export function createObservationLifecycle(options = {}) {
|
|
|
143
159
|
notifyStart(span, [...spanAdapters]);
|
|
144
160
|
return active;
|
|
145
161
|
};
|
|
146
|
-
return {
|
|
162
|
+
return {
|
|
163
|
+
start,
|
|
164
|
+
record(input, endInput) {
|
|
165
|
+
const spanAdapters = adaptersForRecord();
|
|
166
|
+
const span = makeSpan(input);
|
|
167
|
+
const monotonicStart = endInput.durationMs !== undefined && Number.isFinite(endInput.durationMs)
|
|
168
|
+
? 0
|
|
169
|
+
: clock.monotonicTime();
|
|
170
|
+
notifyStart(span, spanAdapters);
|
|
171
|
+
finish(span, endInput, monotonicStart);
|
|
172
|
+
notifyEnd(span, spanAdapters);
|
|
173
|
+
return span;
|
|
174
|
+
},
|
|
175
|
+
};
|
|
147
176
|
}
|
|
148
177
|
//# sourceMappingURL=lifecycle.js.map
|
package/dist/lifecycle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AAkGzB,MAAM,YAAY,GAAqB;IACrC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IAC1B,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,WAAW,K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,CAAA;QAC1B,mFAAmF;QACnF,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAClC,CAAA;IACD;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,qGAAqG;IACrG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C,uEAAuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAChG;AAED,MAAM,WAAW,YAAa,SAAQ,kBAAkB;IACtD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,0GAA0G;IAC1G,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAiED,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAuIvE"}
|
package/dist/otlp.js
CHANGED
|
@@ -77,10 +77,12 @@ export function otlpExporter(options) {
|
|
|
77
77
|
const resourceAttributes = keyValues({ "service.name": options.serviceName ?? "nifra" });
|
|
78
78
|
const queue = [];
|
|
79
79
|
let timer;
|
|
80
|
-
// Spans ever queued,
|
|
81
|
-
//
|
|
80
|
+
// Spans ever queued, numbered in order. The queue holds the newest `queue.length` of them and the
|
|
81
|
+
// batch in flight the run starting at `inFlightFrom`, so every span numbered below the older of the
|
|
82
|
+
// two has been sent, failed or dropped. A count of settled spans is not enough: a later span dropped
|
|
83
|
+
// on overflow would count toward an earlier flush whose batch is still exporting.
|
|
82
84
|
let queued = 0;
|
|
83
|
-
let
|
|
85
|
+
let inFlightFrom;
|
|
84
86
|
const waiters = [];
|
|
85
87
|
let pumping = false;
|
|
86
88
|
const report = (error) => {
|
|
@@ -133,11 +135,11 @@ export function otlpExporter(options) {
|
|
|
133
135
|
clearTimeout(deadline);
|
|
134
136
|
}
|
|
135
137
|
};
|
|
136
|
-
const settle = (
|
|
137
|
-
|
|
138
|
+
const settle = () => {
|
|
139
|
+
const unsettled = inFlightFrom ?? queued - queue.length;
|
|
138
140
|
for (let i = waiters.length - 1; i >= 0; i--) {
|
|
139
141
|
const waiter = waiters[i];
|
|
140
|
-
if (waiter === undefined || waiter.mark >
|
|
142
|
+
if (waiter === undefined || waiter.mark > unsettled)
|
|
141
143
|
continue;
|
|
142
144
|
waiters.splice(i, 1);
|
|
143
145
|
waiter.resolve();
|
|
@@ -146,9 +148,11 @@ export function otlpExporter(options) {
|
|
|
146
148
|
// One export in flight at a time; spans arriving meanwhile wait in the bounded queue.
|
|
147
149
|
const pump = async () => {
|
|
148
150
|
while (queue.length > 0) {
|
|
151
|
+
inFlightFrom = queued - queue.length;
|
|
149
152
|
const batch = queue.splice(0, maxBatch);
|
|
150
153
|
await send(batch);
|
|
151
|
-
|
|
154
|
+
inFlightFrom = undefined;
|
|
155
|
+
settle();
|
|
152
156
|
}
|
|
153
157
|
};
|
|
154
158
|
const kick = () => {
|
|
@@ -162,7 +166,7 @@ export function otlpExporter(options) {
|
|
|
162
166
|
});
|
|
163
167
|
};
|
|
164
168
|
const flush = () => {
|
|
165
|
-
if (
|
|
169
|
+
if (inFlightFrom === undefined && queue.length === 0)
|
|
166
170
|
return Promise.resolve();
|
|
167
171
|
const done = new Promise((resolve) => waiters.push({ mark: queued, resolve }));
|
|
168
172
|
kick();
|
|
@@ -180,7 +184,7 @@ export function otlpExporter(options) {
|
|
|
180
184
|
queued++;
|
|
181
185
|
if (queue.length > maxQueue) {
|
|
182
186
|
queue.shift(); // drop the oldest under sustained backpressure rather than grow unbounded
|
|
183
|
-
settle(
|
|
187
|
+
settle();
|
|
184
188
|
report(new Error("otlp_queue_overflow_span_dropped"));
|
|
185
189
|
}
|
|
186
190
|
if (queue.length >= maxBatch)
|
package/dist/otlp.js.map
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ACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nifrajs/otel",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Distributed tracing for nifra - W3C traceparent/tracestate propagation + OpenTelemetry-semantic-convention spans via a pluggable exporter. Bridge to the OpenTelemetry SDK or log spans directly; no SDK bundled. Edge-safe.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
},
|
|
62
62
|
"files": [
|
|
63
63
|
"dist",
|
|
64
|
-
"src"
|
|
64
|
+
"src",
|
|
65
|
+
"CHANGELOG.md"
|
|
65
66
|
],
|
|
66
67
|
"sideEffects": false,
|
|
67
68
|
"scripts": {
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
"access": "public"
|
|
73
74
|
},
|
|
74
75
|
"peerDependencies": {
|
|
75
|
-
"@nifrajs/core": "^5.
|
|
76
|
+
"@nifrajs/core": "^5.3.0"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
79
|
"@nifrajs/cache": "workspace:*",
|
package/src/cache.ts
CHANGED
|
@@ -100,8 +100,8 @@ export function cacheTracing(options: CacheTracingOptions = {}): CacheTracingObs
|
|
|
100
100
|
if (event.tag !== undefined)
|
|
101
101
|
keyAttributes(attributes, event.tag, "nifra.cache.tag_prefix", "nifra.cache.tag")
|
|
102
102
|
const revalidation = event.op === "revalidate"
|
|
103
|
-
lifecycle
|
|
104
|
-
|
|
103
|
+
lifecycle.record(
|
|
104
|
+
{
|
|
105
105
|
name: `cache ${event.op}`,
|
|
106
106
|
kind: "internal",
|
|
107
107
|
startTime: event.startedAt,
|
|
@@ -109,7 +109,8 @@ export function cacheTracing(options: CacheTracingOptions = {}): CacheTracingObs
|
|
|
109
109
|
...(revalidation
|
|
110
110
|
? { parent: null, links: [{ traceId: trace.traceId, spanId: trace.spanId }] }
|
|
111
111
|
: { parent: trace }),
|
|
112
|
-
}
|
|
113
|
-
|
|
112
|
+
},
|
|
113
|
+
{ status: event.outcome === "error" ? "error" : "ok", durationMs: event.durationMs },
|
|
114
|
+
)
|
|
114
115
|
}
|
|
115
116
|
}
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ export {
|
|
|
25
25
|
type ObservationLifecycleOptions,
|
|
26
26
|
type ObservationParent,
|
|
27
27
|
type ObservationScope,
|
|
28
|
+
type RecordingObservationLifecycle,
|
|
28
29
|
type StartObservation,
|
|
29
30
|
} from "./lifecycle.ts"
|
|
30
31
|
export { type OtlpExporter, type OtlpExporterOptions, otlpExporter } from "./otlp.ts"
|
package/src/lifecycle.ts
CHANGED
|
@@ -94,6 +94,12 @@ export interface ObservationLifecycle {
|
|
|
94
94
|
): ActiveObservation
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/** Factory lifecycles can record completed work; custom start-only implementations remain valid. */
|
|
98
|
+
export interface RecordingObservationLifecycle extends ObservationLifecycle {
|
|
99
|
+
/** Record already-completed work without allocating an active observation. */
|
|
100
|
+
record(input: StartObservation, end: EndObservation): NifraSpan
|
|
101
|
+
}
|
|
102
|
+
|
|
97
103
|
export interface ObservationClock {
|
|
98
104
|
/** Epoch milliseconds for interoperable start/end timestamps. */
|
|
99
105
|
wallTime(): number
|
|
@@ -117,8 +123,20 @@ const defaultClock: ObservationClock = {
|
|
|
117
123
|
/** Creates an independent lifecycle factory. Adapters are always called fail-open. */
|
|
118
124
|
export function createObservationLifecycle(
|
|
119
125
|
options: ObservationLifecycleOptions = {},
|
|
120
|
-
):
|
|
126
|
+
): RecordingObservationLifecycle {
|
|
121
127
|
const adapters = options.adapters ?? []
|
|
128
|
+
let adapterSnapshot = [...adapters]
|
|
129
|
+
let recordedAdapters = [...new Set(adapterSnapshot)]
|
|
130
|
+
const adaptersForRecord = (): readonly ObservationAdapter[] => {
|
|
131
|
+
let changed = adapterSnapshot.length !== adapters.length
|
|
132
|
+
for (let i = 0; !changed && i < adapters.length; i++)
|
|
133
|
+
changed = adapterSnapshot[i] !== adapters[i]
|
|
134
|
+
if (changed) {
|
|
135
|
+
adapterSnapshot = [...adapters]
|
|
136
|
+
recordedAdapters = [...new Set(adapterSnapshot)]
|
|
137
|
+
}
|
|
138
|
+
return recordedAdapters
|
|
139
|
+
}
|
|
122
140
|
const clock = options.clock ?? defaultClock
|
|
123
141
|
const newTraceId = options.generateTraceId ?? generateTraceId
|
|
124
142
|
const newSpanId = options.generateSpanId ?? generateSpanId
|
|
@@ -143,11 +161,7 @@ export function createObservationLifecycle(
|
|
|
143
161
|
}
|
|
144
162
|
}
|
|
145
163
|
|
|
146
|
-
const
|
|
147
|
-
input: StartObservation,
|
|
148
|
-
additionalAdapters: readonly ObservationAdapter[] = [],
|
|
149
|
-
): ActiveObservation => {
|
|
150
|
-
const spanAdapters = new Set([...adapters, ...additionalAdapters])
|
|
164
|
+
const makeSpan = (input: StartObservation): NifraSpan => {
|
|
151
165
|
const parent =
|
|
152
166
|
input.parent === undefined ? parseTraceparent(input.traceparent ?? null) : input.parent
|
|
153
167
|
const traceId = parent?.traceId ?? newTraceId()
|
|
@@ -157,8 +171,7 @@ export function createObservationLifecycle(
|
|
|
157
171
|
input.startTime !== undefined && Number.isFinite(input.startTime)
|
|
158
172
|
? input.startTime
|
|
159
173
|
: clock.wallTime()
|
|
160
|
-
|
|
161
|
-
const span: NifraSpan = {
|
|
174
|
+
return {
|
|
162
175
|
traceId,
|
|
163
176
|
spanId,
|
|
164
177
|
...(parent === null ? {} : { parentSpanId: parent.spanId }),
|
|
@@ -184,10 +197,47 @@ export function createObservationLifecycle(
|
|
|
184
197
|
),
|
|
185
198
|
}),
|
|
186
199
|
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const finish = (
|
|
203
|
+
span: NifraSpan,
|
|
204
|
+
endInput: EndObservation,
|
|
205
|
+
monotonicStart: number,
|
|
206
|
+
recordedError = false,
|
|
207
|
+
): NifraSpan => {
|
|
208
|
+
Object.assign(span.attributes, endInput.attributes)
|
|
209
|
+
if (endInput.durationMs !== undefined && Number.isFinite(endInput.durationMs)) {
|
|
210
|
+
span.durationMs = Math.max(0, endInput.durationMs)
|
|
211
|
+
span.endTime = span.startTime + span.durationMs
|
|
212
|
+
} else {
|
|
213
|
+
span.endTime = clock.wallTime()
|
|
214
|
+
span.durationMs = Math.max(0, clock.monotonicTime() - monotonicStart)
|
|
215
|
+
}
|
|
216
|
+
span.status =
|
|
217
|
+
endInput.status ??
|
|
218
|
+
(endInput.statusCode === undefined
|
|
219
|
+
? recordedError
|
|
220
|
+
? "error"
|
|
221
|
+
: "ok"
|
|
222
|
+
: endInput.statusCode >= 500
|
|
223
|
+
? "error"
|
|
224
|
+
: "ok")
|
|
225
|
+
Object.freeze(span.attributes)
|
|
226
|
+
return Object.freeze(span)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const start = (
|
|
230
|
+
input: StartObservation,
|
|
231
|
+
additionalAdapters: readonly ObservationAdapter[] = [],
|
|
232
|
+
): ActiveObservation => {
|
|
233
|
+
const spanAdapters = new Set([...adapters, ...additionalAdapters])
|
|
234
|
+
const span = makeSpan(input)
|
|
235
|
+
const { traceId, spanId, parentSpanId, sampled } = span
|
|
236
|
+
const monotonicStart = clock.monotonicTime()
|
|
187
237
|
const context: ObservationContext = {
|
|
188
238
|
traceId,
|
|
189
239
|
spanId,
|
|
190
|
-
...(
|
|
240
|
+
...(parentSpanId === undefined ? {} : { parentSpanId }),
|
|
191
241
|
sampled,
|
|
192
242
|
traceparent: formatTraceparent(traceId, spanId, sampled),
|
|
193
243
|
}
|
|
@@ -230,28 +280,7 @@ export function createObservationLifecycle(
|
|
|
230
280
|
end(endInput = {}) {
|
|
231
281
|
if (ended) return span
|
|
232
282
|
ended = true
|
|
233
|
-
|
|
234
|
-
if (endInput.durationMs !== undefined && Number.isFinite(endInput.durationMs)) {
|
|
235
|
-
span.durationMs = Math.max(0, endInput.durationMs)
|
|
236
|
-
span.endTime = span.startTime + span.durationMs
|
|
237
|
-
} else {
|
|
238
|
-
span.endTime = clock.wallTime()
|
|
239
|
-
span.durationMs = Math.max(0, clock.monotonicTime() - monotonicStart)
|
|
240
|
-
}
|
|
241
|
-
span.status =
|
|
242
|
-
endInput.status ??
|
|
243
|
-
(endInput.statusCode === undefined
|
|
244
|
-
? recordedError
|
|
245
|
-
? "error"
|
|
246
|
-
: "ok"
|
|
247
|
-
: endInput.statusCode >= 500
|
|
248
|
-
? "error"
|
|
249
|
-
: "ok")
|
|
250
|
-
// Publish an immutable completed span: a misbehaving adapter can no longer mutate the shared
|
|
251
|
-
// attributes bag and corrupt what other adapters (or the caller) observe. Adapters are fail-open,
|
|
252
|
-
// so a stray write throws into their own try/catch rather than changing request behavior.
|
|
253
|
-
Object.freeze(span.attributes)
|
|
254
|
-
Object.freeze(span)
|
|
283
|
+
finish(span, endInput, monotonicStart, recordedError)
|
|
255
284
|
notifyEnd(span, [...spanAdapters])
|
|
256
285
|
return span
|
|
257
286
|
},
|
|
@@ -261,5 +290,19 @@ export function createObservationLifecycle(
|
|
|
261
290
|
return active
|
|
262
291
|
}
|
|
263
292
|
|
|
264
|
-
return {
|
|
293
|
+
return {
|
|
294
|
+
start,
|
|
295
|
+
record(input, endInput) {
|
|
296
|
+
const spanAdapters = adaptersForRecord()
|
|
297
|
+
const span = makeSpan(input)
|
|
298
|
+
const monotonicStart =
|
|
299
|
+
endInput.durationMs !== undefined && Number.isFinite(endInput.durationMs)
|
|
300
|
+
? 0
|
|
301
|
+
: clock.monotonicTime()
|
|
302
|
+
notifyStart(span, spanAdapters)
|
|
303
|
+
finish(span, endInput, monotonicStart)
|
|
304
|
+
notifyEnd(span, spanAdapters)
|
|
305
|
+
return span
|
|
306
|
+
},
|
|
307
|
+
}
|
|
265
308
|
}
|
package/src/otlp.ts
CHANGED
|
@@ -125,10 +125,12 @@ export function otlpExporter(options: OtlpExporterOptions): OtlpExporter {
|
|
|
125
125
|
|
|
126
126
|
const queue: NifraSpan[] = []
|
|
127
127
|
let timer: ReturnType<typeof setInterval> | undefined
|
|
128
|
-
// Spans ever queued,
|
|
129
|
-
//
|
|
128
|
+
// Spans ever queued, numbered in order. The queue holds the newest `queue.length` of them and the
|
|
129
|
+
// batch in flight the run starting at `inFlightFrom`, so every span numbered below the older of the
|
|
130
|
+
// two has been sent, failed or dropped. A count of settled spans is not enough: a later span dropped
|
|
131
|
+
// on overflow would count toward an earlier flush whose batch is still exporting.
|
|
130
132
|
let queued = 0
|
|
131
|
-
let
|
|
133
|
+
let inFlightFrom: number | undefined
|
|
132
134
|
const waiters: Array<{ readonly mark: number; readonly resolve: () => void }> = []
|
|
133
135
|
let pumping = false
|
|
134
136
|
|
|
@@ -180,11 +182,11 @@ export function otlpExporter(options: OtlpExporterOptions): OtlpExporter {
|
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
|
|
183
|
-
const settle = (
|
|
184
|
-
|
|
185
|
+
const settle = (): void => {
|
|
186
|
+
const unsettled = inFlightFrom ?? queued - queue.length
|
|
185
187
|
for (let i = waiters.length - 1; i >= 0; i--) {
|
|
186
188
|
const waiter = waiters[i]
|
|
187
|
-
if (waiter === undefined || waiter.mark >
|
|
189
|
+
if (waiter === undefined || waiter.mark > unsettled) continue
|
|
188
190
|
waiters.splice(i, 1)
|
|
189
191
|
waiter.resolve()
|
|
190
192
|
}
|
|
@@ -193,9 +195,11 @@ export function otlpExporter(options: OtlpExporterOptions): OtlpExporter {
|
|
|
193
195
|
// One export in flight at a time; spans arriving meanwhile wait in the bounded queue.
|
|
194
196
|
const pump = async (): Promise<void> => {
|
|
195
197
|
while (queue.length > 0) {
|
|
198
|
+
inFlightFrom = queued - queue.length
|
|
196
199
|
const batch = queue.splice(0, maxBatch)
|
|
197
200
|
await send(batch)
|
|
198
|
-
|
|
201
|
+
inFlightFrom = undefined
|
|
202
|
+
settle()
|
|
199
203
|
}
|
|
200
204
|
}
|
|
201
205
|
|
|
@@ -209,7 +213,7 @@ export function otlpExporter(options: OtlpExporterOptions): OtlpExporter {
|
|
|
209
213
|
}
|
|
210
214
|
|
|
211
215
|
const flush = (): Promise<void> => {
|
|
212
|
-
if (
|
|
216
|
+
if (inFlightFrom === undefined && queue.length === 0) return Promise.resolve()
|
|
213
217
|
const done = new Promise<void>((resolve) => waiters.push({ mark: queued, resolve }))
|
|
214
218
|
kick()
|
|
215
219
|
return done
|
|
@@ -227,7 +231,7 @@ export function otlpExporter(options: OtlpExporterOptions): OtlpExporter {
|
|
|
227
231
|
queued++
|
|
228
232
|
if (queue.length > maxQueue) {
|
|
229
233
|
queue.shift() // drop the oldest under sustained backpressure rather than grow unbounded
|
|
230
|
-
settle(
|
|
234
|
+
settle()
|
|
231
235
|
report(new Error("otlp_queue_overflow_span_dropped"))
|
|
232
236
|
}
|
|
233
237
|
if (queue.length >= maxBatch) kick()
|