@glasstrace/sdk 1.3.4 → 1.3.6

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/README.md CHANGED
@@ -165,6 +165,12 @@ The nudge never fires in production (detected via `NODE_ENV` or
165
165
 
166
166
  ## Production deployment under Next 16
167
167
 
168
+ As of `@glasstrace/sdk@1.3.5`, auto-attach detection now classifies the
169
+ SDK's own bundled proxy correctly under bundler minification (DISC-1556
170
+ — verified against the `clean-next-sdk130` validation fixture). The
171
+ manual integration documented below remains supported for users who
172
+ prefer explicit configuration.
173
+
168
174
  Next 16 (`next build && next start`) registers an OpenTelemetry
169
175
  TracerProvider before user code runs. When `registerGlasstrace()` then
170
176
  detects that provider, the SDK attempts to attach its span processor to
@@ -3671,6 +3671,27 @@ var OTLPTraceExporter = class extends OTLPExporterBase {
3671
3671
  }
3672
3672
  };
3673
3673
 
3674
+ // src/proxy-detection.ts
3675
+ function isProxyTracerProvider(value) {
3676
+ if (value === null || value === void 0 || typeof value !== "object") {
3677
+ return false;
3678
+ }
3679
+ 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";
3680
+ }
3681
+ function isProxyTracer(value, ownerProvider) {
3682
+ if (value === null || value === void 0 || typeof value !== "object") {
3683
+ return false;
3684
+ }
3685
+ const structurallyShaped = "_getTracer" in value && typeof value._getTracer === "function" && "startSpan" in value && typeof value.startSpan === "function" && "startActiveSpan" in value && typeof value.startActiveSpan === "function";
3686
+ if (!structurallyShaped) {
3687
+ return false;
3688
+ }
3689
+ if (!Object.hasOwn(value, "_provider")) {
3690
+ return false;
3691
+ }
3692
+ return value._provider === ownerProvider;
3693
+ }
3694
+
3674
3695
  // src/otel-config.ts
3675
3696
  var resolvedApiKey = API_KEY_PENDING;
3676
3697
  var activeExporter = null;
@@ -3709,7 +3730,7 @@ async function configureOtel(config, sessionManager) {
3709
3730
  });
3710
3731
  const existingProvider = trace.getTracerProvider();
3711
3732
  const probeTracer = existingProvider.getTracer("glasstrace-probe");
3712
- const anotherProviderRegistered = probeTracer.constructor.name !== "ProxyTracer";
3733
+ const anotherProviderRegistered = !isProxyTracerProvider(existingProvider) || !isProxyTracer(probeTracer, existingProvider);
3713
3734
  if (anotherProviderRegistered) {
3714
3735
  setCoexistenceState("coexisting");
3715
3736
  await runCoexistencePath(existingProvider, config);
@@ -4071,19 +4092,19 @@ function stopHeartbeat() {
4071
4092
  }
4072
4093
  }
