@glasstrace/sdk 1.9.1 → 1.10.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/dist/async-context/index.cjs +44 -0
- package/dist/async-context/index.cjs.map +1 -1
- package/dist/async-context/index.js +2 -2
- package/dist/{chunk-JHUNLPSS.js → chunk-6RKS3DNA.js} +45 -1
- package/dist/{chunk-JHUNLPSS.js.map → chunk-6RKS3DNA.js.map} +1 -1
- package/dist/{chunk-HD6JIFKN.js → chunk-BSVWJSVX.js} +2 -2
- package/dist/{chunk-QOHKZOKB.js → chunk-D54FMQHF.js} +2 -2
- package/dist/chunk-I2DVVSKW.js +419 -0
- package/dist/chunk-I2DVVSKW.js.map +1 -0
- package/dist/{chunk-H6WJ63X2.js → chunk-M5GO2SSO.js} +2 -2
- package/dist/{chunk-2F2MGFLO.js → chunk-OXA4IHQX.js} +39 -405
- package/dist/chunk-OXA4IHQX.js.map +1 -0
- package/dist/{chunk-QEXRCXSY.js → chunk-OXM2BZMF.js} +2 -2
- package/dist/{chunk-M6EWJCAT.js → chunk-QVTONMVZ.js} +2 -2
- package/dist/{chunk-DKV53A2C.js → chunk-RL43PU2X.js} +2 -2
- package/dist/{chunk-GWIEUBFR.js → chunk-UMGZJYC4.js} +3 -3
- package/dist/{chunk-QXITSNYM.js → chunk-XG6WR2KS.js} +3 -3
- package/dist/cli/init.cjs +4 -4
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.js +7 -7
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/mcp-add.cjs +1 -1
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +3 -3
- package/dist/cli/mcp-add.js.map +1 -1
- package/dist/cli/uninit.js +3 -3
- package/dist/cli/upgrade-instructions.cjs +1 -1
- package/dist/cli/upgrade-instructions.cjs.map +1 -1
- package/dist/cli/upgrade-instructions.js +3 -3
- package/dist/cli/upgrade-instructions.js.map +1 -1
- package/dist/cli/validate.cjs.map +1 -1
- package/dist/cli/validate.js +2 -2
- package/dist/edge-entry.cjs +44 -0
- package/dist/edge-entry.cjs.map +1 -1
- package/dist/edge-entry.js +4 -4
- package/dist/index.cjs +58 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/middleware/index.cjs +44 -0
- package/dist/middleware/index.cjs.map +1 -1
- package/dist/middleware/index.js +2 -2
- package/dist/node-entry.cjs +58 -5
- package/dist/node-entry.cjs.map +1 -1
- package/dist/node-entry.js +12 -10
- package/dist/node-subpath.cjs.map +1 -1
- package/dist/node-subpath.js +3 -3
- package/dist/{source-map-uploader-MMJ2WCL4.js → source-map-uploader-CLYCE2TZ.js} +3 -3
- package/dist/trpc/index.cjs +15164 -503
- package/dist/trpc/index.cjs.map +1 -1
- package/dist/trpc/index.d.cts +62 -1
- package/dist/trpc/index.d.ts +62 -1
- package/dist/trpc/index.js +200 -1
- package/dist/trpc/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2F2MGFLO.js.map +0 -1
- /package/dist/{chunk-HD6JIFKN.js.map → chunk-BSVWJSVX.js.map} +0 -0
- /package/dist/{chunk-QOHKZOKB.js.map → chunk-D54FMQHF.js.map} +0 -0
- /package/dist/{chunk-H6WJ63X2.js.map → chunk-M5GO2SSO.js.map} +0 -0
- /package/dist/{chunk-QEXRCXSY.js.map → chunk-OXM2BZMF.js.map} +0 -0
- /package/dist/{chunk-M6EWJCAT.js.map → chunk-QVTONMVZ.js.map} +0 -0
- /package/dist/{chunk-DKV53A2C.js.map → chunk-RL43PU2X.js.map} +0 -0
- /package/dist/{chunk-GWIEUBFR.js.map → chunk-UMGZJYC4.js.map} +0 -0
- /package/dist/{chunk-QXITSNYM.js.map → chunk-XG6WR2KS.js.map} +0 -0
- /package/dist/{source-map-uploader-MMJ2WCL4.js.map → source-map-uploader-CLYCE2TZ.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createBuildHash
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6RKS3DNA.js";
|
|
4
4
|
|
|
5
5
|
// src/import-graph.ts
|
|
6
6
|
import * as fs from "node:fs/promises";
|
|
@@ -175,4 +175,4 @@ export {
|
|
|
175
175
|
extractImports,
|
|
176
176
|
buildImportGraph
|
|
177
177
|
};
|
|
178
|
-
//# sourceMappingURL=chunk-
|
|
178
|
+
//# sourceMappingURL=chunk-BSVWJSVX.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./chunk-DQ25VOKK.js";
|
|
8
8
|
import {
|
|
9
9
|
GLASSTRACE_ATTRIBUTE_NAMES
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-6RKS3DNA.js";
|
|
11
11
|
|
|
12
12
|
// src/middleware/index.ts
|
|
13
13
|
var ATTR = GLASSTRACE_ATTRIBUTE_NAMES;
|
|
@@ -136,4 +136,4 @@ export {
|
|
|
136
136
|
_resetForTesting,
|
|
137
137
|
tracedRequestMiddleware
|
|
138
138
|
};
|
|
139
|
-
//# sourceMappingURL=chunk-
|
|
139
|
+
//# sourceMappingURL=chunk-D54FMQHF.js.map
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_registerLifecycleEmitForBridge
|
|
3
|
+
} from "./chunk-CL3OVHPO.js";
|
|
4
|
+
|
|
5
|
+
// src/lifecycle.ts
|
|
6
|
+
import { EventEmitter } from "node:events";
|
|
7
|
+
|
|
8
|
+
// src/signal-handler.ts
|
|
9
|
+
var coexistenceState = "unknown";
|
|
10
|
+
function setCoexistenceState(s) {
|
|
11
|
+
coexistenceState = s;
|
|
12
|
+
}
|
|
13
|
+
function getCoexistenceState() {
|
|
14
|
+
return coexistenceState;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/lifecycle.ts
|
|
18
|
+
var CoreState = {
|
|
19
|
+
IDLE: "IDLE",
|
|
20
|
+
REGISTERING: "REGISTERING",
|
|
21
|
+
KEY_PENDING: "KEY_PENDING",
|
|
22
|
+
KEY_RESOLVED: "KEY_RESOLVED",
|
|
23
|
+
ACTIVE: "ACTIVE",
|
|
24
|
+
ACTIVE_DEGRADED: "ACTIVE_DEGRADED",
|
|
25
|
+
SHUTTING_DOWN: "SHUTTING_DOWN",
|
|
26
|
+
SHUTDOWN: "SHUTDOWN",
|
|
27
|
+
PRODUCTION_DISABLED: "PRODUCTION_DISABLED",
|
|
28
|
+
REGISTRATION_FAILED: "REGISTRATION_FAILED"
|
|
29
|
+
};
|
|
30
|
+
var AuthState = {
|
|
31
|
+
ANONYMOUS: "ANONYMOUS",
|
|
32
|
+
AUTHENTICATED: "AUTHENTICATED",
|
|
33
|
+
CLAIMING: "CLAIMING",
|
|
34
|
+
CLAIMED: "CLAIMED"
|
|
35
|
+
};
|
|
36
|
+
var OtelState = {
|
|
37
|
+
UNCONFIGURED: "UNCONFIGURED",
|
|
38
|
+
CONFIGURING: "CONFIGURING",
|
|
39
|
+
OWNS_PROVIDER: "OWNS_PROVIDER",
|
|
40
|
+
AUTO_ATTACHED: "AUTO_ATTACHED",
|
|
41
|
+
PROCESSOR_PRESENT: "PROCESSOR_PRESENT",
|
|
42
|
+
COEXISTENCE_FAILED: "COEXISTENCE_FAILED"
|
|
43
|
+
};
|
|
44
|
+
var VALID_CORE_TRANSITIONS = {
|
|
45
|
+
[CoreState.IDLE]: [CoreState.REGISTERING, CoreState.REGISTRATION_FAILED, CoreState.SHUTTING_DOWN],
|
|
46
|
+
[CoreState.REGISTERING]: [
|
|
47
|
+
CoreState.KEY_PENDING,
|
|
48
|
+
CoreState.PRODUCTION_DISABLED,
|
|
49
|
+
CoreState.REGISTRATION_FAILED,
|
|
50
|
+
CoreState.SHUTTING_DOWN
|
|
51
|
+
],
|
|
52
|
+
[CoreState.KEY_PENDING]: [
|
|
53
|
+
CoreState.KEY_RESOLVED,
|
|
54
|
+
CoreState.REGISTRATION_FAILED,
|
|
55
|
+
CoreState.SHUTTING_DOWN
|
|
56
|
+
],
|
|
57
|
+
[CoreState.KEY_RESOLVED]: [
|
|
58
|
+
CoreState.ACTIVE,
|
|
59
|
+
CoreState.ACTIVE_DEGRADED,
|
|
60
|
+
CoreState.SHUTTING_DOWN
|
|
61
|
+
],
|
|
62
|
+
[CoreState.ACTIVE]: [
|
|
63
|
+
CoreState.ACTIVE_DEGRADED,
|
|
64
|
+
CoreState.SHUTTING_DOWN
|
|
65
|
+
],
|
|
66
|
+
[CoreState.ACTIVE_DEGRADED]: [
|
|
67
|
+
CoreState.ACTIVE,
|
|
68
|
+
CoreState.SHUTTING_DOWN
|
|
69
|
+
],
|
|
70
|
+
[CoreState.SHUTTING_DOWN]: [CoreState.SHUTDOWN],
|
|
71
|
+
[CoreState.SHUTDOWN]: [],
|
|
72
|
+
[CoreState.PRODUCTION_DISABLED]: [],
|
|
73
|
+
[CoreState.REGISTRATION_FAILED]: []
|
|
74
|
+
};
|
|
75
|
+
var VALID_AUTH_TRANSITIONS = {
|
|
76
|
+
[AuthState.ANONYMOUS]: [AuthState.CLAIMING],
|
|
77
|
+
[AuthState.AUTHENTICATED]: [AuthState.CLAIMING],
|
|
78
|
+
[AuthState.CLAIMING]: [AuthState.CLAIMED],
|
|
79
|
+
[AuthState.CLAIMED]: [AuthState.CLAIMING]
|
|
80
|
+
};
|
|
81
|
+
var VALID_OTEL_TRANSITIONS = {
|
|
82
|
+
[OtelState.UNCONFIGURED]: [OtelState.CONFIGURING],
|
|
83
|
+
[OtelState.CONFIGURING]: [
|
|
84
|
+
OtelState.OWNS_PROVIDER,
|
|
85
|
+
OtelState.AUTO_ATTACHED,
|
|
86
|
+
OtelState.PROCESSOR_PRESENT,
|
|
87
|
+
OtelState.COEXISTENCE_FAILED
|
|
88
|
+
],
|
|
89
|
+
[OtelState.OWNS_PROVIDER]: [],
|
|
90
|
+
[OtelState.AUTO_ATTACHED]: [],
|
|
91
|
+
[OtelState.PROCESSOR_PRESENT]: [],
|
|
92
|
+
[OtelState.COEXISTENCE_FAILED]: []
|
|
93
|
+
};
|
|
94
|
+
var _coreState = CoreState.IDLE;
|
|
95
|
+
var _authState = AuthState.ANONYMOUS;
|
|
96
|
+
var _otelState = OtelState.UNCONFIGURED;
|
|
97
|
+
var _emitter = new EventEmitter();
|
|
98
|
+
var _logger = null;
|
|
99
|
+
var _initialized = false;
|
|
100
|
+
var _initWarned = false;
|
|
101
|
+
var _coreReadyEmitted = false;
|
|
102
|
+
var _authInitialized = false;
|
|
103
|
+
var _emitting = false;
|
|
104
|
+
function initLifecycle(options) {
|
|
105
|
+
if (_initialized) {
|
|
106
|
+
options.logger("warn", "[glasstrace] initLifecycle() called twice \u2014 ignored.");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
_logger = options.logger;
|
|
110
|
+
_initialized = true;
|
|
111
|
+
_registerLifecycleEmitForBridge((event, payload) => {
|
|
112
|
+
emitLifecycleEvent(
|
|
113
|
+
event,
|
|
114
|
+
payload
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function warnIfNotInitialized() {
|
|
119
|
+
if (!_initialized && !_initWarned) {
|
|
120
|
+
_initWarned = true;
|
|
121
|
+
console.warn(
|
|
122
|
+
"[glasstrace] Lifecycle state changed before initLifecycle() was called. Logger not available \u2014 errors will be silent."
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function setCoreState(to) {
|
|
127
|
+
warnIfNotInitialized();
|
|
128
|
+
const from = _coreState;
|
|
129
|
+
if (from === to) return;
|
|
130
|
+
const valid = VALID_CORE_TRANSITIONS[from];
|
|
131
|
+
if (!valid.includes(to)) {
|
|
132
|
+
_logger?.(
|
|
133
|
+
"warn",
|
|
134
|
+
`[glasstrace] Invalid core state transition: ${from} \u2192 ${to}. Ignored.`
|
|
135
|
+
);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
_coreState = to;
|
|
139
|
+
if (_emitting) return;
|
|
140
|
+
_emitting = true;
|
|
141
|
+
try {
|
|
142
|
+
emitSafe("core:state_changed", { from, to });
|
|
143
|
+
const current = _coreState;
|
|
144
|
+
if (!_coreReadyEmitted && (current === CoreState.ACTIVE || current === CoreState.ACTIVE_DEGRADED)) {
|
|
145
|
+
_coreReadyEmitted = true;
|
|
146
|
+
emitSafe("core:ready", {});
|
|
147
|
+
}
|
|
148
|
+
if (current === CoreState.SHUTTING_DOWN) {
|
|
149
|
+
emitSafe("core:shutdown_started", {});
|
|
150
|
+
}
|
|
151
|
+
if (current === CoreState.SHUTDOWN) {
|
|
152
|
+
emitSafe("core:shutdown_completed", {});
|
|
153
|
+
}
|
|
154
|
+
} finally {
|
|
155
|
+
_emitting = false;
|
|
156
|
+
}
|
|
157
|
+
if (to === CoreState.ACTIVE && _degradationSources.size > 0) {
|
|
158
|
+
recomputeCoreFromDegradationSources();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function initAuthState(state) {
|
|
162
|
+
if (_authInitialized) {
|
|
163
|
+
_logger?.(
|
|
164
|
+
"warn",
|
|
165
|
+
"[glasstrace] initAuthState() called after auth state already initialized. Ignored."
|
|
166
|
+
);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
_authInitialized = true;
|
|
170
|
+
_authState = state;
|
|
171
|
+
}
|
|
172
|
+
function setAuthState(to) {
|
|
173
|
+
warnIfNotInitialized();
|
|
174
|
+
const from = _authState;
|
|
175
|
+
if (from === to) return;
|
|
176
|
+
const valid = VALID_AUTH_TRANSITIONS[from];
|
|
177
|
+
if (!valid.includes(to)) {
|
|
178
|
+
_logger?.(
|
|
179
|
+
"warn",
|
|
180
|
+
`[glasstrace] Invalid auth state transition: ${from} \u2192 ${to}. Ignored.`
|
|
181
|
+
);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
_authState = to;
|
|
185
|
+
}
|
|
186
|
+
function setOtelState(to) {
|
|
187
|
+
warnIfNotInitialized();
|
|
188
|
+
const from = _otelState;
|
|
189
|
+
if (from === to) return;
|
|
190
|
+
const valid = VALID_OTEL_TRANSITIONS[from];
|
|
191
|
+
if (!valid.includes(to)) {
|
|
192
|
+
_logger?.(
|
|
193
|
+
"warn",
|
|
194
|
+
`[glasstrace] Invalid OTel state transition: ${from} \u2192 ${to}. Ignored.`
|
|
195
|
+
);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
_otelState = to;
|
|
199
|
+
}
|
|
200
|
+
var _degradationSources = /* @__PURE__ */ new Set();
|
|
201
|
+
function pushDegradationSource(key) {
|
|
202
|
+
_degradationSources.add(key);
|
|
203
|
+
recomputeCoreFromDegradationSources();
|
|
204
|
+
}
|
|
205
|
+
function clearDegradationSource(key) {
|
|
206
|
+
_degradationSources.delete(key);
|
|
207
|
+
recomputeCoreFromDegradationSources();
|
|
208
|
+
}
|
|
209
|
+
function recomputeCoreFromDegradationSources() {
|
|
210
|
+
const hasDegradation = _degradationSources.size > 0;
|
|
211
|
+
if (hasDegradation && _coreState === CoreState.ACTIVE) {
|
|
212
|
+
setCoreState(CoreState.ACTIVE_DEGRADED);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!hasDegradation && _coreState === CoreState.ACTIVE_DEGRADED) {
|
|
216
|
+
setCoreState(CoreState.ACTIVE);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function getCoreState() {
|
|
220
|
+
return _coreState;
|
|
221
|
+
}
|
|
222
|
+
function getSdkState() {
|
|
223
|
+
return {
|
|
224
|
+
core: _coreState,
|
|
225
|
+
auth: _authState,
|
|
226
|
+
otel: _otelState
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function onLifecycleEvent(event, listener) {
|
|
230
|
+
_emitter.on(event, listener);
|
|
231
|
+
}
|
|
232
|
+
function emitLifecycleEvent(event, payload) {
|
|
233
|
+
emitSafe(event, payload);
|
|
234
|
+
}
|
|
235
|
+
function offLifecycleEvent(event, listener) {
|
|
236
|
+
_emitter.off(event, listener);
|
|
237
|
+
}
|
|
238
|
+
function emitSafe(event, payload) {
|
|
239
|
+
const listeners = _emitter.listeners(event);
|
|
240
|
+
for (const listener of listeners) {
|
|
241
|
+
try {
|
|
242
|
+
const result = listener(payload);
|
|
243
|
+
if (result && typeof result.catch === "function") {
|
|
244
|
+
result.catch((err) => {
|
|
245
|
+
_logger?.(
|
|
246
|
+
"error",
|
|
247
|
+
`[glasstrace] Async error in lifecycle event listener for "${event}": ${err instanceof Error ? err.message : String(err)}`
|
|
248
|
+
);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
} catch (err) {
|
|
252
|
+
_logger?.(
|
|
253
|
+
"error",
|
|
254
|
+
`[glasstrace] Error in lifecycle event listener for "${event}": ${err instanceof Error ? err.message : String(err)}`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function isReady() {
|
|
260
|
+
return _coreState === CoreState.ACTIVE || _coreState === CoreState.ACTIVE_DEGRADED;
|
|
261
|
+
}
|
|
262
|
+
function waitForReady(timeoutMs = 3e4) {
|
|
263
|
+
if (isReady()) {
|
|
264
|
+
return Promise.resolve();
|
|
265
|
+
}
|
|
266
|
+
if (_coreState === CoreState.PRODUCTION_DISABLED || _coreState === CoreState.REGISTRATION_FAILED || _coreState === CoreState.SHUTTING_DOWN || _coreState === CoreState.SHUTDOWN) {
|
|
267
|
+
return Promise.reject(new Error(`SDK is in terminal state: ${_coreState}`));
|
|
268
|
+
}
|
|
269
|
+
return new Promise((resolve, reject) => {
|
|
270
|
+
let settled = false;
|
|
271
|
+
const listener = ({ to }) => {
|
|
272
|
+
if (settled) return;
|
|
273
|
+
if (to === CoreState.ACTIVE || to === CoreState.ACTIVE_DEGRADED) {
|
|
274
|
+
settled = true;
|
|
275
|
+
offLifecycleEvent("core:state_changed", listener);
|
|
276
|
+
resolve();
|
|
277
|
+
} else if (to === CoreState.PRODUCTION_DISABLED || to === CoreState.REGISTRATION_FAILED || to === CoreState.SHUTTING_DOWN || to === CoreState.SHUTDOWN) {
|
|
278
|
+
settled = true;
|
|
279
|
+
offLifecycleEvent("core:state_changed", listener);
|
|
280
|
+
reject(new Error(`SDK reached terminal state: ${to}`));
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
onLifecycleEvent("core:state_changed", listener);
|
|
284
|
+
if (timeoutMs > 0) {
|
|
285
|
+
const timer = setTimeout(() => {
|
|
286
|
+
if (settled) return;
|
|
287
|
+
settled = true;
|
|
288
|
+
offLifecycleEvent("core:state_changed", listener);
|
|
289
|
+
reject(new Error(`waitForReady timed out after ${timeoutMs}ms (state: ${_coreState})`));
|
|
290
|
+
}, timeoutMs);
|
|
291
|
+
if (typeof timer === "object" && "unref" in timer) {
|
|
292
|
+
timer.unref();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function getStatus() {
|
|
298
|
+
let mode;
|
|
299
|
+
if (_coreState === CoreState.PRODUCTION_DISABLED) {
|
|
300
|
+
mode = "disabled";
|
|
301
|
+
} else if (_authState === AuthState.CLAIMING || _authState === AuthState.CLAIMED) {
|
|
302
|
+
mode = "claiming";
|
|
303
|
+
} else if (_authState === AuthState.AUTHENTICATED) {
|
|
304
|
+
mode = "authenticated";
|
|
305
|
+
} else {
|
|
306
|
+
mode = "anonymous";
|
|
307
|
+
}
|
|
308
|
+
let tracing;
|
|
309
|
+
if (_otelState === OtelState.COEXISTENCE_FAILED || _otelState === OtelState.UNCONFIGURED || _otelState === OtelState.CONFIGURING) {
|
|
310
|
+
tracing = "not-configured";
|
|
311
|
+
} else if (_coreState === CoreState.ACTIVE_DEGRADED) {
|
|
312
|
+
tracing = "degraded";
|
|
313
|
+
} else if (_otelState === OtelState.AUTO_ATTACHED || _otelState === OtelState.PROCESSOR_PRESENT) {
|
|
314
|
+
tracing = "coexistence";
|
|
315
|
+
} else {
|
|
316
|
+
tracing = "active";
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
ready: isReady(),
|
|
320
|
+
mode,
|
|
321
|
+
tracing
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
var _shutdownHooks = [];
|
|
325
|
+
var _signalHandlersRegistered = false;
|
|
326
|
+
var _signalHandler = null;
|
|
327
|
+
var _beforeExitRegistered = false;
|
|
328
|
+
var _beforeExitHandler = null;
|
|
329
|
+
var _shutdownExecuted = false;
|
|
330
|
+
function registerShutdownHook(hook) {
|
|
331
|
+
_shutdownHooks.push(hook);
|
|
332
|
+
_shutdownHooks.sort((a, b) => a.priority - b.priority);
|
|
333
|
+
}
|
|
334
|
+
async function executeShutdown(timeoutMs = 5e3) {
|
|
335
|
+
if (_shutdownExecuted) return;
|
|
336
|
+
_shutdownExecuted = true;
|
|
337
|
+
setCoreState(CoreState.SHUTTING_DOWN);
|
|
338
|
+
for (const hook of _shutdownHooks) {
|
|
339
|
+
try {
|
|
340
|
+
const hookPromise = hook.fn();
|
|
341
|
+
hookPromise.catch(() => {
|
|
342
|
+
});
|
|
343
|
+
await Promise.race([
|
|
344
|
+
hookPromise,
|
|
345
|
+
new Promise((_, reject) => {
|
|
346
|
+
const timer = setTimeout(() => reject(new Error(`Shutdown hook "${hook.name}" timed out`)), timeoutMs);
|
|
347
|
+
if (typeof timer === "object" && "unref" in timer) {
|
|
348
|
+
timer.unref();
|
|
349
|
+
}
|
|
350
|
+
})
|
|
351
|
+
]);
|
|
352
|
+
} catch (err) {
|
|
353
|
+
_logger?.(
|
|
354
|
+
"warn",
|
|
355
|
+
`[glasstrace] Shutdown hook "${hook.name}" failed: ${err instanceof Error ? err.message : String(err)}`
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
setCoreState(CoreState.SHUTDOWN);
|
|
360
|
+
}
|
|
361
|
+
function registerSignalHandlers() {
|
|
362
|
+
if (_signalHandlersRegistered) return;
|
|
363
|
+
if (typeof process === "undefined" || typeof process.once !== "function") return;
|
|
364
|
+
_signalHandlersRegistered = true;
|
|
365
|
+
const otherSigtermListeners = process.listenerCount("SIGTERM");
|
|
366
|
+
const otherSigintListeners = process.listenerCount("SIGINT");
|
|
367
|
+
const handler = (signal) => {
|
|
368
|
+
void executeShutdown().finally(() => {
|
|
369
|
+
if (_signalHandler) {
|
|
370
|
+
process.removeListener("SIGTERM", _signalHandler);
|
|
371
|
+
process.removeListener("SIGINT", _signalHandler);
|
|
372
|
+
}
|
|
373
|
+
const otherListeners = signal === "SIGTERM" ? otherSigtermListeners : otherSigintListeners;
|
|
374
|
+
const otherProviderOwnsSignal = getCoexistenceState() === "coexisting" && otherListeners > 0;
|
|
375
|
+
if (!otherProviderOwnsSignal) {
|
|
376
|
+
process.kill(process.pid, signal);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
_signalHandler = handler;
|
|
381
|
+
process.once("SIGTERM", handler);
|
|
382
|
+
process.once("SIGINT", handler);
|
|
383
|
+
}
|
|
384
|
+
function registerBeforeExitTrigger() {
|
|
385
|
+
if (_beforeExitRegistered) return;
|
|
386
|
+
if (typeof process === "undefined" || typeof process.once !== "function") return;
|
|
387
|
+
_beforeExitRegistered = true;
|
|
388
|
+
const handler = () => {
|
|
389
|
+
void executeShutdown();
|
|
390
|
+
};
|
|
391
|
+
_beforeExitHandler = handler;
|
|
392
|
+
process.once("beforeExit", handler);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export {
|
|
396
|
+
setCoexistenceState,
|
|
397
|
+
CoreState,
|
|
398
|
+
AuthState,
|
|
399
|
+
OtelState,
|
|
400
|
+
initLifecycle,
|
|
401
|
+
setCoreState,
|
|
402
|
+
initAuthState,
|
|
403
|
+
setAuthState,
|
|
404
|
+
setOtelState,
|
|
405
|
+
pushDegradationSource,
|
|
406
|
+
clearDegradationSource,
|
|
407
|
+
getCoreState,
|
|
408
|
+
getSdkState,
|
|
409
|
+
onLifecycleEvent,
|
|
410
|
+
emitLifecycleEvent,
|
|
411
|
+
isReady,
|
|
412
|
+
waitForReady,
|
|
413
|
+
getStatus,
|
|
414
|
+
registerShutdownHook,
|
|
415
|
+
executeShutdown,
|
|
416
|
+
registerSignalHandlers,
|
|
417
|
+
registerBeforeExitTrigger
|
|
418
|
+
};
|
|
419
|
+
//# sourceMappingURL=chunk-I2DVVSKW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lifecycle.ts","../src/signal-handler.ts"],"sourcesContent":["/**\n * SDK Lifecycle State Machine\n *\n * Provides a single source of truth for SDK state across three runtime\n * layers: core, auth, and OTel coexistence. (The CLI layer is handled\n * separately via the runtime state file bridge in SDK-026.)\n *\n * The core layer provides a shared typed event emitter that other layers\n * and SDK modules use for cross-layer communication.\n *\n * This module imports only from `./signal-handler.js`, which itself has no\n * imports, so the dependency graph remains acyclic. The logger is still\n * injected via initLifecycle() to avoid coupling to console-capture.\n *\n * @see docs/component-designs/sdk-lifecycle.md\n */\n\nimport { EventEmitter } from \"node:events\";\nimport { getCoexistenceState } from \"./signal-handler.js\";\nimport {\n _registerLifecycleEmitForBridge,\n _clearLifecycleEmitForBridge,\n} from \"./optional-lifecycle.js\";\n\n// ---------------------------------------------------------------------------\n// State Enums\n// ---------------------------------------------------------------------------\n\nexport const CoreState = {\n IDLE: \"IDLE\",\n REGISTERING: \"REGISTERING\",\n KEY_PENDING: \"KEY_PENDING\",\n KEY_RESOLVED: \"KEY_RESOLVED\",\n ACTIVE: \"ACTIVE\",\n ACTIVE_DEGRADED: \"ACTIVE_DEGRADED\",\n SHUTTING_DOWN: \"SHUTTING_DOWN\",\n SHUTDOWN: \"SHUTDOWN\",\n PRODUCTION_DISABLED: \"PRODUCTION_DISABLED\",\n REGISTRATION_FAILED: \"REGISTRATION_FAILED\",\n} as const;\nexport type CoreState = (typeof CoreState)[keyof typeof CoreState];\n\nexport const AuthState = {\n ANONYMOUS: \"ANONYMOUS\",\n AUTHENTICATED: \"AUTHENTICATED\",\n CLAIMING: \"CLAIMING\",\n CLAIMED: \"CLAIMED\",\n} as const;\nexport type AuthState = (typeof AuthState)[keyof typeof AuthState];\n\nexport const OtelState = {\n UNCONFIGURED: \"UNCONFIGURED\",\n CONFIGURING: \"CONFIGURING\",\n OWNS_PROVIDER: \"OWNS_PROVIDER\",\n AUTO_ATTACHED: \"AUTO_ATTACHED\",\n PROCESSOR_PRESENT: \"PROCESSOR_PRESENT\",\n COEXISTENCE_FAILED: \"COEXISTENCE_FAILED\",\n} as const;\nexport type OtelState = (typeof OtelState)[keyof typeof OtelState];\n\n// ---------------------------------------------------------------------------\n// Valid Transitions\n// ---------------------------------------------------------------------------\n\n/**\n * Valid transitions for the core SDK lifecycle state machine.\n *\n * @drift-check ../glasstrace-product/docs/component-designs/sdk-lifecycle.md §4.2 Transition Rules\n */\nconst VALID_CORE_TRANSITIONS: Record<CoreState, readonly CoreState[]> = {\n [CoreState.IDLE]: [CoreState.REGISTERING, CoreState.REGISTRATION_FAILED, CoreState.SHUTTING_DOWN],\n [CoreState.REGISTERING]: [\n CoreState.KEY_PENDING,\n CoreState.PRODUCTION_DISABLED,\n CoreState.REGISTRATION_FAILED,\n CoreState.SHUTTING_DOWN,\n ],\n [CoreState.KEY_PENDING]: [\n CoreState.KEY_RESOLVED,\n CoreState.REGISTRATION_FAILED,\n CoreState.SHUTTING_DOWN,\n ],\n [CoreState.KEY_RESOLVED]: [\n CoreState.ACTIVE,\n CoreState.ACTIVE_DEGRADED,\n CoreState.SHUTTING_DOWN,\n ],\n [CoreState.ACTIVE]: [\n CoreState.ACTIVE_DEGRADED,\n CoreState.SHUTTING_DOWN,\n ],\n [CoreState.ACTIVE_DEGRADED]: [\n CoreState.ACTIVE,\n CoreState.SHUTTING_DOWN,\n ],\n [CoreState.SHUTTING_DOWN]: [CoreState.SHUTDOWN],\n [CoreState.SHUTDOWN]: [],\n [CoreState.PRODUCTION_DISABLED]: [],\n [CoreState.REGISTRATION_FAILED]: [],\n};\n\n/**\n * Valid transitions for the auth state machine.\n *\n * @drift-check ../glasstrace-product/docs/component-designs/sdk-lifecycle.md §5.2 Transitions\n */\nconst VALID_AUTH_TRANSITIONS: Record<AuthState, readonly AuthState[]> = {\n [AuthState.ANONYMOUS]: [AuthState.CLAIMING],\n [AuthState.AUTHENTICATED]: [AuthState.CLAIMING],\n [AuthState.CLAIMING]: [AuthState.CLAIMED],\n [AuthState.CLAIMED]: [AuthState.CLAIMING],\n};\n\n/**\n * Valid transitions for the OTel coexistence state machine.\n *\n * @drift-check ../glasstrace-product/docs/component-designs/sdk-lifecycle.md §6 Layer 3: OTel Coexistence Lifecycle\n */\nconst VALID_OTEL_TRANSITIONS: Record<OtelState, readonly OtelState[]> = {\n [OtelState.UNCONFIGURED]: [OtelState.CONFIGURING],\n [OtelState.CONFIGURING]: [\n OtelState.OWNS_PROVIDER,\n OtelState.AUTO_ATTACHED,\n OtelState.PROCESSOR_PRESENT,\n OtelState.COEXISTENCE_FAILED,\n ],\n [OtelState.OWNS_PROVIDER]: [],\n [OtelState.AUTO_ATTACHED]: [],\n [OtelState.PROCESSOR_PRESENT]: [],\n [OtelState.COEXISTENCE_FAILED]: [],\n};\n\n// ---------------------------------------------------------------------------\n// Event Types\n// ---------------------------------------------------------------------------\n\nexport interface SdkLifecycleEvents {\n \"core:state_changed\": { from: CoreState; to: CoreState };\n \"core:ready\": Record<string, never>;\n \"core:shutdown_started\": Record<string, never>;\n \"core:shutdown_completed\": Record<string, never>;\n /**\n * The boundary-masked-error heuristic fired for an HTTP server span\n * (SDK-051 / DISC-1125 — same-span scope). Emitted from the enriching\n * exporter when ALL of the following hold for an HTTP server span:\n *\n * 1. At least one error signal is present on the span — any of:\n * `span.status.code === SpanStatusCode.ERROR`, an `exception`\n * event from `recordException()`, OR an `exception.type` /\n * `exception.message` span attribute.\n * 2. `http.status_code` is in the trigger set `{200, 0, undefined}`.\n * 3. `span.status.code` is not explicitly `OK`.\n *\n * When all three hold, the SDK promotes the inferred\n * `glasstrace.http.status_code` (typically to 500, or to a value\n * parsed from a numeric `error.type` attribute when present) and\n * fires this event. Informational only — subscribers MAY use it for\n * observability (e.g., heuristic activation rate dashboards) but the\n * heuristic's behavior does NOT depend on subscribers.\n *\n * **Same-span scope:** this event fires when the HTTP server span\n * itself carries the error signal (the DISC-1134 case the existing\n * inference block already handled). Descendant-traversal detection\n * (the page-route boundary case where the exception lives in a\n * child span) is tracked separately and does NOT emit this event\n * today.\n *\n * **PII-safety:** `exceptionMessage` is truncated to 256 characters\n * and is the same content already present on the span's exception\n * event or `exception.message` attribute — no new disclosure surface\n * beyond what already ships in the trace itself. `exceptionMessage`\n * is OMITTED from the payload entirely when no exception event /\n * attribute is present (the `status.code === ERROR`-only case).\n * `spanId` is the OTel span identifier for the HTTP server span\n * where the heuristic fired.\n */\n \"core:error_boundary_detected\": {\n spanId: string;\n inferredStatus: number;\n exceptionMessage?: string;\n };\n\n \"auth:key_resolved\": { key: string; mode: \"anonymous\" | \"dev\" };\n \"auth:claim_started\": { accountId: string };\n \"auth:claim_completed\": { newKey: string; accountId: string };\n\n \"otel:configured\": { state: OtelState; scenario?: string };\n \"otel:injection_succeeded\": { method: string };\n \"otel:injection_failed\": { reason: string };\n /**\n * Structured fail-loud diagnostic emitted when the OTel coexistence\n * path observes an unrecoverable auto-attach failure (DISC-1556).\n * Distinct from `otel:injection_failed` (which carries a free-form\n * `reason` string for logging) — `otel:failed` carries a\n * machine-readable payload destined for the runtime-state CLI bridge.\n *\n * **PII-safety:** the payload's `message` is built from a fixed\n * template; `providerClass` is a sanitized constructor name. See\n * `RuntimeStateLastError` in `runtime-state.ts` for the full contract.\n */\n \"otel:failed\": {\n category: \"auto-attach-returned-null\";\n message: string;\n timestamp: string;\n providerClass?: string;\n };\n /**\n * The export-path circuit breaker has tripped from CLOSED to OPEN\n * (DISC-1568 / Wave 15C). Fired exactly once per outage; the\n * `category` discriminates the failure class that crossed the\n * consecutive-failure threshold and `nextProbeMs` reports the\n * scheduled HALF_OPEN delay.\n *\n * **PII-safety:** the payload's `message` is built from a fixed\n * template and references only the closed `category` enum and the\n * failure count; never URLs, headers, payload bodies, or the\n * underlying error message text. Mirrors the DISC-1556 `otel:failed`\n * contract.\n */\n \"otel:circuit_opened\": {\n category:\n | \"auth\"\n | \"client_error\"\n | \"rate_limit\"\n | \"server_error\"\n | \"network\";\n message: string;\n timestamp: string;\n consecutiveFailures: number;\n nextProbeMs: number;\n };\n /**\n * The breaker's backoff timer expired and the next real export\n * batch is being permitted as a probe (DISC-1568). `previousTimerMs`\n * reports the timer that just elapsed; useful for surfacing a\n * recovery-attempt diagnostic in the CLI bridge.\n */\n \"otel:circuit_half_open\": {\n timestamp: string;\n previousTimerMs: number;\n };\n /**\n * The breaker has transitioned back to CLOSED, either because a\n * probe succeeded or because credential rotation reset the breaker\n * (DISC-1568). `outageDurationMs` reports the wall-clock duration\n * the breaker spent in OPEN+HALF_OPEN; `0` when the close was a\n * defensive no-op (already CLOSED).\n */\n \"otel:circuit_closed\": {\n timestamp: string;\n outageDurationMs: number;\n };\n /**\n * `tracedMiddleware` ran for a procedure invocation under a\n * `wrapBatchedHttpHandler` batch envelope but could not resolve\n * the invocation to a positional batch member (the\n * `procedureName` does not appear in the envelope's procedure\n * list, OR the per-name occurrence count exceeds the positional\n * matches available). The middleware emits the span as today\n * (no batch attributes); this event is informational only — the\n * trace shape is preserved (SDK-052 / Wave 16B).\n *\n * **PII-safety:** `procedureName` and `batchMembers` are tRPC\n * procedure names already on the trace; no new disclosure\n * surface. `spanId` is the OTel span identifier of the\n * unmatched member span.\n */\n \"otel:trpc_batch_member_mismatch\": {\n procedureName: string;\n batchMembers: ReadonlyArray<string>;\n spanId: string;\n };\n \"otel:shutdown_started\": Record<string, never>;\n \"otel:shutdown_completed\": Record<string, never>;\n\n \"health:init_succeeded\": Record<string, never>;\n \"health:init_failed\": { error: string };\n \"health:heartbeat_tick\": Record<string, never>;\n \"health:config_refreshed\": Record<string, never>;\n\n /**\n * `tracedRequestMiddleware` from `@glasstrace/sdk/middleware` was\n * invoked but the SDK is not registered (early-init race or\n * `OtelState.UNCONFIGURED`). The wrapped middleware still runs;\n * the span landed on the OTel API's noop tracer and was discarded\n * (DISC-1537 / SDK-046).\n *\n * Emitted at most once per process by the wrapper to avoid log\n * floods on a hot request path; a single signal is sufficient to\n * surface the misconfiguration.\n *\n * **PII-safety:** payload is empty by construction.\n */\n \"middleware:skipped_uninstalled\": Record<string, never>;\n /**\n * `withAsyncCausality` from `@glasstrace/sdk/async-context` was\n * invoked outside an active request span (no captured\n * `SpanContext` at call time). The continuation still runs; the\n * resulting span has no `glasstrace.causal.post_response_async`\n * link (DISC-1539 / SDK-046).\n *\n * Emitted at most once per process. **PII-safety:** payload is\n * empty by construction.\n */\n \"async:no_originating_context\": Record<string, never>;\n /**\n * `withAsyncCausality` continuation fired but the SDK is not\n * registered. The continuation still runs; the span landed on the\n * noop tracer (DISC-1539 / SDK-046).\n *\n * Emitted at most once per process. **PII-safety:** payload is\n * empty by construction.\n */\n \"async:skipped_uninstalled\": Record<string, never>;\n}\n\n// ---------------------------------------------------------------------------\n// Module State\n// ---------------------------------------------------------------------------\n\nlet _coreState: CoreState = CoreState.IDLE;\nlet _authState: AuthState = AuthState.ANONYMOUS;\nlet _otelState: OtelState = OtelState.UNCONFIGURED;\nlet _emitter: EventEmitter = new EventEmitter();\nlet _logger: ((level: \"warn\" | \"info\" | \"error\", message: string) => void) | null = null;\nlet _initialized = false;\nlet _initWarned = false;\nlet _coreReadyEmitted = false;\nlet _authInitialized = false;\nlet _emitting = false;\n\n// ---------------------------------------------------------------------------\n// Initialization\n// ---------------------------------------------------------------------------\n\n/**\n * Initialize the lifecycle module. Must be called before any state\n * transitions. Accepts a logger function to avoid importing SDK modules.\n *\n * Calling this twice logs a warning and is ignored.\n */\nexport function initLifecycle(options: {\n logger: (level: \"warn\" | \"info\" | \"error\", message: string) => void;\n}): void {\n if (_initialized) {\n options.logger(\"warn\", \"[glasstrace] initLifecycle() called twice — ignored.\");\n return;\n }\n _logger = options.logger;\n _initialized = true;\n\n // Register the lifecycle-emit bridge so edge-safe wrappers\n // (`./middleware/index.ts`, `./async-context/index.ts`) can emit\n // lifecycle events without a static import on this Node-only\n // module. See `./optional-lifecycle.ts` for the contract.\n _registerLifecycleEmitForBridge((event, payload) => {\n emitLifecycleEvent(\n event as keyof SdkLifecycleEvents,\n payload as SdkLifecycleEvents[keyof SdkLifecycleEvents],\n );\n });\n}\n\n// ---------------------------------------------------------------------------\n// State Transitions\n// ---------------------------------------------------------------------------\n\n/** Warn once if lifecycle functions are called before initLifecycle(). */\nfunction warnIfNotInitialized(): void {\n if (!_initialized && !_initWarned) {\n _initWarned = true;\n // Use console.warn directly since _logger is null\n console.warn(\n \"[glasstrace] Lifecycle state changed before initLifecycle() was called. \" +\n \"Logger not available — errors will be silent.\",\n );\n }\n}\n\n/**\n * Transition the core lifecycle state. Invalid transitions are logged\n * and ignored — the state does not change.\n *\n * Guards against reentrant calls: if a listener calls setCoreState()\n * during emission, the inner transition completes first. The outer\n * call's post-transition events (core:ready, shutdown) check the\n * current state before emitting to avoid stale signals.\n */\nexport function setCoreState(to: CoreState): void {\n warnIfNotInitialized();\n\n const from = _coreState;\n if (from === to) return;\n\n const valid = VALID_CORE_TRANSITIONS[from];\n if (!valid.includes(to)) {\n _logger?.(\n \"warn\",\n `[glasstrace] Invalid core state transition: ${from} → ${to}. Ignored.`,\n );\n return;\n }\n\n _coreState = to;\n\n // Guard against reentrant emission: if a listener calls setCoreState(),\n // the inner call will complete (including its own events). The outer call\n // skips its post-transition events to avoid stale/duplicate signals.\n if (_emitting) return;\n\n _emitting = true;\n try {\n emitSafe(\"core:state_changed\", { from, to });\n\n // Check current state (not `to`) in case a listener changed it\n const current = _coreState;\n\n if (!_coreReadyEmitted && (current === CoreState.ACTIVE || current === CoreState.ACTIVE_DEGRADED)) {\n _coreReadyEmitted = true;\n emitSafe(\"core:ready\", {});\n }\n\n if (current === CoreState.SHUTTING_DOWN) {\n emitSafe(\"core:shutdown_started\", {});\n }\n if (current === CoreState.SHUTDOWN) {\n emitSafe(\"core:shutdown_completed\", {});\n }\n } finally {\n _emitting = false;\n }\n\n // Catch-up after entering ACTIVE: if a degradation source was\n // pushed while core was still in a pre-ACTIVE state\n // (KEY_PENDING/KEY_RESOLVED), `recomputeCoreFromDegradationSources()`\n // no-op'd at push time because the guard said \"only act if core is\n // ACTIVE\". Now that we've reached ACTIVE, re-evaluate so the\n // registry's truth wins (Codex P1, 2026-05-08; covers the export\n // circuit + future degradation sources uniformly).\n if (to === CoreState.ACTIVE && _degradationSources.size > 0) {\n recomputeCoreFromDegradationSources();\n }\n}\n\n/**\n * Set the initial auth state. Must be called exactly once during\n * registration, before any auth transitions. This bypasses transition\n * validation because the initial state (ANONYMOUS vs AUTHENTICATED)\n * is determined by configuration, not by a runtime transition.\n *\n * Subsequent calls log a warning and are ignored.\n */\nexport function initAuthState(state: AuthState): void {\n if (_authInitialized) {\n _logger?.(\n \"warn\",\n \"[glasstrace] initAuthState() called after auth state already initialized. Ignored.\",\n );\n return;\n }\n _authInitialized = true;\n _authState = state;\n}\n\n/**\n * Transition the auth lifecycle state. Invalid transitions are logged\n * and ignored.\n */\nexport function setAuthState(to: AuthState): void {\n warnIfNotInitialized();\n\n const from = _authState;\n if (from === to) return;\n\n const valid = VALID_AUTH_TRANSITIONS[from];\n if (!valid.includes(to)) {\n _logger?.(\n \"warn\",\n `[glasstrace] Invalid auth state transition: ${from} → ${to}. Ignored.`,\n );\n return;\n }\n\n _authState = to;\n}\n\n/**\n * Transition the OTel coexistence state. Invalid transitions are logged\n * and ignored.\n */\nexport function setOtelState(to: OtelState): void {\n warnIfNotInitialized();\n\n const from = _otelState;\n if (from === to) return;\n\n const valid = VALID_OTEL_TRANSITIONS[from];\n if (!valid.includes(to)) {\n _logger?.(\n \"warn\",\n `[glasstrace] Invalid OTel state transition: ${from} → ${to}. Ignored.`,\n );\n return;\n }\n\n _otelState = to;\n}\n\n// ---------------------------------------------------------------------------\n// Degradation Source Registry (DISC-1568 / Wave 15C)\n//\n// Multiple subsystems can independently push the SDK into\n// `CoreState.ACTIVE_DEGRADED`. Each source registers a key here when\n// it goes degraded and clears the same key when it recovers.\n// `recomputeCoreFromDegradationSources()` reads the registry and\n// transitions `ACTIVE ↔ ACTIVE_DEGRADED` only when the SDK is in one\n// of those two states — `OtelState.COEXISTENCE_FAILED` and other\n// pre-`ACTIVE` states are untouched.\n//\n// Keys are namespaced strings (e.g., `\"export-circuit\"`) so multiple\n// sources can coexist without clobbering each other. Centralising the\n// recompute prevents the \"two sources of truth\" bug where one source\n// thinks the SDK is healthy but another still has it degraded.\n// ---------------------------------------------------------------------------\n\nconst _degradationSources = new Set<string>();\n\n/**\n * Register a subsystem-specific degradation source. Idempotent — calling\n * twice with the same key has no additional effect. After updating the\n * registry the function calls {@link recomputeCoreFromDegradationSources}\n * so a transition fires immediately when appropriate.\n */\nexport function pushDegradationSource(key: string): void {\n _degradationSources.add(key);\n recomputeCoreFromDegradationSources();\n}\n\n/**\n * Clear a previously-registered degradation source. Triggers a\n * recompute so the SDK can return to `CoreState.ACTIVE` if no other\n * source remains.\n */\nexport function clearDegradationSource(key: string): void {\n _degradationSources.delete(key);\n recomputeCoreFromDegradationSources();\n}\n\n/**\n * Re-evaluate the core state against the degradation registry:\n *\n * - At least one source AND core is `ACTIVE` → transition to\n * `ACTIVE_DEGRADED`.\n * - Zero sources AND core is `ACTIVE_DEGRADED` → transition to\n * `ACTIVE`.\n * - Otherwise: no-op. We do not push a pre-ACTIVE state forward and\n * we do not transition out of terminal/shutdown states.\n *\n * Centralised so a future degradation source (e.g., heartbeat\n * failures) can reuse the same path without duplicating the guard.\n */\nexport function recomputeCoreFromDegradationSources(): void {\n const hasDegradation = _degradationSources.size > 0;\n if (hasDegradation && _coreState === CoreState.ACTIVE) {\n setCoreState(CoreState.ACTIVE_DEGRADED);\n return;\n }\n if (!hasDegradation && _coreState === CoreState.ACTIVE_DEGRADED) {\n setCoreState(CoreState.ACTIVE);\n }\n}\n\n// ---------------------------------------------------------------------------\n// State Queries\n// ---------------------------------------------------------------------------\n\n/** Returns the current core lifecycle state. */\nexport function getCoreState(): CoreState {\n return _coreState;\n}\n\n/** Returns the current auth lifecycle state. */\nexport function getAuthState(): AuthState {\n return _authState;\n}\n\n/** Returns the current OTel coexistence state. */\nexport function getOtelState(): OtelState {\n return _otelState;\n}\n\n/** Returns the full internal state across all layers. */\nexport function getSdkState(): {\n core: CoreState;\n auth: AuthState;\n otel: OtelState;\n} {\n return {\n core: _coreState,\n auth: _authState,\n otel: _otelState,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Event Emitter\n// ---------------------------------------------------------------------------\n\n/**\n * Subscribe to a lifecycle event. The listener is synchronous.\n * Errors in listeners are caught and logged.\n */\nexport function onLifecycleEvent<K extends keyof SdkLifecycleEvents>(\n event: K,\n listener: (payload: SdkLifecycleEvents[K]) => void,\n): void {\n _emitter.on(event, listener);\n}\n\n/**\n * Emit a typed lifecycle event. Exported so that other SDK modules\n * (auth, OTel, health) can emit their layer-specific events through\n * the shared emitter with type safety.\n */\nexport function emitLifecycleEvent<K extends keyof SdkLifecycleEvents>(\n event: K,\n payload: SdkLifecycleEvents[K],\n): void {\n emitSafe(event, payload);\n}\n\n/**\n * Unsubscribe from a lifecycle event.\n */\nexport function offLifecycleEvent<K extends keyof SdkLifecycleEvents>(\n event: K,\n listener: (payload: SdkLifecycleEvents[K]) => void,\n): void {\n _emitter.off(event, listener);\n}\n\n/**\n * Emit a lifecycle event. Each listener is called individually so that\n * an error in one listener does not prevent subsequent listeners from\n * running. Both synchronous throws and async rejections are caught and\n * logged via the lifecycle logger.\n */\nfunction emitSafe<K extends keyof SdkLifecycleEvents>(\n event: K,\n payload: SdkLifecycleEvents[K],\n): void {\n const listeners = _emitter.listeners(event);\n for (const listener of listeners) {\n try {\n const result = (listener as (p: SdkLifecycleEvents[K]) => unknown)(payload);\n // Catch async listeners that return a rejected promise\n if (result && typeof (result as Promise<unknown>).catch === \"function\") {\n (result as Promise<unknown>).catch((err: unknown) => {\n _logger?.(\n \"error\",\n `[glasstrace] Async error in lifecycle event listener for \"${event}\": ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n });\n }\n } catch (err) {\n _logger?.(\n \"error\",\n `[glasstrace] Error in lifecycle event listener for \"${event}\": ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Readiness API\n// ---------------------------------------------------------------------------\n\n/**\n * Returns true when the SDK is in ACTIVE or ACTIVE_DEGRADED state.\n */\nexport function isReady(): boolean {\n return _coreState === CoreState.ACTIVE || _coreState === CoreState.ACTIVE_DEGRADED;\n}\n\n/**\n * Resolves when the SDK reaches ACTIVE or ACTIVE_DEGRADED.\n * Rejects on PRODUCTION_DISABLED, REGISTRATION_FAILED, or timeout.\n *\n * Checks current state synchronously first — resolves/rejects immediately\n * if the SDK has already reached a terminal or ready state.\n */\nexport function waitForReady(timeoutMs = 30000): Promise<void> {\n // Check current state synchronously\n if (isReady()) {\n return Promise.resolve();\n }\n if (\n _coreState === CoreState.PRODUCTION_DISABLED ||\n _coreState === CoreState.REGISTRATION_FAILED ||\n _coreState === CoreState.SHUTTING_DOWN ||\n _coreState === CoreState.SHUTDOWN\n ) {\n return Promise.reject(new Error(`SDK is in terminal state: ${_coreState}`));\n }\n\n return new Promise<void>((resolve, reject) => {\n let settled = false;\n\n const listener = ({ to }: { from: CoreState; to: CoreState }) => {\n if (settled) return;\n if (to === CoreState.ACTIVE || to === CoreState.ACTIVE_DEGRADED) {\n settled = true;\n offLifecycleEvent(\"core:state_changed\", listener);\n resolve();\n } else if (\n to === CoreState.PRODUCTION_DISABLED ||\n to === CoreState.REGISTRATION_FAILED ||\n to === CoreState.SHUTTING_DOWN ||\n to === CoreState.SHUTDOWN\n ) {\n settled = true;\n offLifecycleEvent(\"core:state_changed\", listener);\n reject(new Error(`SDK reached terminal state: ${to}`));\n }\n };\n\n onLifecycleEvent(\"core:state_changed\", listener);\n\n if (timeoutMs > 0) {\n const timer = setTimeout(() => {\n if (settled) return;\n settled = true;\n offLifecycleEvent(\"core:state_changed\", listener);\n reject(new Error(`waitForReady timed out after ${timeoutMs}ms (state: ${_coreState})`));\n }, timeoutMs);\n // unref() so this timer doesn't prevent process exit\n if (typeof timer === \"object\" && \"unref\" in timer) {\n timer.unref();\n }\n }\n });\n}\n\n/**\n * Simplified public state query for external consumers.\n * Hides implementation details like coexistence scenarios.\n *\n * The returned `tracing` field is the canonical user-observable signal\n * for OTel coexistence outcomes:\n *\n * - `\"active\"` — the SDK owns the OTel provider and is exporting spans.\n * - `\"coexistence\"` — another OTel provider was detected and the SDK\n * either auto-attached its span processor or found one already\n * present. Spans are exported through the existing pipeline.\n * - `\"degraded\"` — the SDK is exporting but the core lifecycle entered\n * `ACTIVE_DEGRADED` (e.g., a non-fatal export failure).\n * - `\"not-configured\"` — the SDK could not configure tracing. Covers\n * `OtelState.UNCONFIGURED`, `OtelState.CONFIGURING`, and\n * `OtelState.COEXISTENCE_FAILED` (the DISC-1556 Next 16 production\n * \"auto-attach returned null\" path). When the value is\n * `\"not-configured\"` after `registerGlasstrace()` has resolved,\n * spans are NOT reaching the Glasstrace exporter and the manual\n * `createGlasstraceSpanProcessor()` workaround should be applied.\n * See `runtime-state.json`'s `lastError` field for the structured\n * failure record.\n */\nexport function getStatus(): {\n ready: boolean;\n mode: \"anonymous\" | \"authenticated\" | \"claiming\" | \"disabled\";\n tracing: \"active\" | \"degraded\" | \"not-configured\" | \"coexistence\";\n} {\n let mode: \"anonymous\" | \"authenticated\" | \"claiming\" | \"disabled\";\n if (_coreState === CoreState.PRODUCTION_DISABLED) {\n mode = \"disabled\";\n } else if (_authState === AuthState.CLAIMING || _authState === AuthState.CLAIMED) {\n mode = \"claiming\";\n } else if (_authState === AuthState.AUTHENTICATED) {\n mode = \"authenticated\";\n } else {\n mode = \"anonymous\";\n }\n\n let tracing: \"active\" | \"degraded\" | \"not-configured\" | \"coexistence\";\n if (_otelState === OtelState.COEXISTENCE_FAILED || _otelState === OtelState.UNCONFIGURED || _otelState === OtelState.CONFIGURING) {\n tracing = \"not-configured\";\n } else if (_coreState === CoreState.ACTIVE_DEGRADED) {\n tracing = \"degraded\";\n } else if (_otelState === OtelState.AUTO_ATTACHED || _otelState === OtelState.PROCESSOR_PRESENT) {\n tracing = \"coexistence\";\n } else {\n tracing = \"active\";\n }\n\n return {\n ready: isReady(),\n mode,\n tracing,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Shutdown Coordinator\n//\n// IMPORTANT: The shutdown system has two parts that must stay in sync:\n// 1. HOOKS — registered via registerShutdownHook() by each module\n// 2. TRIGGERS — registerSignalHandlers() for signal-based exit, or\n// registerBeforeExitTrigger() for event-loop-drain exit. Both\n// call executeShutdown() which is idempotent.\n//\n// Rules for agents modifying shutdown behavior:\n// - When registering a hook, verify its trigger exists in the same PR.\n// A hook without a trigger is dead code.\n// - When removing a trigger, verify no hooks depend on it.\n// A trigger removal without hook cleanup drops spans on exit.\n// - Scenario A (bare path): register BOTH signal handlers AND\n// beforeExit trigger. Signals cover SIGTERM/SIGINT, beforeExit\n// covers clean event loop drain (all timers unref'd).\n// - Scenario B (coexistence): signal handlers are ALWAYS installed\n// (DISC-1265) but do NOT re-raise (coexistenceState=\"coexisting\").\n// The beforeExit trigger also fires for event-loop-drain exit.\n// The existing provider owns signal re-raise and its own flush.\n// ---------------------------------------------------------------------------\n\nexport interface ShutdownHook {\n name: string;\n priority: number;\n fn: () => Promise<void>;\n}\n\nlet _shutdownHooks: ShutdownHook[] = [];\nlet _signalHandlersRegistered = false;\nlet _signalHandler: ((signal: NodeJS.Signals) => void) | null = null;\nlet _beforeExitRegistered = false;\nlet _beforeExitHandler: (() => void) | null = null;\nlet _shutdownExecuted = false;\n\n/**\n * Register a shutdown hook. Hooks are executed in priority order\n * (lower number = earlier execution) during shutdown.\n */\nexport function registerShutdownHook(hook: ShutdownHook): void {\n _shutdownHooks.push(hook);\n _shutdownHooks.sort((a, b) => a.priority - b.priority);\n}\n\n/**\n * Execute all registered shutdown hooks in priority order.\n * Each hook runs with a timeout. Errors in individual hooks are caught\n * and logged — remaining hooks still execute.\n *\n * Idempotent: calling this multiple times has no effect after the first.\n */\nexport async function executeShutdown(timeoutMs = 5000): Promise<void> {\n if (_shutdownExecuted) return;\n _shutdownExecuted = true;\n\n setCoreState(CoreState.SHUTTING_DOWN);\n\n for (const hook of _shutdownHooks) {\n try {\n // Suppress unhandled rejection on the hook promise if the timeout wins the race.\n const hookPromise = hook.fn();\n hookPromise.catch(() => {});\n\n await Promise.race([\n hookPromise,\n new Promise<void>((_, reject) => {\n const timer = setTimeout(() => reject(new Error(`Shutdown hook \"${hook.name}\" timed out`)), timeoutMs);\n if (typeof timer === \"object\" && \"unref\" in timer) {\n timer.unref();\n }\n }),\n ]);\n } catch (err) {\n _logger?.(\n \"warn\",\n `[glasstrace] Shutdown hook \"${hook.name}\" failed: ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n }\n }\n\n setCoreState(CoreState.SHUTDOWN);\n}\n\n/**\n * Register SIGTERM and SIGINT handlers that trigger the shutdown coordinator.\n * Always installed by registerGlasstrace(), regardless of whether another\n * OTel provider exists (DISC-1265). The re-raise decision is deferred to\n * delivery time: the handler checks coexistenceState (set by configureOtel()\n * once its async provider probe completes) and only re-raises when NOT\n * \"coexisting\". In coexistence mode, hooks still run but the existing\n * provider is responsible for re-raising the signal.\n */\nexport function registerSignalHandlers(): void {\n if (_signalHandlersRegistered) return;\n if (typeof process === \"undefined\" || typeof process.once !== \"function\") return;\n\n _signalHandlersRegistered = true;\n\n // Snapshot listener counts BEFORE we install our own handlers. A non-zero\n // count means another party (Sentry, Datadog, the existing provider) already\n // owns SIGTERM/SIGINT and will re-raise when it is done flushing. Zero means\n // nobody else handles the signal — if we don't re-raise, the process hangs.\n // This check is needed because `coexistenceState === \"coexisting\"` only tells\n // us that ANOTHER OTEL PROVIDER exists, not that it installed signal handlers.\n // A bare BasicTracerProvider has no signal handlers, so we must still re-raise.\n const otherSigtermListeners = process.listenerCount(\"SIGTERM\");\n const otherSigintListeners = process.listenerCount(\"SIGINT\");\n\n const handler = (signal: NodeJS.Signals) => {\n void executeShutdown().finally(() => {\n // Remove our handler to avoid re-entry on re-raise.\n if (_signalHandler) {\n process.removeListener(\"SIGTERM\", _signalHandler);\n process.removeListener(\"SIGINT\", _signalHandler);\n }\n // Re-raise the signal to restore default OS behavior UNLESS we are in\n // coexistence mode AND the other provider had its own signal handlers at\n // registration time. When both conditions hold, that provider owns signal\n // re-raise and will terminate the process on its own schedule; re-raising\n // here would race against its async flush and could kill the process\n // before buffered spans are delivered.\n //\n // When coexisting but NO pre-existing signal listeners were detected, we\n // must still re-raise — the other provider (e.g. a bare BasicTracerProvider)\n // has no signal ownership, so OS default termination will not happen\n // otherwise and the process would hang indefinitely.\n //\n // During the async-window (\"unknown\"), re-raise is the safe default because\n // it preserves standard process termination semantics when we have no\n // information about provider ownership.\n const otherListeners = signal === \"SIGTERM\" ? otherSigtermListeners : otherSigintListeners;\n const otherProviderOwnsSignal = getCoexistenceState() === \"coexisting\" && otherListeners > 0;\n if (!otherProviderOwnsSignal) {\n process.kill(process.pid, signal);\n }\n });\n };\n\n _signalHandler = handler;\n process.once(\"SIGTERM\", handler);\n process.once(\"SIGINT\", handler);\n}\n\n/**\n * Register a beforeExit handler that triggers the shutdown coordinator.\n * beforeExit fires when the event loop drains (not on signals).\n *\n * For Scenario B (coexistence): Glasstrace installs signal handlers (DISC-1265)\n * but does not re-raise — the existing provider owns signal re-raise. This\n * beforeExit trigger covers the edge case where the process exits without\n * signals (event loop drains naturally).\n *\n * Both signal handlers and beforeExit triggers call the same executeShutdown(),\n * which is idempotent — if signals already ran shutdown, beforeExit is a no-op.\n */\nexport function registerBeforeExitTrigger(): void {\n if (_beforeExitRegistered) return;\n if (typeof process === \"undefined\" || typeof process.once !== \"function\") return;\n\n _beforeExitRegistered = true;\n\n const handler = () => {\n void executeShutdown();\n };\n\n _beforeExitHandler = handler;\n process.once(\"beforeExit\", handler);\n}\n\n// ---------------------------------------------------------------------------\n// Testing\n// ---------------------------------------------------------------------------\n\n/**\n * Reset all lifecycle state to initial values. For testing only.\n * Removes all event listeners, resets all state enums, and clears\n * the initialized flag.\n */\nexport function resetLifecycleForTesting(): void {\n _coreState = CoreState.IDLE;\n _authState = AuthState.ANONYMOUS;\n _otelState = OtelState.UNCONFIGURED;\n _emitter.removeAllListeners();\n _emitter = new EventEmitter();\n _logger = null;\n _initialized = false;\n _initWarned = false;\n _coreReadyEmitted = false;\n _authInitialized = false;\n _emitting = false;\n _shutdownHooks = [];\n _shutdownExecuted = false;\n _degradationSources.clear();\n if (_signalHandler && typeof process !== \"undefined\") {\n process.removeListener(\"SIGTERM\", _signalHandler);\n process.removeListener(\"SIGINT\", _signalHandler);\n }\n _signalHandler = null;\n _signalHandlersRegistered = false;\n if (_beforeExitHandler && typeof process !== \"undefined\") {\n process.removeListener(\"beforeExit\", _beforeExitHandler);\n }\n _beforeExitHandler = null;\n _beforeExitRegistered = false;\n _clearLifecycleEmitForBridge();\n}\n","/**\n * Coexistence state for the signal handler.\n *\n * Set by configureOtel() once the async provider probe completes:\n * - \"sole-owner\" — Glasstrace owns the OTel provider (Scenarios A / E).\n * The signal handler re-raises after draining hooks.\n * - \"coexisting\" — Another provider exists (Scenario B / C / F).\n * The signal handler drains our hooks but does NOT\n * re-raise, so the existing provider's shutdown can\n * complete at its own pace.\n * - \"unknown\" — The async probe has not completed yet (startup window).\n * Treated the same as \"sole-owner\" — re-raise is the\n * safe default because it preserves the process's default\n * signal semantics when we have no information.\n */\ntype CoexistenceState = \"unknown\" | \"sole-owner\" | \"coexisting\";\n\nlet coexistenceState: CoexistenceState = \"unknown\";\n\n/**\n * Called by configureOtel() once the async provider probe completes.\n * \"sole-owner\" when Glasstrace owns the provider; \"coexisting\" otherwise.\n */\nexport function setCoexistenceState(s: CoexistenceState): void {\n coexistenceState = s;\n}\n\n/**\n * Returns the current coexistence state.\n * \"unknown\" until configureOtel() completes its async provider probe.\n */\nexport function getCoexistenceState(): CoexistenceState {\n return coexistenceState;\n}\n\n/**\n * Resets coexistence state to \"unknown\". For testing only.\n */\nexport function _resetCoexistenceStateForTesting(): void {\n coexistenceState = \"unknown\";\n}\n"],"mappings":";;;;;AAiBA,SAAS,oBAAoB;;;ACA7B,IAAI,mBAAqC;AAMlC,SAAS,oBAAoB,GAA2B;AAC7D,qBAAmB;AACrB;AAMO,SAAS,sBAAwC;AACtD,SAAO;AACT;;;ADLO,IAAM,YAAY;AAAA,EACvB,MAAM;AAAA,EACN,aAAa;AAAA,EACb,aAAa;AAAA,EACb,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,UAAU;AAAA,EACV,qBAAqB;AAAA,EACrB,qBAAqB;AACvB;AAGO,IAAM,YAAY;AAAA,EACvB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,UAAU;AAAA,EACV,SAAS;AACX;AAGO,IAAM,YAAY;AAAA,EACvB,cAAc;AAAA,EACd,aAAa;AAAA,EACb,eAAe;AAAA,EACf,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,oBAAoB;AACtB;AAYA,IAAM,yBAAkE;AAAA,EACtE,CAAC,UAAU,IAAI,GAAG,CAAC,UAAU,aAAa,UAAU,qBAAqB,UAAU,aAAa;AAAA,EAChG,CAAC,UAAU,WAAW,GAAG;AAAA,IACvB,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,EACZ;AAAA,EACA,CAAC,UAAU,WAAW,GAAG;AAAA,IACvB,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,EACZ;AAAA,EACA,CAAC,UAAU,YAAY,GAAG;AAAA,IACxB,UAAU;AAAA,IACV,UAAU;AAAA,IACV,UAAU;AAAA,EACZ;AAAA,EACA,CAAC,UAAU,MAAM,GAAG;AAAA,IAClB,UAAU;AAAA,IACV,UAAU;AAAA,EACZ;AAA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AAe,OAAO,QAAQ,SAAS,WAAY;AAE1E,0BAAwB;AAExB,QAAM,UAAU,MAAM;AACpB,SAAK,gBAAgB;AAAA,EACvB;AAEA,uBAAqB;AACrB,UAAQ,KAAK,cAAc,OAAO;AACpC;","names":[]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-DQ25VOKK.js";
|
|
4
4
|
import {
|
|
5
5
|
GLASSTRACE_ATTRIBUTE_NAMES
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6RKS3DNA.js";
|
|
7
7
|
|
|
8
8
|
// src/errors.ts
|
|
9
9
|
var SdkError = class extends Error {
|
|
@@ -102,4 +102,4 @@ export {
|
|
|
102
102
|
GlasstraceSpanProcessor,
|
|
103
103
|
captureCorrelationId
|
|
104
104
|
};
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
105
|
+
//# sourceMappingURL=chunk-M5GO2SSO.js.map
|