@glasstrace/sdk 0.13.2 → 0.13.3
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/index.cjs +29 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3643,32 +3643,34 @@ async function configureOtel(config, sessionManager) {
|
|
|
3643
3643
|
const provider = new BasicTracerProvider({
|
|
3644
3644
|
spanProcessors: [processor]
|
|
3645
3645
|
});
|
|
3646
|
-
const asyncHooks = await tryImport("node:async_hooks");
|
|
3647
|
-
if (!asyncHooks) {
|
|
3648
|
-
trace.setGlobalTracerProvider(provider);
|
|
3649
|
-
registerShutdownHooks(provider);
|
|
3650
|
-
return;
|
|
3651
|
-
}
|
|
3652
|
-
const { AsyncLocalStorage } = asyncHooks;
|
|
3653
|
-
const als = new AsyncLocalStorage();
|
|
3654
|
-
const contextManager = {
|
|
3655
|
-
active: () => als.getStore() ?? ROOT_CONTEXT,
|
|
3656
|
-
with: (context2, fn, thisArg, ...args) => als.run(context2, () => fn.apply(thisArg, args)),
|
|
3657
|
-
bind: (context2, target) => {
|
|
3658
|
-
if (typeof target === "function") {
|
|
3659
|
-
const bound = (...args) => als.run(context2, () => target(...args));
|
|
3660
|
-
return bound;
|
|
3661
|
-
}
|
|
3662
|
-
return target;
|
|
3663
|
-
},
|
|
3664
|
-
enable: () => contextManager,
|
|
3665
|
-
disable: () => contextManager
|
|
3666
|
-
};
|
|
3667
|
-
context.setGlobalContextManager(contextManager);
|
|
3668
3646
|
trace.setGlobalTracerProvider(provider);
|
|
3669
3647
|
registerShutdownHooks(provider);
|
|
3670
3648
|
}
|
|
3671
3649
|
|
|
3650
|
+
// src/context-manager.ts
|
|
3651
|
+
function installContextManager() {
|
|
3652
|
+
try {
|
|
3653
|
+
const req = Function("id", "return require(id)");
|
|
3654
|
+
const asyncHooks = req("node:async_hooks");
|
|
3655
|
+
const als = new asyncHooks.AsyncLocalStorage();
|
|
3656
|
+
const contextManager = {
|
|
3657
|
+
active: () => als.getStore() ?? ROOT_CONTEXT,
|
|
3658
|
+
with: (context2, fn, thisArg, ...args) => als.run(context2, () => fn.apply(thisArg, args)),
|
|
3659
|
+
bind: (context2, target) => {
|
|
3660
|
+
if (typeof target === "function") {
|
|
3661
|
+
const bound = (...fnArgs) => als.run(context2, () => target(...fnArgs));
|
|
3662
|
+
return bound;
|
|
3663
|
+
}
|
|
3664
|
+
return target;
|
|
3665
|
+
},
|
|
3666
|
+
enable: () => contextManager,
|
|
3667
|
+
disable: () => contextManager
|
|
3668
|
+
};
|
|
3669
|
+
context.setGlobalContextManager(contextManager);
|
|
3670
|
+
} catch {
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
|
|
3672
3674
|
// src/heartbeat.ts
|
|
3673
3675
|
var HEARTBEAT_INTERVAL_MS = 5 * 60 * 1e3;
|
|
3674
3676
|
var BACKOFF_BASE_MS = HEARTBEAT_INTERVAL_MS;
|
|
@@ -3826,6 +3828,7 @@ function registerGlasstrace(options) {
|
|
|
3826
3828
|
}
|
|
3827
3829
|
isRegistered = true;
|
|
3828
3830
|
const currentGeneration = registrationGeneration;
|
|
3831
|
+
installContextManager();
|
|
3829
3832
|
void configureOtel(config, sessionManager).then(
|
|
3830
3833
|
() => {
|
|
3831
3834
|
maybeInstallConsoleCapture();
|
|
@@ -3925,8 +3928,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
|
|
|
3925
3928
|
if (config.verbose) {
|
|
3926
3929
|
console.info("[glasstrace] Background init firing.");
|
|
3927
3930
|
}
|
|
3928
|
-
const healthReport = collectHealthReport("0.13.
|
|
3929
|
-
const initResult = await performInit(config, anonKeyForInit, "0.13.
|
|
3931
|
+
const healthReport = collectHealthReport("0.13.3");
|
|
3932
|
+
const initResult = await performInit(config, anonKeyForInit, "0.13.3", healthReport);
|
|
3930
3933
|
if (generation !== registrationGeneration) return;
|
|
3931
3934
|
if (initResult?.claimResult) {
|
|
3932
3935
|
setResolvedApiKey(initResult.claimResult.newApiKey);
|
|
@@ -3934,7 +3937,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
|
|
|
3934
3937
|
}
|
|
3935
3938
|
maybeInstallConsoleCapture();
|
|
3936
3939
|
if (didLastInitSucceed()) {
|
|
3937
|
-
startHeartbeat(config, anonKeyForInit, "0.13.
|
|
3940
|
+
startHeartbeat(config, anonKeyForInit, "0.13.3", generation, (newApiKey) => {
|
|
3938
3941
|
setResolvedApiKey(newApiKey);
|
|
3939
3942
|
notifyApiKeyResolved();
|
|
3940
3943
|
});
|