@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/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  registerGlasstrace,
13
13
  waitForReady,
14
14
  withGlasstraceConfig
15
- } from "./chunk-FGDS33I2.js";
15
+ } from "./chunk-6RIH6SFM.js";
16
16
  import {
17
17
  GlasstraceSpanProcessor,
18
18
  SdkError,
@@ -22260,8 +22260,51 @@ async function runRegistrationPath(config2, sessionManager) {
22260
22260
  // src/context-manager.ts
22261
22261
  var import_node_async_hooks = require("node:async_hooks");
22262
22262
  init_esm();
22263
+ var GLASSTRACE_BRAND = 1;
22264
+ var GUARD = /* @__PURE__ */ Symbol.for("glasstrace.context-manager.installed");
22265
+ var OTEL_API_KEY = /* @__PURE__ */ Symbol.for("opentelemetry.js.api.1");
22266
+ function isOtelContextManager(value) {
22267
+ if (typeof value !== "object" || value === null) return false;
22268
+ const candidate = value;
22269
+ return typeof candidate.active === "function" && typeof candidate.with === "function" && typeof candidate.bind === "function" && typeof candidate.enable === "function" && typeof candidate.disable === "function";
22270
+ }
22271
+ function isInstallationRecord(value) {
22272
+ if (typeof value !== "object" || value === null) return false;
22273
+ const candidate = value;
22274
+ if (candidate.glasstraceContextManagerBrand !== GLASSTRACE_BRAND) return false;
22275
+ return candidate.manager === null || isOtelContextManager(candidate.manager);
22276
+ }
22277
+ function getOtelRegisteredContextManager() {
22278
+ const otelSlot = globalThis[OTEL_API_KEY];
22279
+ if (typeof otelSlot !== "object" || otelSlot === null) return void 0;
22280
+ const ctx = otelSlot.context;
22281
+ return isOtelContextManager(ctx) ? ctx : void 0;
22282
+ }
22263
22283
  function installContextManager() {
22264
22284
  try {
22285
+ const slot = globalThis;
22286
+ const existing = slot[GUARD];
22287
+ const otelCurrent = getOtelRegisteredContextManager();
22288
+ if (isInstallationRecord(existing) && existing.manager !== null && existing.manager === otelCurrent) {
22289
+ return true;
22290
+ }
22291
+ if (isInstallationRecord(existing) && existing.manager === null && otelCurrent !== void 0) {
22292
+ return false;
22293
+ }
22294
+ if (isInstallationRecord(existing) && existing.manager !== null) {
22295
+ const reSuccess = context.setGlobalContextManager(existing.manager);
22296
+ if (!reSuccess) {
22297
+ console.warn(
22298
+ "[glasstrace] Another context manager is already registered. Trace context propagation may not work as expected."
22299
+ );
22300
+ }
22301
+ const reRecord = {
22302
+ glasstraceContextManagerBrand: GLASSTRACE_BRAND,
22303
+ manager: reSuccess ? existing.manager : null
22304
+ };
22305
+ slot[GUARD] = reRecord;
22306
+ return reSuccess;
22307
+ }
22265
22308
  const als = new import_node_async_hooks.AsyncLocalStorage();
22266
22309
  const contextManager = {
22267
22310
  active: () => als.getStore() ?? ROOT_CONTEXT,
@@ -22282,6 +22325,11 @@ function installContextManager() {
22282
22325
  "[glasstrace] Another context manager is already registered. Trace context propagation may not work as expected."
22283
22326
  );
22284
22327
  }
22328
+ const record2 = {
22329
+ glasstraceContextManagerBrand: GLASSTRACE_BRAND,
22330
+ manager: success2 ? contextManager : null
22331
+ };
22332
+ slot[GUARD] = record2;
22285
22333
  return success2;
22286
22334
  } catch {
22287
22335
  return false;
@@ -22513,7 +22561,7 @@ function registerGlasstrace(options) {
22513
22561
  setCoreState(CoreState.REGISTERING);
22514
22562
  startRuntimeStateWriter({
22515
22563
  projectRoot: process.cwd(),
22516
- sdkVersion: "1.1.3"
22564
+ sdkVersion: "1.2.0"
22517
22565
  });
22518
22566
  const config2 = resolveConfig(options);
22519
22567
  if (config2.verbose) {
@@ -22679,8 +22727,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22679
22727
  if (config2.verbose) {
22680
22728
  console.info("[glasstrace] Background init firing.");
22681
22729
  }
22682
- const healthReport = collectHealthReport("1.1.3");
22683
- const initResult = await performInit(config2, anonKeyForInit, "1.1.3", healthReport);
22730
+ const healthReport = collectHealthReport("1.2.0");
22731
+ const initResult = await performInit(config2, anonKeyForInit, "1.2.0", healthReport);
22684
22732
  if (generation !== registrationGeneration) return;
22685
22733
  const currentState = getCoreState();
22686
22734
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -22703,7 +22751,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22703
22751
  }
22704
22752
  maybeInstallConsoleCapture();
22705
22753
  if (didLastInitSucceed()) {
22706
- startHeartbeat(config2, anonKeyForInit, "1.1.3", generation, (newApiKey, accountId) => {
22754
+ startHeartbeat(config2, anonKeyForInit, "1.2.0", generation, (newApiKey, accountId) => {
22707
22755
  setAuthState(AuthState.CLAIMING);
22708
22756
  emitLifecycleEvent("auth:claim_started", { accountId });
22709
22757
  setResolvedApiKey(newApiKey);