@glasstrace/sdk 0.17.1 → 0.17.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.
@@ -5,7 +5,7 @@ import {
5
5
  injectInfoSection,
6
6
  updateGitignore,
7
7
  writeMcpConfig
8
- } from "../chunk-CTJI2YKA.js";
8
+ } from "../chunk-HAU66QBQ.js";
9
9
  import {
10
10
  readAnonKey
11
11
  } from "../chunk-J5BW7V2D.js";
package/dist/index.cjs CHANGED
@@ -17507,6 +17507,7 @@ async function performInit(config2, anonKey, sdkVersion, healthReport) {
17507
17507
  rateLimitBackoff = false;
17508
17508
  return null;
17509
17509
  }
17510
+ let failureRecorded = false;
17510
17511
  try {
17511
17512
  const effectiveKey = config2.apiKey || anonKey;
17512
17513
  if (!effectiveKey) {
@@ -17539,6 +17540,7 @@ async function performInit(config2, anonKey, sdkVersion, healthReport) {
17539
17540
  return null;
17540
17541
  } catch (err) {
17541
17542
  recordInitFailure();
17543
+ failureRecorded = true;
17542
17544
  if (err instanceof HttpsTransportError) {
17543
17545
  if (/timed out|aborted/i.test(err.message)) {
17544
17546
  console.warn("[glasstrace] ingestion_unreachable: Init request timed out.");
@@ -17577,9 +17579,15 @@ async function performInit(config2, anonKey, sdkVersion, healthReport) {
17577
17579
  return null;
17578
17580
  }
17579
17581
  } catch (err) {
17580
- console.warn(
17581
- `[glasstrace] Unexpected init error: ${err instanceof Error ? err.message : String(err)}`
17582
- );
17582
+ if (!failureRecorded) {
17583
+ recordInitFailure();
17584
+ }
17585
+ try {
17586
+ console.warn(
17587
+ `[glasstrace] Unexpected init error: ${err instanceof Error ? err.message : String(err)}`
17588
+ );
17589
+ } catch {
17590
+ }
17583
17591
  }
17584
17592
  return null;
17585
17593
  }
@@ -20751,6 +20759,17 @@ init_console_capture();
20751
20759
 
20752
20760
  // src/lifecycle.ts
20753
20761
  var import_node_events = require("node:events");
20762
+
20763
+ // src/signal-handler.ts
20764
+ var coexistenceState = "unknown";
20765
+ function setCoexistenceState(s) {
20766
+ coexistenceState = s;
20767
+ }
20768
+ function getCoexistenceState() {
20769
+ return coexistenceState;
20770
+ }
20771
+
20772
+ // src/lifecycle.ts
20754
20773
  var CoreState = {
20755
20774
  IDLE: "IDLE",
20756
20775
  REGISTERING: "REGISTERING",
@@ -21070,13 +21089,19 @@ function registerSignalHandlers() {
21070
21089
  if (_signalHandlersRegistered) return;
21071
21090
  if (typeof process === "undefined" || typeof process.once !== "function") return;
21072
21091
  _signalHandlersRegistered = true;
21092
+ const otherSigtermListeners = process.listenerCount("SIGTERM");
21093
+ const otherSigintListeners = process.listenerCount("SIGINT");
21073
21094
  const handler = (signal) => {
21074
21095
  void executeShutdown().finally(() => {
21075
21096
  if (_signalHandler) {
21076
21097
  process.removeListener("SIGTERM", _signalHandler);
21077
21098
  process.removeListener("SIGINT", _signalHandler);
21078
21099
  }
21079
- process.kill(process.pid, signal);
21100
+ const otherListeners = signal === "SIGTERM" ? otherSigtermListeners : otherSigintListeners;
21101
+ const otherProviderOwnsSignal = getCoexistenceState() === "coexisting" && otherListeners > 0;
21102
+ if (!otherProviderOwnsSignal) {
21103
+ process.kill(process.pid, signal);
21104
+ }
21080
21105
  });
21081
21106
  };
21082
21107
  _signalHandler = handler;
@@ -21294,9 +21319,11 @@ async function configureOtel(config2, sessionManager) {
21294
21319
  const probeTracer = existingProvider.getTracer("glasstrace-probe");
21295
21320
  const anotherProviderRegistered = probeTracer.constructor.name !== "ProxyTracer";
21296
21321
  if (anotherProviderRegistered) {
21322
+ setCoexistenceState("coexisting");
21297
21323
  await runCoexistencePath(existingProvider, config2);
21298
21324
  return;
21299
21325
  }
21326
+ setCoexistenceState("sole-owner");
21300
21327
  await runRegistrationPath(config2, sessionManager);
21301
21328
  }
21302
21329
  async function runCoexistencePath(existingProvider, config2) {
@@ -21376,6 +21403,19 @@ async function runRegistrationPath(config2, sessionManager) {
21376
21403
  }
21377
21404
  }
21378
21405
  vercelOtel.registerOTel(otelConfig);
21406
+ const vercelProxy = trace.getTracerProvider();
21407
+ const vercelConcreteProvider = typeof vercelProxy.getDelegate === "function" ? vercelProxy.getDelegate() : vercelProxy;
21408
+ registerShutdownHook({
21409
+ name: "vercel-otel-shutdown",
21410
+ priority: 0,
21411
+ fn: async () => {
21412
+ try {
21413
+ await vercelConcreteProvider.shutdown?.();
21414
+ } catch {
21415
+ }
21416
+ }
21417
+ });
21418
+ registerBeforeExitTrigger();
21379
21419
  setOtelState(OtelState.OWNS_PROVIDER);
21380
21420
  emitLifecycleEvent("otel:configured", { state: OtelState.OWNS_PROVIDER, scenario: "E" });
21381
21421
  return;
@@ -21681,7 +21721,7 @@ function registerGlasstrace(options) {
21681
21721
  setCoreState(CoreState.REGISTERING);
21682
21722
  startRuntimeStateWriter({
21683
21723
  projectRoot: process.cwd(),
21684
- sdkVersion: "0.17.1"
21724
+ sdkVersion: "0.17.3"
21685
21725
  });
21686
21726
  const config2 = resolveConfig(options);
21687
21727
  if (config2.verbose) {
@@ -21699,9 +21739,10 @@ function registerGlasstrace(options) {
21699
21739
  }
21700
21740
  const existingProbe = trace.getTracerProvider().getTracer("glasstrace-probe");
21701
21741
  const anotherProviderRegistered = existingProbe.constructor.name !== "ProxyTracer";
21702
- if (!anotherProviderRegistered) {
21703
- registerSignalHandlers();
21742
+ if (anotherProviderRegistered) {
21743
+ setCoexistenceState("coexisting");
21704
21744
  }
21745
+ registerSignalHandlers();
21705
21746
  const anonymous = isAnonymousMode(config2);
21706
21747
  let effectiveKey = config2.apiKey;
21707
21748
  initAuthState(anonymous ? AuthState.ANONYMOUS : AuthState.AUTHENTICATED);
@@ -21846,8 +21887,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
21846
21887
  if (config2.verbose) {
21847
21888
  console.info("[glasstrace] Background init firing.");
21848
21889
  }
21849
- const healthReport = collectHealthReport("0.17.1");
21850
- const initResult = await performInit(config2, anonKeyForInit, "0.17.1", healthReport);
21890
+ const healthReport = collectHealthReport("0.17.3");
21891
+ const initResult = await performInit(config2, anonKeyForInit, "0.17.3", healthReport);
21851
21892
  if (generation !== registrationGeneration) return;
21852
21893
  const currentState = getCoreState();
21853
21894
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -21870,7 +21911,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
21870
21911
  }
21871
21912
  maybeInstallConsoleCapture();
21872
21913
  if (didLastInitSucceed()) {
21873
- startHeartbeat(config2, anonKeyForInit, "0.17.1", generation, (newApiKey, accountId) => {
21914
+ startHeartbeat(config2, anonKeyForInit, "0.17.3", generation, (newApiKey, accountId) => {
21874
21915
  setAuthState(AuthState.CLAIMING);
21875
21916
  emitLifecycleEvent("auth:claim_started", { accountId });
21876
21917
  setResolvedApiKey(newApiKey);