@veryfront/ext-content-mdx 0.1.1186 → 0.1.1189
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/esm/_dnt.polyfills.d.ts +6 -6
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/deno.d.ts +18 -0
- package/esm/deno.js +30 -9
- package/esm/src/config/defaults.d.ts +31 -24
- package/esm/src/config/defaults.d.ts.map +1 -1
- package/esm/src/config/defaults.js +25 -18
- package/esm/src/errors/diagnostic-policy.d.ts +35 -0
- package/esm/src/errors/diagnostic-policy.d.ts.map +1 -0
- package/esm/src/errors/diagnostic-policy.js +100 -0
- package/esm/src/errors/error-registry/boundary.d.ts +2 -0
- package/esm/src/errors/error-registry/boundary.d.ts.map +1 -1
- package/esm/src/errors/error-registry/boundary.js +8 -0
- package/esm/src/errors/error-registry/config.d.ts.map +1 -1
- package/esm/src/errors/error-registry/config.js +3 -3
- package/esm/src/errors/error-registry/deploy.js +1 -1
- package/esm/src/errors/error-registry/server.d.ts +2 -0
- package/esm/src/errors/error-registry/server.d.ts.map +1 -1
- package/esm/src/errors/error-registry/server.js +8 -0
- package/esm/src/errors/error-registry-helpers.d.ts +11 -2
- package/esm/src/errors/error-registry-helpers.d.ts.map +1 -1
- package/esm/src/errors/error-registry-helpers.js +70 -1
- package/esm/src/errors/error-registry.d.ts +85 -73
- package/esm/src/errors/error-registry.d.ts.map +1 -1
- package/esm/src/errors/error-registry.js +2 -14
- package/esm/src/errors/types.d.ts +44 -5
- package/esm/src/errors/types.d.ts.map +1 -1
- package/esm/src/errors/types.js +148 -24
- package/esm/src/errors/veryfront-error.d.ts +25 -2
- package/esm/src/errors/veryfront-error.d.ts.map +1 -1
- package/esm/src/errors/veryfront-error.js +638 -28
- package/esm/src/observability/limits.d.ts +20 -0
- package/esm/src/observability/limits.d.ts.map +1 -0
- package/esm/src/observability/limits.js +19 -0
- package/esm/src/observability/telemetry-error.d.ts +22 -0
- package/esm/src/observability/telemetry-error.d.ts.map +1 -0
- package/esm/src/observability/telemetry-error.js +377 -0
- package/esm/src/observability/tracing/api-shim.d.ts +39 -0
- package/esm/src/observability/tracing/api-shim.d.ts.map +1 -1
- package/esm/src/observability/tracing/api-shim.js +196 -69
- package/esm/src/observability/tracing/context-callback.d.ts +14 -0
- package/esm/src/observability/tracing/context-callback.d.ts.map +1 -0
- package/esm/src/observability/tracing/context-callback.js +111 -0
- package/esm/src/observability/tracing/otlp-setup.d.ts.map +1 -1
- package/esm/src/observability/tracing/otlp-setup.js +190 -46
- package/esm/src/platform/adapters/base.d.ts +51 -7
- package/esm/src/platform/adapters/base.d.ts.map +1 -1
- package/esm/src/platform/adapters/base.js +4 -2
- package/esm/src/platform/adapters/bounded-file-read.d.ts +9 -0
- package/esm/src/platform/adapters/bounded-file-read.d.ts.map +1 -1
- package/esm/src/platform/adapters/bounded-file-read.js +11 -5
- package/esm/src/platform/adapters/file-snapshot-error.d.ts +2 -0
- package/esm/src/platform/adapters/file-snapshot-error.d.ts.map +1 -1
- package/esm/src/platform/adapters/file-snapshot-error.js +2 -0
- package/esm/src/platform/adapters/file-system-capabilities.d.ts +74 -0
- package/esm/src/platform/adapters/file-system-capabilities.d.ts.map +1 -0
- package/esm/src/platform/adapters/file-system-capabilities.js +508 -0
- package/esm/src/platform/adapters/native-file-system-provenance.d.ts +6 -0
- package/esm/src/platform/adapters/native-file-system-provenance.d.ts.map +1 -0
- package/esm/src/platform/adapters/native-file-system-provenance.js +15 -0
- package/esm/src/platform/adapters/runtime/deno/filesystem-adapter.d.ts +45 -0
- package/esm/src/platform/adapters/runtime/deno/filesystem-adapter.d.ts.map +1 -0
- package/esm/src/platform/adapters/runtime/deno/filesystem-adapter.js +291 -0
- package/esm/src/platform/adapters/runtime/shared/node-filesystem-adapter.d.ts +71 -0
- package/esm/src/platform/adapters/runtime/shared/node-filesystem-adapter.d.ts.map +1 -0
- package/esm/src/platform/adapters/runtime/shared/node-filesystem-adapter.js +471 -0
- package/esm/src/platform/adapters/runtime/shared/shared-watcher.d.ts +16 -0
- package/esm/src/platform/adapters/runtime/shared/shared-watcher.d.ts.map +1 -0
- package/esm/src/platform/adapters/runtime/shared/shared-watcher.js +140 -0
- package/esm/src/platform/adapters/runtime/shared/temp-dir.d.ts +2 -0
- package/esm/src/platform/adapters/runtime/shared/temp-dir.d.ts.map +1 -0
- package/esm/src/platform/adapters/runtime/shared/temp-dir.js +10 -0
- package/esm/src/platform/adapters/runtime/shared/watcher-queue.d.ts +5 -0
- package/esm/src/platform/adapters/runtime/shared/watcher-queue.d.ts.map +1 -0
- package/esm/src/platform/adapters/runtime/shared/watcher-queue.js +75 -0
- package/esm/src/platform/compat/abort-signal.d.ts +20 -0
- package/esm/src/platform/compat/abort-signal.d.ts.map +1 -0
- package/esm/src/platform/compat/abort-signal.js +64 -0
- package/esm/src/platform/compat/constants.d.ts +2 -2
- package/esm/src/platform/compat/constants.d.ts.map +1 -1
- package/esm/src/platform/compat/constants.js +2 -2
- package/esm/src/platform/compat/error-introspection.d.ts +37 -0
- package/esm/src/platform/compat/error-introspection.d.ts.map +1 -0
- package/esm/src/platform/compat/error-introspection.js +258 -0
- package/esm/src/platform/compat/fs.d.ts +29 -8
- package/esm/src/platform/compat/fs.d.ts.map +1 -1
- package/esm/src/platform/compat/fs.js +123 -57
- package/esm/src/platform/compat/native-brand-checks.d.ts +14 -0
- package/esm/src/platform/compat/native-brand-checks.d.ts.map +1 -0
- package/esm/src/platform/compat/native-brand-checks.js +68 -0
- package/esm/src/platform/compat/not-found-error.d.ts +8 -3
- package/esm/src/platform/compat/not-found-error.d.ts.map +1 -1
- package/esm/src/platform/compat/not-found-error.js +164 -31
- package/esm/src/platform/compat/path/security.d.ts.map +1 -1
- package/esm/src/platform/compat/path/security.js +3 -5
- package/esm/src/platform/compat/process/command.d.ts +24 -1
- package/esm/src/platform/compat/process/command.d.ts.map +1 -1
- package/esm/src/platform/compat/process/command.js +393 -78
- package/esm/src/platform/compat/process/env.d.ts +11 -0
- package/esm/src/platform/compat/process/env.d.ts.map +1 -1
- package/esm/src/platform/compat/process/env.js +28 -38
- package/esm/src/platform/compat/process/global-error.d.ts +19 -0
- package/esm/src/platform/compat/process/global-error.d.ts.map +1 -0
- package/esm/src/platform/compat/process/global-error.js +57 -0
- package/esm/src/platform/compat/process/lifecycle.d.ts +10 -3
- package/esm/src/platform/compat/process/lifecycle.d.ts.map +1 -1
- package/esm/src/platform/compat/process/lifecycle.js +74 -23
- package/esm/src/platform/compat/process/project-env-contract.d.ts +19 -0
- package/esm/src/platform/compat/process/project-env-contract.d.ts.map +1 -0
- package/esm/src/platform/compat/process/project-env-contract.js +19 -0
- package/esm/src/platform/compat/runtime.d.ts +14 -5
- package/esm/src/platform/compat/runtime.d.ts.map +1 -1
- package/esm/src/platform/compat/runtime.js +34 -9
- package/esm/src/platform/compat/std/front-matter-yaml.d.ts +12 -0
- package/esm/src/platform/compat/std/front-matter-yaml.d.ts.map +1 -1
- package/esm/src/platform/compat/std/front-matter-yaml.js +35 -3
- package/esm/src/platform/compat/temp-directory-prefix.d.ts +8 -0
- package/esm/src/platform/compat/temp-directory-prefix.d.ts.map +1 -0
- package/esm/src/platform/compat/temp-directory-prefix.js +15 -0
- package/esm/src/utils/abort.d.ts +10 -0
- package/esm/src/utils/abort.d.ts.map +1 -0
- package/esm/src/utils/abort.js +35 -0
- package/esm/src/utils/constants/build.d.ts +3 -0
- package/esm/src/utils/constants/build.d.ts.map +1 -1
- package/esm/src/utils/constants/build.js +5 -1
- package/esm/src/utils/constants/cache.d.ts +21 -0
- package/esm/src/utils/constants/cache.d.ts.map +1 -1
- package/esm/src/utils/constants/cache.js +101 -39
- package/esm/src/utils/constants/css.d.ts +20 -0
- package/esm/src/utils/constants/css.d.ts.map +1 -0
- package/esm/src/utils/constants/css.js +19 -0
- package/esm/src/utils/constants/limits.d.ts +4 -0
- package/esm/src/utils/constants/limits.d.ts.map +1 -1
- package/esm/src/utils/constants/limits.js +4 -0
- package/esm/src/utils/constants/project-identity.d.ts +5 -0
- package/esm/src/utils/constants/project-identity.d.ts.map +1 -0
- package/esm/src/utils/constants/project-identity.js +4 -0
- package/esm/src/utils/constants/retry.d.ts +18 -0
- package/esm/src/utils/constants/retry.d.ts.map +1 -1
- package/esm/src/utils/constants/retry.js +18 -0
- package/esm/src/utils/constants/security.d.ts +4 -0
- package/esm/src/utils/constants/security.d.ts.map +1 -1
- package/esm/src/utils/constants/security.js +4 -0
- package/esm/src/utils/index.d.ts +3 -1
- package/esm/src/utils/index.d.ts.map +1 -1
- package/esm/src/utils/index.js +3 -1
- package/esm/src/utils/logger/core.d.ts +5 -0
- package/esm/src/utils/logger/core.d.ts.map +1 -1
- package/esm/src/utils/logger/core.js +67 -2
- package/esm/src/utils/logger/redact.d.ts +36 -13
- package/esm/src/utils/logger/redact.d.ts.map +1 -1
- package/esm/src/utils/logger/redact.js +573 -83
- package/esm/src/utils/parallel.d.ts.map +1 -1
- package/esm/src/utils/parallel.js +11 -1
- package/esm/src/utils/project-identity.d.ts +11 -0
- package/esm/src/utils/project-identity.d.ts.map +1 -0
- package/esm/src/utils/project-identity.js +69 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +3 -3
- package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.d.ts +0 -33
- package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.d.ts.map +0 -1
- package/esm/src/platform/adapters/runtime/shared/native-file-capabilities.js +0 -205
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
*
|
|
19
19
|
* @module observability/tracing/api-shim
|
|
20
20
|
*/
|
|
21
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
22
|
+
import { runSyncWithContextFallback } from "./context-callback.js";
|
|
21
23
|
// ---------------------------------------------------------------------------
|
|
22
24
|
// Span kind + status constants
|
|
23
25
|
// ---------------------------------------------------------------------------
|
|
@@ -36,21 +38,22 @@ export const SpanStatusCode = {
|
|
|
36
38
|
// ---------------------------------------------------------------------------
|
|
37
39
|
// No-op provider (default when ext-observability-opentelemetry is not installed)
|
|
38
40
|
// ---------------------------------------------------------------------------
|
|
39
|
-
function createNoopContext() {
|
|
40
|
-
const store = new Map();
|
|
41
|
-
return {
|
|
41
|
+
function createNoopContext(entries = new Map()) {
|
|
42
|
+
const store = new Map(entries);
|
|
43
|
+
return Object.freeze({
|
|
42
44
|
getValue: (key) => store.get(key),
|
|
43
45
|
setValue(key, value) {
|
|
44
|
-
store
|
|
45
|
-
|
|
46
|
+
const next = new Map(store);
|
|
47
|
+
next.set(key, value);
|
|
48
|
+
return createNoopContext(next);
|
|
46
49
|
},
|
|
47
50
|
deleteValue(key) {
|
|
48
|
-
store
|
|
49
|
-
|
|
51
|
+
const next = new Map(store);
|
|
52
|
+
next.delete(key);
|
|
53
|
+
return createNoopContext(next);
|
|
50
54
|
},
|
|
51
|
-
};
|
|
55
|
+
});
|
|
52
56
|
}
|
|
53
|
-
const NOOP_CONTEXT = createNoopContext();
|
|
54
57
|
const EMPTY_TRACE_ID = "00000000000000000000000000000000";
|
|
55
58
|
const EMPTY_SPAN_ID = "0000000000000000";
|
|
56
59
|
const NOOP_SPAN_CONTEXT = {
|
|
@@ -100,25 +103,142 @@ function createNoopProvider() {
|
|
|
100
103
|
// ---------------------------------------------------------------------------
|
|
101
104
|
// Global provider state
|
|
102
105
|
// ---------------------------------------------------------------------------
|
|
103
|
-
let _provider = createNoopProvider();
|
|
104
|
-
let _providerRevision = 0;
|
|
105
|
-
let _activeContext = NOOP_CONTEXT;
|
|
106
|
-
let _propagator = null;
|
|
107
|
-
let _contextAccessor = null;
|
|
108
106
|
const ACTIVE_SPAN_CONTEXT_KEY = Symbol.for("veryfront.observability.active_span");
|
|
107
|
+
function createEmptyTelemetryState(generation = 0, tracerProviderRevision = 0, metricsApiRevision = 0) {
|
|
108
|
+
return Object.freeze({
|
|
109
|
+
generation,
|
|
110
|
+
tracerProviderRevision,
|
|
111
|
+
metricsApiRevision,
|
|
112
|
+
tracerProviderInstalled: false,
|
|
113
|
+
tracerProvider: createNoopProvider(),
|
|
114
|
+
metricsApi: null,
|
|
115
|
+
contextAccessor: null,
|
|
116
|
+
activeSpanAccessor: null,
|
|
117
|
+
propagator: null,
|
|
118
|
+
ownerToken: Symbol("veryfront.telemetry.empty"),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
let telemetryState = createEmptyTelemetryState();
|
|
109
122
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
123
|
+
* Async-scoped fallback context used until a real context accessor is installed.
|
|
124
|
+
*
|
|
125
|
+
* Async-local storage keeps an activation visible across the awaits of the work
|
|
126
|
+
* it wraps without leaking into concurrent work, so span attributes recorded
|
|
127
|
+
* after an await still reach the span that is active for that request.
|
|
113
128
|
*/
|
|
114
|
-
|
|
129
|
+
const fallbackContextStorage = new AsyncLocalStorage();
|
|
130
|
+
let _rootContext = createNoopContext();
|
|
131
|
+
function resetFallbackContext() {
|
|
132
|
+
_rootContext = createNoopContext();
|
|
133
|
+
}
|
|
134
|
+
function getFallbackContext() {
|
|
135
|
+
try {
|
|
136
|
+
return fallbackContextStorage.getStore() ?? _rootContext;
|
|
137
|
+
}
|
|
138
|
+
catch (_) {
|
|
139
|
+
return _rootContext;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function assertOptionalMethod(value, method, label) {
|
|
143
|
+
if (value === null || value === undefined)
|
|
144
|
+
return;
|
|
145
|
+
if (typeof value[method] !== "function") {
|
|
146
|
+
throw new TypeError(`${label} must implement ${method}()`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function preReadTelemetryConfig(config) {
|
|
150
|
+
// Read every potentially accessor-backed property before mutating global
|
|
151
|
+
// state. A hostile or partially constructed facade therefore cannot leave
|
|
152
|
+
// the shim half-installed.
|
|
153
|
+
const suppliedTracerProvider = config.tracerProvider;
|
|
154
|
+
const metricsApi = config.metricsApi ?? null;
|
|
155
|
+
const contextAccessor = config.contextAccessor ?? null;
|
|
156
|
+
const activeSpanAccessor = config.activeSpanAccessor ?? null;
|
|
157
|
+
const propagator = config.propagator ?? null;
|
|
158
|
+
assertOptionalMethod(suppliedTracerProvider, "getTracer", "tracerProvider");
|
|
159
|
+
assertOptionalMethod(metricsApi, "getMeter", "metricsApi");
|
|
160
|
+
assertOptionalMethod(contextAccessor, "active", "contextAccessor");
|
|
161
|
+
assertOptionalMethod(contextAccessor, "with", "contextAccessor");
|
|
162
|
+
assertOptionalMethod(activeSpanAccessor, "getActiveSpan", "activeSpanAccessor");
|
|
163
|
+
assertOptionalMethod(activeSpanAccessor, "getSpan", "activeSpanAccessor");
|
|
164
|
+
assertOptionalMethod(propagator, "inject", "propagator");
|
|
165
|
+
assertOptionalMethod(propagator, "extract", "propagator");
|
|
166
|
+
return {
|
|
167
|
+
tracerProvider: suppliedTracerProvider ?? createNoopProvider(),
|
|
168
|
+
tracerProviderInstalled: suppliedTracerProvider !== null &&
|
|
169
|
+
suppliedTracerProvider !== undefined,
|
|
170
|
+
metricsApi,
|
|
171
|
+
contextAccessor,
|
|
172
|
+
activeSpanAccessor,
|
|
173
|
+
propagator,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function installTelemetryState(config) {
|
|
177
|
+
const previous = telemetryState;
|
|
178
|
+
const generation = previous.generation + 1;
|
|
179
|
+
const token = Symbol(`veryfront.telemetry.${generation}`);
|
|
180
|
+
telemetryState = Object.freeze({
|
|
181
|
+
generation,
|
|
182
|
+
tracerProviderRevision: previous.tracerProviderRevision + 1,
|
|
183
|
+
metricsApiRevision: previous.metricsApiRevision + 1,
|
|
184
|
+
...config,
|
|
185
|
+
ownerToken: token,
|
|
186
|
+
});
|
|
187
|
+
resetFallbackContext();
|
|
188
|
+
return Object.freeze({
|
|
189
|
+
generation,
|
|
190
|
+
token,
|
|
191
|
+
dispose: () => clearGlobalTelemetryAPI({ generation, token }),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/** Atomically install one complete telemetry facade and return its owner handle. */
|
|
195
|
+
export function installGlobalTelemetryAPI(config) {
|
|
196
|
+
return installTelemetryState(preReadTelemetryConfig(config));
|
|
197
|
+
}
|
|
198
|
+
/** Clear the current generation without allowing stale owners to clobber it. */
|
|
199
|
+
export function clearGlobalTelemetryAPI(owner) {
|
|
200
|
+
const current = telemetryState;
|
|
201
|
+
if (owner.generation !== current.generation || owner.token !== current.ownerToken) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
telemetryState = createEmptyTelemetryState(current.generation + 1, current.tracerProviderRevision + 1, current.metricsApiRevision + 1);
|
|
205
|
+
resetFallbackContext();
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
/** Read one internally consistent telemetry facade snapshot. */
|
|
209
|
+
export function getGlobalTelemetryAPISnapshot() {
|
|
210
|
+
const current = telemetryState;
|
|
211
|
+
return Object.freeze({
|
|
212
|
+
generation: current.generation,
|
|
213
|
+
tracerProviderRevision: current.tracerProviderRevision,
|
|
214
|
+
metricsApiRevision: current.metricsApiRevision,
|
|
215
|
+
tracerProviderInstalled: current.tracerProviderInstalled,
|
|
216
|
+
tracerProvider: current.tracerProvider,
|
|
217
|
+
metricsApi: current.metricsApi,
|
|
218
|
+
contextAccessor: current.contextAccessor,
|
|
219
|
+
activeSpanAccessor: current.activeSpanAccessor,
|
|
220
|
+
propagator: current.propagator,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function updateTelemetryState(patch, revisions = {}) {
|
|
224
|
+
const current = telemetryState;
|
|
225
|
+
telemetryState = Object.freeze({
|
|
226
|
+
...current,
|
|
227
|
+
...patch,
|
|
228
|
+
generation: current.generation + 1,
|
|
229
|
+
tracerProviderRevision: current.tracerProviderRevision + (revisions.tracer ? 1 : 0),
|
|
230
|
+
metricsApiRevision: current.metricsApiRevision + (revisions.metrics ? 1 : 0),
|
|
231
|
+
ownerToken: Symbol("veryfront.telemetry.legacy-install"),
|
|
232
|
+
});
|
|
233
|
+
resetFallbackContext();
|
|
234
|
+
}
|
|
115
235
|
/**
|
|
116
236
|
* Register the real OTel trace API's span accessors. Called by the
|
|
117
237
|
* ext-observability-opentelemetry extension after it wires the SDK so that the shim's
|
|
118
238
|
* `trace.getActiveSpan()` / `trace.getSpan()` can return real spans.
|
|
119
239
|
*/
|
|
120
240
|
export function setGlobalActiveSpanAccessor(accessor) {
|
|
121
|
-
|
|
241
|
+
updateTelemetryState({ activeSpanAccessor: accessor });
|
|
122
242
|
}
|
|
123
243
|
/**
|
|
124
244
|
* Register the real OTel context API. This lets the shim preserve active span
|
|
@@ -126,56 +246,48 @@ export function setGlobalActiveSpanAccessor(accessor) {
|
|
|
126
246
|
* AsyncLocalStorageContextManager.
|
|
127
247
|
*/
|
|
128
248
|
export function setGlobalContextAccessor(accessor) {
|
|
129
|
-
|
|
249
|
+
updateTelemetryState({ contextAccessor: accessor });
|
|
130
250
|
}
|
|
131
251
|
/**
|
|
132
252
|
* Wire in the real SDK TracerProvider.
|
|
133
253
|
* Called from `src/server/bootstrap.ts` after `orchestrateExtensions()` runs.
|
|
134
254
|
*/
|
|
135
255
|
export function setGlobalTracerProvider(p) {
|
|
136
|
-
|
|
137
|
-
_providerRevision++;
|
|
256
|
+
updateTelemetryState({ tracerProvider: p, tracerProviderInstalled: true }, { tracer: true });
|
|
138
257
|
}
|
|
139
258
|
export function getGlobalTracerProvider() {
|
|
140
|
-
return
|
|
259
|
+
return telemetryState.tracerProvider;
|
|
141
260
|
}
|
|
142
261
|
export function getTracerProviderRevision() {
|
|
143
|
-
return
|
|
262
|
+
return telemetryState.tracerProviderRevision;
|
|
144
263
|
}
|
|
145
264
|
/**
|
|
146
265
|
* Get a tracer from the active provider.
|
|
147
266
|
* Returns the no-op tracer when ext-observability-opentelemetry is not installed.
|
|
148
267
|
*/
|
|
149
268
|
export function getTracer(name, version) {
|
|
150
|
-
return
|
|
269
|
+
return telemetryState.tracerProvider.getTracer(name, version);
|
|
151
270
|
}
|
|
152
271
|
// ---------------------------------------------------------------------------
|
|
153
272
|
// Context API
|
|
154
273
|
// ---------------------------------------------------------------------------
|
|
155
274
|
export const context = {
|
|
156
275
|
active() {
|
|
157
|
-
return _contextAccessor?.active() ?? _activeContext;
|
|
158
|
-
},
|
|
159
|
-
with(ctx, fn) {
|
|
160
|
-
if (_contextAccessor) {
|
|
161
|
-
return _contextAccessor.with(ctx, fn);
|
|
162
|
-
}
|
|
163
|
-
const prev = _activeContext;
|
|
164
|
-
_activeContext = ctx;
|
|
165
276
|
try {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
_activeContext = prev;
|
|
173
|
-
return result;
|
|
277
|
+
return telemetryState.contextAccessor?.active() ?? getFallbackContext();
|
|
278
|
+
}
|
|
279
|
+
catch (_) {
|
|
280
|
+
return getFallbackContext();
|
|
174
281
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
282
|
+
},
|
|
283
|
+
with(ctx, fn) {
|
|
284
|
+
const accessor = telemetryState.contextAccessor;
|
|
285
|
+
if (accessor) {
|
|
286
|
+
return runSyncWithContextFallback((callback) => accessor.with(ctx, callback), fn);
|
|
178
287
|
}
|
|
288
|
+
// run() invokes fn exactly once and propagates its result or failure
|
|
289
|
+
// unchanged, so application outcomes never depend on activation.
|
|
290
|
+
return fallbackContextStorage.run(ctx, fn);
|
|
179
291
|
},
|
|
180
292
|
setGlobalContextManager(_mgr) {
|
|
181
293
|
// no-op in shim; real SDK sets this via the real OTel API
|
|
@@ -186,14 +298,13 @@ export const context = {
|
|
|
186
298
|
// ---------------------------------------------------------------------------
|
|
187
299
|
export const trace = {
|
|
188
300
|
getTracer(name, version) {
|
|
189
|
-
return
|
|
301
|
+
return telemetryState.tracerProvider.getTracer(name, version);
|
|
190
302
|
},
|
|
191
303
|
setGlobalTracerProvider(p) {
|
|
192
|
-
|
|
193
|
-
_providerRevision++;
|
|
304
|
+
setGlobalTracerProvider(p);
|
|
194
305
|
},
|
|
195
306
|
getGlobalTracerProvider() {
|
|
196
|
-
return
|
|
307
|
+
return telemetryState.tracerProvider;
|
|
197
308
|
},
|
|
198
309
|
setSpan(ctx, _span) {
|
|
199
310
|
try {
|
|
@@ -205,17 +316,32 @@ export const trace = {
|
|
|
205
316
|
catch {
|
|
206
317
|
// Keep structural test doubles usable even when they omit spanContext().
|
|
207
318
|
}
|
|
208
|
-
|
|
209
|
-
|
|
319
|
+
try {
|
|
320
|
+
const accessor = telemetryState.activeSpanAccessor;
|
|
321
|
+
if (accessor?.setSpan)
|
|
322
|
+
return accessor.setSpan(ctx, _span);
|
|
323
|
+
return ctx.setValue(ACTIVE_SPAN_CONTEXT_KEY, _span);
|
|
324
|
+
}
|
|
325
|
+
catch (_) {
|
|
326
|
+
return ctx;
|
|
210
327
|
}
|
|
211
|
-
return ctx.setValue(ACTIVE_SPAN_CONTEXT_KEY, _span);
|
|
212
328
|
},
|
|
213
329
|
getSpan(ctx) {
|
|
214
|
-
|
|
215
|
-
|
|
330
|
+
try {
|
|
331
|
+
return telemetryState.activeSpanAccessor?.getSpan(ctx) ??
|
|
332
|
+
ctx.getValue(ACTIVE_SPAN_CONTEXT_KEY);
|
|
333
|
+
}
|
|
334
|
+
catch (_) {
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
216
337
|
},
|
|
217
338
|
getActiveSpan() {
|
|
218
|
-
|
|
339
|
+
try {
|
|
340
|
+
return telemetryState.activeSpanAccessor?.getActiveSpan() ?? trace.getSpan(context.active());
|
|
341
|
+
}
|
|
342
|
+
catch (_) {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
219
345
|
},
|
|
220
346
|
};
|
|
221
347
|
// ---------------------------------------------------------------------------
|
|
@@ -223,17 +349,19 @@ export const trace = {
|
|
|
223
349
|
// ---------------------------------------------------------------------------
|
|
224
350
|
export const propagation = {
|
|
225
351
|
setGlobalPropagator(p) {
|
|
226
|
-
|
|
352
|
+
updateTelemetryState({ propagator: p });
|
|
227
353
|
},
|
|
228
354
|
extract(ctx, carrier, getter) {
|
|
229
|
-
|
|
355
|
+
const propagator = telemetryState.propagator;
|
|
356
|
+
if (!propagator)
|
|
230
357
|
return ctx;
|
|
231
|
-
return
|
|
358
|
+
return propagator.extract(ctx, carrier, getter);
|
|
232
359
|
},
|
|
233
360
|
inject(ctx, carrier, setter) {
|
|
234
|
-
|
|
361
|
+
const propagator = telemetryState.propagator;
|
|
362
|
+
if (!propagator)
|
|
235
363
|
return;
|
|
236
|
-
|
|
364
|
+
propagator.inject(ctx, carrier, setter);
|
|
237
365
|
},
|
|
238
366
|
};
|
|
239
367
|
// ---------------------------------------------------------------------------
|
|
@@ -255,27 +383,26 @@ export const defaultTextMapSetter = {
|
|
|
255
383
|
// ---------------------------------------------------------------------------
|
|
256
384
|
// Metrics API registry (injected by ext-observability-opentelemetry when active)
|
|
257
385
|
// ---------------------------------------------------------------------------
|
|
258
|
-
let _metricsApi = null;
|
|
259
386
|
/**
|
|
260
387
|
* Register the OTel Metrics API (from the SDK).
|
|
261
388
|
* Called by ext-observability-opentelemetry in its setup hook so the metrics subsystem
|
|
262
389
|
* can use `getMeter()` when available.
|
|
263
390
|
*/
|
|
264
391
|
export function setGlobalMetricsAPI(api) {
|
|
265
|
-
|
|
392
|
+
updateTelemetryState({ metricsApi: api }, { metrics: true });
|
|
266
393
|
}
|
|
267
394
|
export function getGlobalMetricsAPI() {
|
|
268
|
-
return
|
|
395
|
+
return telemetryState.metricsApi;
|
|
396
|
+
}
|
|
397
|
+
/** Monotonic revision used by lazy instruments to detect provider changes. */
|
|
398
|
+
export function getMetricsApiRevision() {
|
|
399
|
+
return telemetryState.metricsApiRevision;
|
|
269
400
|
}
|
|
270
401
|
// ---------------------------------------------------------------------------
|
|
271
402
|
// Reset for tests
|
|
272
403
|
// ---------------------------------------------------------------------------
|
|
273
404
|
export function _resetShimForTests() {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
_propagator = null;
|
|
278
|
-
_contextAccessor = null;
|
|
279
|
-
_metricsApi = null;
|
|
280
|
-
_activeSpanAccessor = null;
|
|
405
|
+
const current = telemetryState;
|
|
406
|
+
telemetryState = createEmptyTelemetryState(current.generation + 1, current.tracerProviderRevision + 1, current.metricsApiRevision + 1);
|
|
407
|
+
resetFallbackContext();
|
|
281
408
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ActivationFailureHandler = (error: unknown) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Run an async callback at most once, falling back when context activation fails.
|
|
4
|
+
*
|
|
5
|
+
* Context providers are synchronous callback invokers by contract. Once the
|
|
6
|
+
* application callback has been invoked, its promise is authoritative: a
|
|
7
|
+
* provider-owned replacement (including a promise that never settles) must not
|
|
8
|
+
* delay or replace application work.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runAsyncWithContextFallback<T>(activate: (callback: () => Promise<T>) => Promise<T>, callback: () => Promise<T>, onActivationFailure?: ActivationFailureHandler): Promise<T>;
|
|
11
|
+
/** Run a sync callback at most once, falling back when context activation fails. */
|
|
12
|
+
export declare function runSyncWithContextFallback<T>(activate: (callback: () => T) => T, callback: () => T, onActivationFailure?: ActivationFailureHandler): T;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=context-callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-callback.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/tracing/context-callback.ts"],"names":[],"mappings":"AAAA,KAAK,wBAAwB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;AA+BzD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EACpD,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC1B,mBAAmB,CAAC,EAAE,wBAAwB,GAC7C,OAAO,CAAC,CAAC,CAAC,CAgCZ;AAED,oFAAoF;AACpF,wBAAgB,0BAA0B,CAAC,CAAC,EAC1C,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,EAClC,QAAQ,EAAE,MAAM,CAAC,EACjB,mBAAmB,CAAC,EAAE,wBAAwB,GAC7C,CAAC,CA0CH"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
function reportActivationFailure(handler, error) {
|
|
2
|
+
try {
|
|
3
|
+
handler?.(error);
|
|
4
|
+
}
|
|
5
|
+
catch (_) {
|
|
6
|
+
/* expected: diagnostics must not affect the protected callback */
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function consumeIgnoredThenable(value) {
|
|
10
|
+
if ((typeof value !== "object" || value === null) && typeof value !== "function")
|
|
11
|
+
return;
|
|
12
|
+
let then;
|
|
13
|
+
try {
|
|
14
|
+
then = value.then;
|
|
15
|
+
}
|
|
16
|
+
catch (_) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (typeof then !== "function")
|
|
20
|
+
return;
|
|
21
|
+
try {
|
|
22
|
+
Reflect.apply(then, value, [() => { }, () => { }]);
|
|
23
|
+
}
|
|
24
|
+
catch (_) {
|
|
25
|
+
/* expected: provider-owned thenables cannot affect application outcomes */
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Run an async callback at most once, falling back when context activation fails.
|
|
30
|
+
*
|
|
31
|
+
* Context providers are synchronous callback invokers by contract. Once the
|
|
32
|
+
* application callback has been invoked, its promise is authoritative: a
|
|
33
|
+
* provider-owned replacement (including a promise that never settles) must not
|
|
34
|
+
* delay or replace application work.
|
|
35
|
+
*/
|
|
36
|
+
export function runAsyncWithContextFallback(activate, callback, onActivationFailure) {
|
|
37
|
+
let callbackInvoked = false;
|
|
38
|
+
let callbackResult;
|
|
39
|
+
const invoke = () => {
|
|
40
|
+
if (callbackInvoked && callbackResult)
|
|
41
|
+
return callbackResult;
|
|
42
|
+
callbackInvoked = true;
|
|
43
|
+
try {
|
|
44
|
+
callbackResult = callback();
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
callbackResult = Promise.reject(error);
|
|
48
|
+
}
|
|
49
|
+
return callbackResult;
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
const providerResult = activate(invoke);
|
|
53
|
+
if (callbackInvoked && callbackResult) {
|
|
54
|
+
if (providerResult !== callbackResult)
|
|
55
|
+
consumeIgnoredThenable(providerResult);
|
|
56
|
+
return callbackResult;
|
|
57
|
+
}
|
|
58
|
+
reportActivationFailure(onActivationFailure, new Error("Context activation returned without invoking its callback"));
|
|
59
|
+
consumeIgnoredThenable(providerResult);
|
|
60
|
+
return invoke();
|
|
61
|
+
}
|
|
62
|
+
catch (activationError) {
|
|
63
|
+
if (callbackInvoked && callbackResult)
|
|
64
|
+
return callbackResult;
|
|
65
|
+
reportActivationFailure(onActivationFailure, activationError);
|
|
66
|
+
return invoke();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Run a sync callback at most once, falling back when context activation fails. */
|
|
70
|
+
export function runSyncWithContextFallback(activate, callback, onActivationFailure) {
|
|
71
|
+
let callbackInvoked = false;
|
|
72
|
+
let callbackSucceeded = false;
|
|
73
|
+
let callbackResult;
|
|
74
|
+
let callbackError;
|
|
75
|
+
const invoke = () => {
|
|
76
|
+
if (callbackInvoked) {
|
|
77
|
+
if (!callbackSucceeded)
|
|
78
|
+
throw callbackError;
|
|
79
|
+
return callbackResult;
|
|
80
|
+
}
|
|
81
|
+
callbackInvoked = true;
|
|
82
|
+
try {
|
|
83
|
+
callbackResult = callback();
|
|
84
|
+
callbackSucceeded = true;
|
|
85
|
+
return callbackResult;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
callbackError = error;
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
activate(invoke);
|
|
94
|
+
if (callbackInvoked) {
|
|
95
|
+
if (!callbackSucceeded)
|
|
96
|
+
throw callbackError;
|
|
97
|
+
return callbackResult;
|
|
98
|
+
}
|
|
99
|
+
reportActivationFailure(onActivationFailure, new Error("Context activation returned without invoking its callback"));
|
|
100
|
+
return invoke();
|
|
101
|
+
}
|
|
102
|
+
catch (activationError) {
|
|
103
|
+
if (callbackInvoked) {
|
|
104
|
+
if (!callbackSucceeded)
|
|
105
|
+
throw callbackError;
|
|
106
|
+
return callbackResult;
|
|
107
|
+
}
|
|
108
|
+
reportActivationFailure(onActivationFailure, activationError);
|
|
109
|
+
return invoke();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-setup.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/tracing/otlp-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;4BAY4B;
|
|
1
|
+
{"version":3,"file":"otlp-setup.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/tracing/otlp-setup.ts"],"names":[],"mappings":"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"}
|