@glasstrace/sdk 1.3.3 → 1.3.5

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
@@ -18866,7 +18866,7 @@ async function verifyAnonKeyRegistration(projectRoot) {
18866
18866
  }
18867
18867
  const baseConfig = resolveConfig({ apiKey: devKey });
18868
18868
  const config2 = { ...baseConfig, apiKey: devKey };
18869
- const sdkVersion = true ? "1.3.3" : "0.0.0-dev";
18869
+ const sdkVersion = true ? "1.3.5" : "0.0.0-dev";
18870
18870
  const result = await verifyInitReachable(config2, anonKey, sdkVersion);
18871
18871
  if (result.ok) {
18872
18872
  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.3.3" : "0.0.0-dev";
997
+ const sdkVersion = true ? "1.3.5" : "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
@@ -22036,9 +22036,11 @@ This message will not appear once Glasstrace is added to your provider config.`
22036
22036
  }
22037
22037
  function emitGuidanceMessage() {
22038
22038
  const isSentry = detectSentry();
22039
+ const isProduction = typeof process !== "undefined" && process.env?.NODE_ENV === "production";
22040
+ const level = isProduction ? "error" : "warn";
22039
22041
  if (isSentry) {
22040
22042
  sdkLog(
22041
- "warn",
22043
+ level,
22042
22044
  `[glasstrace] An existing OTel TracerProvider is registered but Glasstrace could not auto-attach its span processor.
22043
22045
  Add Glasstrace to your Sentry config:
22044
22046
 
@@ -22051,7 +22053,7 @@ Add Glasstrace to your Sentry config:
22051
22053
  );
