@glasstrace/sdk 1.2.1 → 1.3.0

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.
Files changed (40) hide show
  1. package/README.md +47 -0
  2. package/dist/{chunk-HV5ID2WJ.js → chunk-A63WX7NR.js} +3 -3
  3. package/dist/{chunk-2GCN27SI.js → chunk-AGCYKZFY.js} +2 -2
  4. package/dist/{chunk-47B2G3FE.js → chunk-AKZGMT33.js} +2 -2
  5. package/dist/{chunk-MD5XPCTQ.js → chunk-AYUL5QMZ.js} +2 -2
  6. package/dist/{chunk-YMLMZCPR.js → chunk-FMEWG3FY.js} +2 -2
  7. package/dist/{chunk-NFPDYME5.js → chunk-FVHVDBGX.js} +3 -3
  8. package/dist/{chunk-EBYISKQP.js → chunk-GTPTKN5A.js} +2 -1
  9. package/dist/{chunk-EBYISKQP.js.map → chunk-GTPTKN5A.js.map} +1 -1
  10. package/dist/{chunk-CTJO7PUZ.js → chunk-JMYKR5Z3.js} +75 -9
  11. package/dist/chunk-JMYKR5Z3.js.map +1 -0
  12. package/dist/cli/init.cjs +1 -1
  13. package/dist/cli/init.cjs.map +1 -1
  14. package/dist/cli/init.js +6 -6
  15. package/dist/cli/mcp-add.cjs.map +1 -1
  16. package/dist/cli/mcp-add.js +2 -2
  17. package/dist/cli/uninit.js +3 -3
  18. package/dist/cli/validate.cjs.map +1 -1
  19. package/dist/cli/validate.js +2 -2
  20. package/dist/edge-entry.cjs +1 -0
  21. package/dist/edge-entry.cjs.map +1 -1
  22. package/dist/edge-entry.js +2 -2
  23. package/dist/index.cjs +74 -4
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.js +5 -5
  26. package/dist/node-entry.cjs +74 -4
  27. package/dist/node-entry.cjs.map +1 -1
  28. package/dist/node-entry.js +7 -7
  29. package/dist/node-subpath.cjs.map +1 -1
  30. package/dist/node-subpath.js +3 -3
  31. package/dist/{source-map-uploader-RA4Z7TWA.js → source-map-uploader-M2P5CDOB.js} +3 -3
  32. package/package.json +1 -1
  33. package/dist/chunk-CTJO7PUZ.js.map +0 -1
  34. /package/dist/{chunk-HV5ID2WJ.js.map → chunk-A63WX7NR.js.map} +0 -0
  35. /package/dist/{chunk-2GCN27SI.js.map → chunk-AGCYKZFY.js.map} +0 -0
  36. /package/dist/{chunk-47B2G3FE.js.map → chunk-AKZGMT33.js.map} +0 -0
  37. /package/dist/{chunk-MD5XPCTQ.js.map → chunk-AYUL5QMZ.js.map} +0 -0
  38. /package/dist/{chunk-YMLMZCPR.js.map → chunk-FMEWG3FY.js.map} +0 -0
  39. /package/dist/{chunk-NFPDYME5.js.map → chunk-FVHVDBGX.js.map} +0 -0
  40. /package/dist/{source-map-uploader-RA4Z7TWA.js.map → source-map-uploader-M2P5CDOB.js.map} +0 -0
@@ -33,7 +33,7 @@ import {
33
33
  performInit,
34
34
  recordSpansDropped,
35
35
  recordSpansExported
36
- } from "./chunk-HV5ID2WJ.js";
36
+ } from "./chunk-A63WX7NR.js";
37
37
  import {
38
38
  isAnonymousMode,
39
39
  isProductionDisabled,
@@ -43,11 +43,11 @@ import {
43
43
  atomicWriteFileSync,
44
44
  getOrCreateAnonKey,
45
45
  readAnonKey
46
- } from "./chunk-MD5XPCTQ.js";
46
+ } from "./chunk-AYUL5QMZ.js";
47
47
  import {
48
48
  GLASSTRACE_ATTRIBUTE_NAMES,
49
49
  deriveSessionId
50
- } from "./chunk-EBYISKQP.js";
50
+ } from "./chunk-GTPTKN5A.js";
51
51
  import {
52
52
  __require
53
53
  } from "./chunk-NSBPE2FW.js";
