@glasstrace/sdk 0.13.1 → 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.d.cts CHANGED
@@ -361,6 +361,7 @@ interface GlasstraceExporterOptions {
361
361
  environment: string | undefined;
362
362
  endpointUrl: string;
363
363
  createDelegate: ((url: string, headers: Record<string, string>) => SpanExporter) | null;
364
+ /** @deprecated No-op retained for backward compatibility. Will be removed in a future major. */
364
365
  verbose?: boolean;
365
366
  }
366
367
  /**
@@ -382,7 +383,6 @@ declare class GlasstraceExporter implements SpanExporter {
382
383
  private readonly environment;
383
384
  private readonly endpointUrl;
384
385
  private readonly createDelegateFn;
385
- private readonly verbose;
386
386
  private delegate;
387
387
  private delegateKey;
388
388
  private pendingBatches;
package/dist/index.d.ts CHANGED
@@ -361,6 +361,7 @@ interface GlasstraceExporterOptions {
361
361
  environment: string | undefined;
362
362
  endpointUrl: string;
363
363
  createDelegate: ((url: string, headers: Record<string, string>) => SpanExporter) | null;
364
+ /** @deprecated No-op retained for backward compatibility. Will be removed in a future major. */
364
365
  verbose?: boolean;
365
366
  }
366
367
  /**
@@ -382,7 +383,6 @@ declare class GlasstraceExporter implements SpanExporter {
382
383
  private readonly environment;
383
384
  private readonly endpointUrl;
384
385
  private readonly createDelegateFn;
385
- private readonly verbose;
386
386
  private delegate;
387
387
  private delegateKey;
388
388
  private pendingBatches;
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  import {
34
34
  DiagLogLevel,
35
35
  INVALID_SPAN_CONTEXT,
36
+ ROOT_CONTEXT,
36
37
  SamplingDecision,
37
38
  SpanKind,
38
39
  SpanStatusCode,
@@ -577,7 +578,6 @@ var GlasstraceExporter = class {
577
578
  environment;
578
579
  endpointUrl;
579
580
  createDelegateFn;
580
- verbose;
581
581
  delegate = null;
582
582
  delegateKey = null;
583
583
  pendingBatches = [];
@@ -590,7 +590,6 @@ var GlasstraceExporter = class {
590
590
  this.environment = options.environment;
591
591
  this.endpointUrl = options.endpointUrl;
592
592
  this.createDelegateFn = options.createDelegate;
593
- this.verbose = options.verbose ?? false;
594
593
  }
595
594
  export(spans, resultCallback) {
596
595
  const currentKey = this.getApiKey();
@@ -598,15 +597,6 @@ var GlasstraceExporter = class {
598
597
  this.bufferSpans(spans, resultCallback);
599
598
  return;
600
599
  }
601
- if (this.verbose) {
602
- for (const span of spans) {
603
- const ctx = span.spanContext();
604
- sdkLog(
605
- "info",
606
- `[glasstrace:span-diag] name=${span.name} traceId=${ctx.traceId} spanId=${ctx.spanId} parentSpanId=${span.parentSpanId ?? "root"}`
607
- );
608
- }
609
- }
610
600
  const enrichedSpans = spans.map((span) => this.enrichSpan(span));
611
601
  const exporter = this.ensureDelegate();
612
602
  if (exporter) {
@@ -838,15 +828,6 @@ var GlasstraceExporter = class {
838
828
  this.pendingBatches = [];
839
829
  this.pendingSpanCount = 0;
840
830
  for (const batch of batches) {
841
- if (this.verbose) {
842
- for (const span of batch.spans) {
843
- const ctx = span.spanContext();
844
- sdkLog(
845
- "info",
846
- `[glasstrace:span-diag] name=${span.name} traceId=${ctx.traceId} spanId=${ctx.spanId} parentSpanId=${span.parentSpanId ?? "root"}`
847
- );
848
- }
849
- }
850
831
  const enriched = batch.spans.map((span) => this.enrichSpan(span));
851
832
  exporter.export(enriched, (result) => {
852
833
  if (result.code !== 0) {
@@ -3616,8 +3597,7 @@ async function configureOtel(config, sessionManager) {
3616
3597
  getConfig: () => getActiveConfig(),
3617
3598
  environment: config.environment,
3618
3599
  endpointUrl: exporterUrl,
3619
- createDelegate: createOtlpExporter,
3620
- verbose: config.verbose
3600
+ createDelegate: createOtlpExporter
3621
3601
  });
3622
3602
  _activeExporter = glasstraceExporter;
3623
3603
  const vercelOtel = await tryImport("@vercel/otel");
@@ -3667,6 +3647,30 @@ async function configureOtel(config, sessionManager) {
3667
3647
  registerShutdownHooks(provider);
3668
3648
  }
3669
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
+
3670
3674
  // src/heartbeat.ts
3671
3675
  var HEARTBEAT_INTERVAL_MS = 5 * 60 * 1e3;
3672
3676
  var BACKOFF_BASE_MS = HEARTBEAT_INTERVAL_MS;
@@ -3824,6 +3828,7 @@ function registerGlasstrace(options) {
3824
3828
  }
3825
3829
  isRegistered = true;
3826
3830
  const currentGeneration = registrationGeneration;
3831
+ installContextManager();
3827
3832
  void configureOtel(config, sessionManager).then(
3828
3833
  () => {
3829
3834
  maybeInstallConsoleCapture();
@@ -3923,8 +3928,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
3923
3928
  if (config.verbose) {
3924
3929
  console.info("[glasstrace] Background init firing.");
3925
3930
  }
3926
- const healthReport = collectHealthReport("0.13.1");
3927
- const initResult = await performInit(config, anonKeyForInit, "0.13.1", healthReport);
3931
+ const healthReport = collectHealthReport("0.13.3");
3932
+ const initResult = await performInit(config, anonKeyForInit, "0.13.3", healthReport);
3928
3933
  if (generation !== registrationGeneration) return;
3929
3934
  if (initResult?.claimResult) {
3930
3935
  setResolvedApiKey(initResult.claimResult.newApiKey);
@@ -3932,7 +3937,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
3932
3937
  }
3933
3938
  maybeInstallConsoleCapture();
3934
3939
  if (didLastInitSucceed()) {
3935
- startHeartbeat(config, anonKeyForInit, "0.13.1", generation, (newApiKey) => {
3940
+ startHeartbeat(config, anonKeyForInit, "0.13.3", generation, (newApiKey) => {
3936
3941
  setResolvedApiKey(newApiKey);
3937
3942
  notifyApiKeyResolved();
3938
3943
  });