@glasstrace/sdk 1.1.3 → 1.2.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/cli/init.cjs CHANGED
@@ -18826,7 +18826,7 @@ async function verifyAnonKeyRegistration(projectRoot) {
18826
18826
  }
18827
18827
  const baseConfig = resolveConfig({ apiKey: devKey });
18828
18828
  const config2 = { ...baseConfig, apiKey: devKey };
18829
- const sdkVersion = true ? "1.1.3" : "0.0.0-dev";
18829
+ const sdkVersion = true ? "1.2.0" : "0.0.0-dev";
18830
18830
  const result = await verifyInitReachable(config2, anonKey, sdkVersion);
18831
18831
  if (result.ok) {
18832
18832
  return { outcome: "verified" };
package/dist/cli/init.js CHANGED
@@ -994,7 +994,7 @@ async function verifyAnonKeyRegistration(projectRoot) {
994
994
  }
995
995
  const baseConfig = resolveConfig({ apiKey: devKey });
996
996
  const config = { ...baseConfig, apiKey: devKey };
997
- const sdkVersion = true ? "1.1.3" : "0.0.0-dev";
997
+ const sdkVersion = true ? "1.2.0" : "0.0.0-dev";
998
998
  const result = await verifyInitReachable(config, anonKey, sdkVersion);
999
999
  if (result.ok) {
1000
1000
  return { outcome: "verified" };
package/dist/index.cjs CHANGED
@@ -22184,8 +22184,51 @@ async function runRegistrationPath(config2, sessionManager) {
22184
22184
  // src/context-manager.ts
22185
22185
  var import_node_async_hooks = require("node:async_hooks");
22186
22186
  init_esm();
22187
+ var GLASSTRACE_BRAND = 1;
22188
+ var GUARD = /* @__PURE__ */ Symbol.for("glasstrace.context-manager.installed");
22189
+ var OTEL_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api.1");
22190
+ function isOtelContextManager(value) {
22191
+ if (typeof value !== "object" || value === null) return false;
22192
+ const candidate = value;
22193
+ return typeof candidate.active === "function" && typeof candidate.with === "function" && typeof candidate.bind === "function" && typeof candidate.enable === "function" && typeof candidate.disable === "function";
22194
+ }
22195
+ function isInstallationRecord(value) {
22196
+ if (typeof value !== "object" || value === null) return false;
22197
+ const candidate = value;
22198
+ if (candidate.glasstraceContextManagerBrand !== GLASSTRACE_BRAND) return false;
22199
+ return candidate.manager === null || isOtelContextManager(candidate.manager);
22200
+ }
22201
+ function getOtelRegisteredContextManager() {
22202
+ const otelSlot = globalThis[OTEL_API_KEY];
22203
+ if (typeof otelSlot !== "object" || otelSlot === null) return void 0;
22204
+ const ctx = otelSlot.context;
22205
+ return isOtelContextManager(ctx) ? ctx : void 0;
22206
+ }
22187
22207
  function installContextManager() {
22188
22208
  try {
22209
+ const slot = globalThis;
22210
+ const existing = slot[GUARD];
22211
+ const otelCurrent = getOtelRegisteredContextManager();
22212
+ if (isInstallationRecord(existing) && existing.manager !== null && existing.manager === otelCurrent) {
22213
+ return true;
22214
+ }
22215
+ if (isInstallationRecord(existing) && existing.manager === null && otelCurrent !== void 0) {
22216
+ return false;
22217
+ }
22218
+ if (isInstallationRecord(existing) && existing.manager !== null) {
22219
+ const reSuccess = context.setGlobalContextManager(existing.manager);
22220
+ if (!reSuccess) {
22221
+ console.warn(
22222
+ "[glasstrace] Another context manager is already registered. Trace context propagation may not work as expected."
22223
+ );
22224
+ }
22225
+ const reRecord = {
22226
+ glasstraceContextManagerBrand: GLASSTRACE_BRAND,
22227
+ manager: reSuccess ? existing.manager : null
22228
+ };
22229
+ slot[GUARD] = reRecord;
22230
+ return reSuccess;
22231
+ }
22189
22232
  const als = new import_node_async_hooks.AsyncLocalStorage();
22190
22233
  const contextManager = {
22191
22234
  active: () => als.getStore() ?? ROOT_CONTEXT,
@@ -22206,6 +22249,11 @@ function installContextManager() {
22206
22249
  "[glasstrace] Another context manager is already registered. Trace context propagation may not work as expected."
22207
22250
  );
22208
22251
  }
22252
+ const record2 = {
22253
+ glasstraceContextManagerBrand: GLASSTRACE_BRAND,
22254
+ manager: success2 ? contextManager : null
22255
+ };
22256
+ slot[GUARD] = record2;
22209
22257
  return success2;
22210
22258
  } catch {
22211
22259
  return false;
@@ -22437,7 +22485,7 @@ function registerGlasstrace(options) {
22437
22485
  setCoreState(CoreState.REGISTERING);
22438
22486
  startRuntimeStateWriter({
22439
22487
  projectRoot: process.cwd(),
22440
- sdkVersion: "1.1.3"
22488
+ sdkVersion: "1.2.0"
22441
22489
  });
22442
22490
  const config2 = resolveConfig(options);
22443
22491
  if (config2.verbose) {
@@ -22603,8 +22651,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22603
22651
  if (config2.verbose) {
22604
22652
  console.info("[glasstrace] Background init firing.");
22605
22653
  }
22606
- const healthReport = collectHealthReport("1.1.3");
22607
- const initResult = await performInit(config2, anonKeyForInit, "1.1.3", healthReport);
22654
+ const healthReport = collectHealthReport("1.2.0");
22655
+ const initResult = await performInit(config2, anonKeyForInit, "1.2.0", healthReport);
22608
22656
  if (generation !== registrationGeneration) return;
22609
22657
  const currentState = getCoreState();
22610
22658
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -22627,7 +22675,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22627
22675
  }
22628
22676
  maybeInstallConsoleCapture();
22629
22677
  if (didLastInitSucceed()) {
22630
- startHeartbeat(config2, anonKeyForInit, "1.1.3", generation, (newApiKey, accountId) => {
22678
+ startHeartbeat(config2, anonKeyForInit, "1.2.0", generation, (newApiKey, accountId) => {
22631
22679
  setAuthState(AuthState.CLAIMING);
22632
22680
  emitLifecycleEvent("auth:claim_started", { accountId });
22633
22681
  setResolvedApiKey(newApiKey);