@@ -264,6 +264,19 @@ function prepareErrorResponseBody(body) {
264
264
  return truncateErrorResponseBody(sanitized);
265
265
  }
266
266
 
267
+ // src/build-info.ts
268
+ var UNSET = "";
269
+ function readBuildHashFromEnv() {
270
+ const raw = process.env.GLASSTRACE_BUILD_HASH;
271
+ if (typeof raw !== "string") return UNSET;
272
+ const trimmed = raw.trim();
273
+ return trimmed.length > 0 ? trimmed : UNSET;
274
+ }
275
+ var cachedBuildHash = readBuildHashFromEnv();
276
+ function getBuildHash() {
277
+ return cachedBuildHash === UNSET ? void 0 : cachedBuildHash;
278
+ }
279
+
267
280
  // src/enriching-exporter.ts
268
281
  var ATTR = GLASSTRACE_ATTRIBUTE_NAMES;
269
282
  var API_KEY_PENDING = "pending";
@@ -379,6 +392,10 @@ var GlasstraceExporter = class {
379
392
  if (env) {
380
393
  extra[ATTR.ENVIRONMENT] = env;
381
394
  }
395
+ const buildHash = getBuildHash();
396
+ if (buildHash) {
397
+ extra[ATTR.BUILD_HASH] = buildHash;
398
+ }
382
399
  const existingCid = attrs["glasstrace.correlation.id"];
383
400
  if (typeof existingCid === "string") {
384
401
  extra[ATTR.CORRELATION_ID] = existingCid;
@@ -4207,7 +4224,7 @@ function registerGlasstrace(options) {
4207
4224
  setCoreState(CoreState.REGISTERING);
4208
4225
  startRuntimeStateWriter({
4209
4226
  projectRoot: process.cwd(),
4210
- sdkVersion: "1.2.1"
4227
+ sdkVersion: "1.3.0"
4211
4228
  });
4212
4229
  const config = resolveConfig(options);
4213
4230
  if (config.verbose) {
@@ -4373,8 +4390,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4373
4390
  if (config.verbose) {
4374
4391
  console.info("[glasstrace] Background init firing.");
4375
4392
  }
4376
- const healthReport = collectHealthReport("1.2.1");
4377
- const initResult = await performInit(config, anonKeyForInit, "1.2.1", healthReport);
4393
+ const healthReport = collectHealthReport("1.3.0");
4394
+ const initResult = await performInit(config, anonKeyForInit, "1.3.0", healthReport);
4378
4395
  if (generation !== registrationGeneration) return;
4379
4396
  const currentState = getCoreState();
4380
4397
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -4397,7 +4414,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4397
4414
  }
4398
4415
  maybeInstallConsoleCapture();
4399
4416
  if (didLastInitSucceed()) {
4400
- startHeartbeat(config, anonKeyForInit, "1.2.1", generation, (newApiKey, accountId) => {
4417
+ startHeartbeat(config, anonKeyForInit, "1.3.0", generation, (newApiKey, accountId) => {
4401
4418
  setAuthState(AuthState.CLAIMING);
4402
4419
  emitLifecycleEvent("auth:claim_started", { accountId });
4403
4420
  setResolvedApiKey(newApiKey);
@@ -4692,7 +4709,7 @@ async function handleSourceMapUpload(distDir) {
4692
4709
  );
4693
4710
  return;
4694
4711
  }
4695
- const { discoverSourceMapFiles, computeBuildHash, uploadSourceMaps } = await import("./source-map-uploader-RA4Z7TWA.js");
4712
+ const { discoverSourceMapFiles, computeBuildHash, uploadSourceMaps } = await import("./source-map-uploader-M2P5CDOB.js");
4696
4713
  const files = await discoverSourceMapFiles(distDir);
4697
4714
  if (files.length === 0) {
4698
4715
  console.info("[glasstrace] No source map files found. Skipping upload.");
@@ -4711,6 +4728,50 @@ async function handleSourceMapUpload(distDir) {
4711
4728
  }
4712
4729
  }
4713
4730
 
4731
+ // src/stack-frame.ts
4732
+ var PAREN_FRAME = /^\s*at\s+(?:[^()]+\s+)?\(([^()\s]+):(\d+):(\d+)\)\s*$/;
4733
+ var BARE_FRAME = /^\s*at\s+(?:async\s+)?([^()\s]+):(\d+):(\d+)\s*$/;
4734
+ var INTERNAL_FRAME_PATTERNS = [
4735
+ /^node:/,
4736
+ /^node:internal\//,
4737
+ /[/\\]node_modules[/\\]@glasstrace[/\\]sdk[/\\]/,
4738
+ /[/\\]packages[/\\]sdk[/\\]src[/\\]capture-error\./,
4739
+ /[/\\]packages[/\\]sdk[/\\]src[/\\]stack-frame\./
4740
+ ];
4741
+ function isInternalFrame(file) {
4742
+ return INTERNAL_FRAME_PATTERNS.some((re) => re.test(file));
4743
+ }
4744
+ function parseTopStackFrame(stack) {
4745
+ if (typeof stack !== "string" || stack.length === 0) return null;
4746
+ let cursor = 0;
4747
+ while (cursor < stack.length) {
4748
+ const newlineAt = stack.indexOf("\n", cursor);
4749
+ const lineEnd = newlineAt === -1 ? stack.length : newlineAt;
4750
+ const line = stack.slice(cursor, lineEnd);
4751
+ cursor = lineEnd + 1;
4752
+ if (!/^\s*at\s/.test(line)) continue;
4753
+ let file;
4754
+ let lineStr;
4755
+ const parenMatch = PAREN_FRAME.exec(line);
4756
+ if (parenMatch) {
4757
+ file = parenMatch[1];
4758
+ lineStr = parenMatch[2];
4759
+ } else {
4760
+ const bareMatch = BARE_FRAME.exec(line);
4761
+ if (bareMatch) {
4762
+ file = bareMatch[1];
4763
+ lineStr = bareMatch[2];
4764
+ }
4765
+ }
4766
+ if (!file || !lineStr) continue;
4767
+ if (isInternalFrame(file)) continue;
4768
+ const lineNum = Number.parseInt(lineStr, 10);
4769
+ if (!Number.isFinite(lineNum) || lineNum <= 0) continue;
4770
+ return { file, line: lineNum };
4771
+ }
4772
+ return null;
4773
+ }
4774
+
4714
4775
  // src/capture-error.ts
4715
4776
  function captureError(error) {
4716
4777
  try {
@@ -4723,6 +4784,11 @@ function captureError(error) {
4723
4784
  attributes["error.type"] = error.constructor.name;
4724
4785
  if (error.stack) {
4725
4786
  attributes["error.stack"] = error.stack;
4787
+ const frame = parseTopStackFrame(error.stack);
4788
+ if (frame) {
4789
+ attributes[GLASSTRACE_ATTRIBUTE_NAMES.SOURCE_FILE] = frame.file;
4790
+ attributes[GLASSTRACE_ATTRIBUTE_NAMES.SOURCE_LINE] = frame.line;
4791
+ }
4726
4792
  }
4727
4793
  }
4728
4794
  span.addEvent("glasstrace.error", attributes);
@@ -4746,4 +4812,4 @@ export {
4746
4812
  withGlasstraceConfig,
4747
4813
  captureError
4748
4814
  };
4749
- //# sourceMappingURL=chunk-CTJO7PUZ.js.map
4815
+ //# sourceMappingURL=chunk-JMYKR5Z3.js.map