22052
22054
  } else {
22053
22055
  sdkLog(
22054
- "warn",
22056
+ level,
22055
22057
  `[glasstrace] An existing OTel TracerProvider is registered but Glasstrace could not auto-attach its span processor.
22056
22058
  Add Glasstrace to your provider configuration:
22057
22059
 
@@ -22086,6 +22088,27 @@ function detectSentry() {
22086
22088
  }
22087
22089
  }
22088
22090
 
22091
+ // src/proxy-detection.ts
22092
+ function isProxyTracerProvider(value) {
22093
+ if (value === null || value === void 0 || typeof value !== "object") {
22094
+ return false;
22095
+ }
22096
+ return "getTracer" in value && typeof value.getTracer === "function" && "getDelegate" in value && typeof value.getDelegate === "function" && "setDelegate" in value && typeof value.setDelegate === "function" && "getDelegateTracer" in value && typeof value.getDelegateTracer === "function";
22097
+ }
22098
+ function isProxyTracer(value, ownerProvider) {
22099
+ if (value === null || value === void 0 || typeof value !== "object") {
22100
+ return false;
22101
+ }
22102
+ const structurallyShaped = "_getTracer" in value && typeof value._getTracer === "function" && "startSpan" in value && typeof value.startSpan === "function" && "startActiveSpan" in value && typeof value.startActiveSpan === "function";
22103
+ if (!structurallyShaped) {
22104
+ return false;
22105
+ }
22106
+ if (!Object.hasOwn(value, "_provider")) {
22107
+ return false;
22108
+ }
22109
+ return value._provider === ownerProvider;
22110
+ }
22111
+
22089
22112
  // src/otel-config.ts
22090
22113
  var resolvedApiKey = API_KEY_PENDING;
22091
22114
  var activeExporter = null;
@@ -22124,7 +22147,7 @@ async function configureOtel(config2, sessionManager) {
22124
22147
  });
22125
22148
  const existingProvider = trace.getTracerProvider();
22126
22149
  const probeTracer = existingProvider.getTracer("glasstrace-probe");
22127
- const anotherProviderRegistered = probeTracer.constructor.name !== "ProxyTracer";
22150
+ const anotherProviderRegistered = !isProxyTracerProvider(existingProvider) || !isProxyTracer(probeTracer, existingProvider);
22128
22151
  if (anotherProviderRegistered) {
22129
22152
  setCoexistenceState("coexisting");
22130
22153
  await runCoexistencePath(existingProvider, config2);
@@ -22178,11 +22201,27 @@ async function runCoexistencePath(existingProvider, config2) {
22178
22201
  setOtelState(OtelState.COEXISTENCE_FAILED);
22179
22202
  emitLifecycleEvent("otel:configured", { state: OtelState.COEXISTENCE_FAILED, scenario: "C/F" });
22180
22203
  emitLifecycleEvent("otel:injection_failed", { reason: "provider internals inaccessible" });
22204
+ emitLifecycleEvent("otel:failed", {
22205
+ category: "auto-attach-returned-null",
22206
+ message: "tryAutoAttachGlasstraceProcessor returned null \u2014 the existing OTel TracerProvider exposed no injection point. Spans are not reaching the Glasstrace exporter. Apply the manual createGlasstraceSpanProcessor() workaround documented in the SDK README.",
22207
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
22208
+ providerClass: readProviderClass(existingProvider)
22209
+ });
22181
22210
  const coreState = getCoreState();
22182
22211
  if (coreState === CoreState.ACTIVE || coreState === CoreState.KEY_RESOLVED) {
22183
22212
  setCoreState(CoreState.ACTIVE_DEGRADED);
22184
22213
  }
22185
22214
  }
22215
+ function readProviderClass(tracerProvider) {
22216
+ try {
22217
+ const proxy = tracerProvider;
22218
+ const delegate = typeof proxy.getDelegate === "function" ? proxy.getDelegate() : tracerProvider;
22219
+ const name = delegate?.constructor?.name;
22220
+ return typeof name === "string" && name.length > 0 ? name : void 0;
22221
+ } catch {
22222
+ return void 0;
22223
+ }
22224
+ }
22186
22225
  async function runRegistrationPath(config2, sessionManager) {
22187
22226
  const exporterUrl = `${config2.endpoint}/v1/traces`;
22188
22227
  const createOtlpExporter = (url2, headers) => new OTLPTraceExporter({ url: url2, headers });
@@ -22485,6 +22524,7 @@ init_console_capture();
22485
22524
  var _projectRoot = null;
22486
22525
  var _sdkVersion = "unknown";
22487
22526
  var _lastScenario;
22527
+ var _lastError;
22488
22528
  var _debounceTimer = null;
22489
22529
  var _started = false;
22490
22530
  function startRuntimeStateWriter(options) {
@@ -22507,6 +22547,10 @@ function startRuntimeStateWriter(options) {
22507
22547
  _lastScenario = scenario;
22508
22548
  debouncedWrite();
22509
22549
  });
22550
+ onLifecycleEvent("otel:failed", (payload) => {
22551
+ _lastError = { ...payload };
22552
+ debouncedWrite();
22553
+ });
22510
22554
  onLifecycleEvent("auth:key_resolved", () => debouncedWrite());
22511
22555
  onLifecycleEvent("auth:claim_started", () => debouncedWrite());
22512
22556
  onLifecycleEvent("auth:claim_completed", () => debouncedWrite());
@@ -22534,6 +22578,9 @@ function writeStateNow() {
22534
22578
  auth: { state: state.auth },
22535
22579
  otel: { state: state.otel, scenario: _lastScenario }
22536
22580
  };
22581
+ if (_lastError) {
22582
+ runtimeState.lastError = _lastError;
22583
+ }
22537
22584
  const dir = (0, import_node_path.join)(_projectRoot, ".glasstrace");
22538
22585
  const filePath = (0, import_node_path.join)(dir, "runtime-state.json");
22539
22586
  (0, import_node_fs.mkdirSync)(dir, { recursive: true, mode: 448 });
@@ -22578,7 +22625,7 @@ function registerGlasstrace(options) {
22578
22625
  setCoreState(CoreState.REGISTERING);
22579
22626
  startRuntimeStateWriter({
22580
22627
  projectRoot: process.cwd(),
22581
- sdkVersion: "1.3.3"
22628
+ sdkVersion: "1.3.5"
22582
22629
  });
22583
22630
  const config2 = resolveConfig(options);
22584
22631
  if (config2.verbose) {
@@ -22594,8 +22641,9 @@ function registerGlasstrace(options) {
22594
22641
  if (config2.verbose) {
22595
22642
  console.info("[glasstrace] Not production-disabled.");
22596
22643
  }
22597
- const existingProbe = trace.getTracerProvider().getTracer("glasstrace-probe");
22598
- const anotherProviderRegistered = existingProbe.constructor.name !== "ProxyTracer";
22644
+ const existingTracerProvider = trace.getTracerProvider();
22645
+ const existingProbe = existingTracerProvider.getTracer("glasstrace-probe");
22646
+ const anotherProviderRegistered = !isProxyTracerProvider(existingTracerProvider) || !isProxyTracer(existingProbe, existingTracerProvider);
22599
22647
  if (anotherProviderRegistered) {
22600
22648
  setCoexistenceState("coexisting");
22601
22649
  }
@@ -22744,8 +22792,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22744
22792
  if (config2.verbose) {
22745
22793
  console.info("[glasstrace] Background init firing.");
22746
22794
  }
22747
- const healthReport = collectHealthReport("1.3.3");
22748
- const initResult = await performInit(config2, anonKeyForInit, "1.3.3", healthReport);
22795
+ const healthReport = collectHealthReport("1.3.5");
22796
+ const initResult = await performInit(config2, anonKeyForInit, "1.3.5", healthReport);
22749
22797
  if (generation !== registrationGeneration) return;
22750
22798
  const currentState = getCoreState();
22751
22799
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -22768,7 +22816,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22768
22816
  }
22769
22817
  maybeInstallConsoleCapture();
22770
22818
  if (didLastInitSucceed()) {
22771
- startHeartbeat(config2, anonKeyForInit, "1.3.3", generation, (newApiKey, accountId) => {
22819
+ startHeartbeat(config2, anonKeyForInit, "1.3.5", generation, (newApiKey, accountId) => {
22772
22820
  setAuthState(AuthState.CLAIMING);
22773
22821
  emitLifecycleEvent("auth:claim_started", { accountId });
22774
22822
  setResolvedApiKey(newApiKey);