4073
4094
  function checkShutdownMarker(projectRoot) {
4074
- let fsSync = null;
4075
- let pathSync = null;
4095
+ let fsSync2 = null;
4096
+ let pathSync2 = null;
4076
4097
  try {
4077
- fsSync = __require("node:fs");
4078
- pathSync = __require("node:path");
4098
+ fsSync2 = __require("node:fs");
4099
+ pathSync2 = __require("node:path");
4079
4100
  } catch {
4080
4101
  return { triggered: false };
4081
4102
  }
4082
4103
  const root = projectRoot ?? (typeof process !== "undefined" ? process.cwd() : ".");
4083
- const markerPath = pathSync.join(root, SHUTDOWN_MARKER_RELPATH);
4084
- if (!fsSync.existsSync(markerPath)) return { triggered: false };
4104
+ const markerPath = pathSync2.join(root, SHUTDOWN_MARKER_RELPATH);
4105
+ if (!fsSync2.existsSync(markerPath)) return { triggered: false };
4085
4106
  try {
4086
- fsSync.unlinkSync(markerPath);
4107
+ fsSync2.unlinkSync(markerPath);
4087
4108
  } catch {
4088
4109
  }
4089
4110
  const shutdown = executeShutdown().catch(() => {
@@ -4163,8 +4184,15 @@ function registerHeartbeatShutdownHook(config, anonKey, sdkVersion) {
4163
4184
  }
4164
4185
 
4165
4186
  // src/runtime-state.ts
4166
- import { mkdirSync } from "node:fs";
4167
- import { join } from "node:path";
4187
+ var fsSync = null;
4188
+ var pathSync = null;
4189
+ try {
4190
+ fsSync = __require("node:fs");
4191
+ pathSync = __require("node:path");
4192
+ } catch {
4193
+ fsSync = null;
4194
+ pathSync = null;
4195
+ }
4168
4196
  var _projectRoot = null;
4169
4197
  var _sdkVersion = "unknown";
4170
4198
  var _lastScenario;
@@ -4173,7 +4201,7 @@ var _debounceTimer = null;
4173
4201
  var _started = false;
4174
4202
  function startRuntimeStateWriter(options) {
4175
4203
  if (_started) return;
4176
- if (!isSyncFsAvailable()) {
4204
+ if (!isSyncFsAvailable() || fsSync === null || pathSync === null) {
4177
4205
  _started = true;
4178
4206
  return;
4179
4207
  }
@@ -4225,9 +4253,9 @@ function writeStateNow() {
4225
4253
  if (_lastError) {
4226
4254
  runtimeState.lastError = _lastError;
4227
4255
  }
4228
- const dir = join(_projectRoot, ".glasstrace");
4229
- const filePath = join(dir, "runtime-state.json");
4230
- mkdirSync(dir, { recursive: true, mode: 448 });
4256
+ const dir = pathSync.join(_projectRoot, ".glasstrace");
4257
+ const filePath = pathSync.join(dir, "runtime-state.json");
4258
+ fsSync.mkdirSync(dir, { recursive: true, mode: 448 });
4231
4259
  atomicWriteFileSync(filePath, JSON.stringify(runtimeState, null, 2) + "\n", {
4232
4260
  mode: 384
4233
4261
  });
@@ -4269,7 +4297,7 @@ function registerGlasstrace(options) {
4269
4297
  setCoreState(CoreState.REGISTERING);
4270
4298
  startRuntimeStateWriter({
4271
4299
  projectRoot: process.cwd(),
4272
- sdkVersion: "1.3.4"
4300
+ sdkVersion: "1.3.6"
4273
4301
  });
4274
4302
  const config = resolveConfig(options);
4275
4303
  if (config.verbose) {
@@ -4285,8 +4313,9 @@ function registerGlasstrace(options) {
4285
4313
  if (config.verbose) {
4286
4314
  console.info("[glasstrace] Not production-disabled.");
4287
4315
  }
4288
- const existingProbe = trace.getTracerProvider().getTracer("glasstrace-probe");
4289
- const anotherProviderRegistered = existingProbe.constructor.name !== "ProxyTracer";
4316
+ const existingTracerProvider = trace.getTracerProvider();
4317
+ const existingProbe = existingTracerProvider.getTracer("glasstrace-probe");
4318
+ const anotherProviderRegistered = !isProxyTracerProvider(existingTracerProvider) || !isProxyTracer(existingProbe, existingTracerProvider);
4290
4319
  if (anotherProviderRegistered) {
4291
4320
  setCoexistenceState("coexisting");
4292
4321
  }
@@ -4435,8 +4464,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4435
4464
  if (config.verbose) {
4436
4465
  console.info("[glasstrace] Background init firing.");
4437
4466
  }
4438
- const healthReport = collectHealthReport("1.3.4");
4439
- const initResult = await performInit(config, anonKeyForInit, "1.3.4", healthReport);
4467
+ const healthReport = collectHealthReport("1.3.6");
4468
+ const initResult = await performInit(config, anonKeyForInit, "1.3.6", healthReport);
4440
4469
  if (generation !== registrationGeneration) return;
4441
4470
  const currentState = getCoreState();
4442
4471
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -4459,7 +4488,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4459
4488
  }
4460
4489
  maybeInstallConsoleCapture();
4461
4490
  if (didLastInitSucceed()) {
4462
- startHeartbeat(config, anonKeyForInit, "1.3.4", generation, (newApiKey, accountId) => {
4491
+ startHeartbeat(config, anonKeyForInit, "1.3.6", generation, (newApiKey, accountId) => {
4463
4492
  setAuthState(AuthState.CLAIMING);
4464
4493
  emitLifecycleEvent("auth:claim_started", { accountId });
4465
4494
  setResolvedApiKey(newApiKey);
@@ -4859,4 +4888,4 @@ export {
4859
4888
  withGlasstraceConfig,
4860
4889
  captureError
4861
4890
  };
4862
- //# sourceMappingURL=chunk-XFNK4YEW.js.map
4891
+ //# sourceMappingURL=chunk-IY6A6EXS.js.map