@glasstrace/sdk 0.17.2 → 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.
package/dist/index.js CHANGED
@@ -3283,6 +3283,17 @@ var BasicTracerProvider = class {
3283
3283
 
3284
3284
  // src/lifecycle.ts
3285
3285
  import { EventEmitter } from "node:events";
3286
+
3287
+ // src/signal-handler.ts
3288
+ var coexistenceState = "unknown";
3289
+ function setCoexistenceState(s) {
3290
+ coexistenceState = s;
3291
+ }
3292
+ function getCoexistenceState() {
3293
+ return coexistenceState;
3294
+ }
3295
+
3296
+ // src/lifecycle.ts
3286
3297
  var CoreState = {
3287
3298
  IDLE: "IDLE",
3288
3299
  REGISTERING: "REGISTERING",
@@ -3602,13 +3613,19 @@ function registerSignalHandlers() {
3602
3613
  if (_signalHandlersRegistered) return;
3603
3614
  if (typeof process === "undefined" || typeof process.once !== "function") return;
3604
3615
  _signalHandlersRegistered = true;
3616
+ const otherSigtermListeners = process.listenerCount("SIGTERM");
3617
+ const otherSigintListeners = process.listenerCount("SIGINT");
3605
3618
  const handler = (signal) => {
3606
3619
  void executeShutdown().finally(() => {
3607
3620
  if (_signalHandler) {
3608
3621
  process.removeListener("SIGTERM", _signalHandler);
3609
3622
  process.removeListener("SIGINT", _signalHandler);
3610
3623
  }
3611
- process.kill(process.pid, signal);
3624
+ const otherListeners = signal === "SIGTERM" ? otherSigtermListeners : otherSigintListeners;
3625
+ const otherProviderOwnsSignal = getCoexistenceState() === "coexisting" && otherListeners > 0;
3626
+ if (!otherProviderOwnsSignal) {
3627
+ process.kill(process.pid, signal);
3628
+ }
3612
3629
  });
3613
3630
  };
3614
3631
  _signalHandler = handler;
@@ -3824,9 +3841,11 @@ async function configureOtel(config, sessionManager) {
3824
3841
  const probeTracer = existingProvider.getTracer("glasstrace-probe");
3825
3842
  const anotherProviderRegistered = probeTracer.constructor.name !== "ProxyTracer";
3826
3843
  if (anotherProviderRegistered) {
3844
+ setCoexistenceState("coexisting");
3827
3845
  await runCoexistencePath(existingProvider, config);
3828
3846
  return;
3829
3847
  }
3848
+ setCoexistenceState("sole-owner");
3830
3849
  await runRegistrationPath(config, sessionManager);
3831
3850
  }
3832
3851
  async function runCoexistencePath(existingProvider, config) {
@@ -3906,6 +3925,19 @@ async function runRegistrationPath(config, sessionManager) {
3906
3925
  }
3907
3926
  }
3908
3927
  vercelOtel.registerOTel(otelConfig);
3928
+ const vercelProxy = trace.getTracerProvider();
3929
+ const vercelConcreteProvider = typeof vercelProxy.getDelegate === "function" ? vercelProxy.getDelegate() : vercelProxy;
3930
+ registerShutdownHook({
3931
+ name: "vercel-otel-shutdown",
3932
+ priority: 0,
3933
+ fn: async () => {
3934
+ try {
3935
+ await vercelConcreteProvider.shutdown?.();
3936
+ } catch {
3937
+ }
3938
+ }
3939
+ });
3940
+ registerBeforeExitTrigger();
3909
3941
  setOtelState(OtelState.OWNS_PROVIDER);
3910
3942
  emitLifecycleEvent("otel:configured", { state: OtelState.OWNS_PROVIDER, scenario: "E" });
3911
3943
  return;
@@ -4204,7 +4236,7 @@ function registerGlasstrace(options) {
4204
4236
  setCoreState(CoreState.REGISTERING);
4205
4237
  startRuntimeStateWriter({
4206
4238
  projectRoot: process.cwd(),
4207
- sdkVersion: "0.17.2"
4239
+ sdkVersion: "0.17.3"
4208
4240
  });
4209
4241
  const config = resolveConfig(options);
4210
4242
  if (config.verbose) {
@@ -4222,9 +4254,10 @@ function registerGlasstrace(options) {
4222
4254
  }
4223
4255
  const existingProbe = trace.getTracerProvider().getTracer("glasstrace-probe");
4224
4256
  const anotherProviderRegistered = existingProbe.constructor.name !== "ProxyTracer";
4225
- if (!anotherProviderRegistered) {
4226
- registerSignalHandlers();
4257
+ if (anotherProviderRegistered) {
4258
+ setCoexistenceState("coexisting");
4227
4259
  }
4260
+ registerSignalHandlers();
4228
4261
  const anonymous = isAnonymousMode(config);
4229
4262
  let effectiveKey = config.apiKey;
4230
4263
  initAuthState(anonymous ? AuthState.ANONYMOUS : AuthState.AUTHENTICATED);
@@ -4369,8 +4402,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4369
4402
  if (config.verbose) {
4370
4403
  console.info("[glasstrace] Background init firing.");
4371
4404
  }
4372
- const healthReport = collectHealthReport("0.17.2");
4373
- const initResult = await performInit(config, anonKeyForInit, "0.17.2", healthReport);
4405
+ const healthReport = collectHealthReport("0.17.3");
4406
+ const initResult = await performInit(config, anonKeyForInit, "0.17.3", healthReport);
4374
4407
  if (generation !== registrationGeneration) return;
4375
4408
  const currentState = getCoreState();
4376
4409
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -4393,7 +4426,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4393
4426
  }
4394
4427
  maybeInstallConsoleCapture();
4395
4428
  if (didLastInitSucceed()) {
4396
- startHeartbeat(config, anonKeyForInit, "0.17.2", generation, (newApiKey, accountId) => {
4429
+ startHeartbeat(config, anonKeyForInit, "0.17.3", generation, (newApiKey, accountId) => {
4397
4430
  setAuthState(AuthState.CLAIMING);
4398
4431
  emitLifecycleEvent("auth:claim_started", { accountId });
4399
4432
  setResolvedApiKey(newApiKey);