@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
@@ -2,9 +2,9 @@ import {
2
2
  GlasstraceSpanProcessor,
3
3
  SdkError,
4
4
  captureCorrelationId
5
- } from "./chunk-2GCN27SI.js";
5
+ } from "./chunk-AGCYKZFY.js";
6
6
  import "./chunk-DQ25VOKK.js";
7
- import "./chunk-EBYISKQP.js";
7
+ import "./chunk-GTPTKN5A.js";
8
8
  import "./chunk-NSBPE2FW.js";
9
9
  export {
10
10
  GlasstraceSpanProcessor,
package/dist/index.cjs CHANGED
@@ -14721,6 +14721,7 @@ var init_dist = __esm({
14721
14721
  FETCH_DURATION_MS: "glasstrace.fetch.duration_ms",
14722
14722
  FETCH_TARGET: "glasstrace.fetch.target",
14723
14723
  ENV_REFERENCED: "glasstrace.env.referenced",
14724
+ BUILD_HASH: "glasstrace.build.hash",
14724
14725
  SOURCE_FILE: "glasstrace.source.file",
14725
14726
  SOURCE_LINE: "glasstrace.source.line",
14726
14727
  SOURCE_MAPPED: "glasstrace.source.mapped",
@@ -18346,6 +18347,19 @@ function prepareErrorResponseBody(body) {
18346
18347
  return truncateErrorResponseBody(sanitized);
18347
18348
  }
18348
18349
 
18350
+ // src/build-info.ts
18351
+ var UNSET = "";
18352
+ function readBuildHashFromEnv() {
18353
+ const raw = process.env.GLASSTRACE_BUILD_HASH;
18354
+ if (typeof raw !== "string") return UNSET;
18355
+ const trimmed = raw.trim();
18356
+ return trimmed.length > 0 ? trimmed : UNSET;
18357
+ }
18358
+ var cachedBuildHash = readBuildHashFromEnv();
18359
+ function getBuildHash() {
18360
+ return cachedBuildHash === UNSET ? void 0 : cachedBuildHash;
18361
+ }
18362
+
18349
18363
  // src/enriching-exporter.ts
18350
18364
  var ATTR = GLASSTRACE_ATTRIBUTE_NAMES;
18351
18365
  var API_KEY_PENDING = "pending";
@@ -18461,6 +18475,10 @@ var GlasstraceExporter = class {
18461
18475
  if (env) {
18462
18476
  extra[ATTR.ENVIRONMENT] = env;
18463
18477
  }
18478
+ const buildHash = getBuildHash();
18479
+ if (buildHash) {
18480
+ extra[ATTR.BUILD_HASH] = buildHash;
18481
+ }
18464
18482
  const existingCid = attrs["glasstrace.correlation.id"];
18465
18483
  if (typeof existingCid === "string") {
18466
18484
  extra[ATTR.CORRELATION_ID] = existingCid;
@@ -22493,7 +22511,7 @@ function registerGlasstrace(options) {
22493
22511
  setCoreState(CoreState.REGISTERING);
22494
22512
  startRuntimeStateWriter({
22495
22513
  projectRoot: process.cwd(),
22496
- sdkVersion: "1.2.1"
22514
+ sdkVersion: "1.3.0"
22497
22515
  });
22498
22516
  const config2 = resolveConfig(options);
22499
22517
  if (config2.verbose) {
@@ -22659,8 +22677,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22659
22677
  if (config2.verbose) {
22660
22678
  console.info("[glasstrace] Background init firing.");
22661
22679
  }
22662
- const healthReport = collectHealthReport("1.2.1");
22663
- const initResult = await performInit(config2, anonKeyForInit, "1.2.1", healthReport);
22680
+ const healthReport = collectHealthReport("1.3.0");
22681
+ const initResult = await performInit(config2, anonKeyForInit, "1.3.0", healthReport);
22664
22682
  if (generation !== registrationGeneration) return;
22665
22683
  const currentState = getCoreState();
22666
22684
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -22683,7 +22701,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22683
22701
  }
22684
22702
  maybeInstallConsoleCapture();
22685
22703
  if (didLastInitSucceed()) {
22686
- startHeartbeat(config2, anonKeyForInit, "1.2.1", generation, (newApiKey, accountId) => {
22704
+ startHeartbeat(config2, anonKeyForInit, "1.3.0", generation, (newApiKey, accountId) => {
22687
22705
  setAuthState(AuthState.CLAIMING);
22688
22706
  emitLifecycleEvent("auth:claim_started", { accountId });
22689
22707
  setResolvedApiKey(newApiKey);
@@ -22841,7 +22859,54 @@ async function handleSourceMapUpload(distDir) {
22841
22859
 
22842
22860
  // src/capture-error.ts
22843
22861
  init_esm();
22862
+ init_dist();
22844
22863
  init_error_nudge();
22864
+
22865
+ // src/stack-frame.ts
22866
+ var PAREN_FRAME = /^\s*at\s+(?:[^()]+\s+)?\(([^()\s]+):(\d+):(\d+)\)\s*$/;
22867
+ var BARE_FRAME = /^\s*at\s+(?:async\s+)?([^()\s]+):(\d+):(\d+)\s*$/;
22868
+ var INTERNAL_FRAME_PATTERNS = [
22869
+ /^node:/,
22870
+ /^node:internal\//,
22871
+ /[/\\]node_modules[/\\]@glasstrace[/\\]sdk[/\\]/,
22872
+ /[/\\]packages[/\\]sdk[/\\]src[/\\]capture-error\./,
22873
+ /[/\\]packages[/\\]sdk[/\\]src[/\\]stack-frame\./
22874
+ ];
22875
+ function isInternalFrame(file2) {
22876
+ return INTERNAL_FRAME_PATTERNS.some((re2) => re2.test(file2));
22877
+ }
22878
+ function parseTopStackFrame(stack) {
22879
+ if (typeof stack !== "string" || stack.length === 0) return null;
22880
+ let cursor = 0;
22881
+ while (cursor < stack.length) {
22882
+ const newlineAt = stack.indexOf("\n", cursor);
22883
+ const lineEnd = newlineAt === -1 ? stack.length : newlineAt;
22884
+ const line = stack.slice(cursor, lineEnd);
22885
+ cursor = lineEnd + 1;
22886
+ if (!/^\s*at\s/.test(line)) continue;
22887
+ let file2;
22888
+ let lineStr;
22889
+ const parenMatch = PAREN_FRAME.exec(line);
22890
+ if (parenMatch) {
22891
+ file2 = parenMatch[1];
22892
+ lineStr = parenMatch[2];
22893
+ } else {
22894
+ const bareMatch = BARE_FRAME.exec(line);
22895
+ if (bareMatch) {
22896
+ file2 = bareMatch[1];
22897
+ lineStr = bareMatch[2];
22898
+ }
22899
+ }
22900
+ if (!file2 || !lineStr) continue;
22901
+ if (isInternalFrame(file2)) continue;
22902
+ const lineNum = Number.parseInt(lineStr, 10);
22903
+ if (!Number.isFinite(lineNum) || lineNum <= 0) continue;
22904
+ return { file: file2, line: lineNum };
22905
+ }
22906
+ return null;
22907
+ }
22908
+
22909
+ // src/capture-error.ts
22845
22910
  function captureError(error48) {
22846
22911
  try {
22847
22912
  const span = trace.getSpan(context.active());
@@ -22853,6 +22918,11 @@ function captureError(error48) {
22853
22918
  attributes["error.type"] = error48.constructor.name;
22854
22919
  if (error48.stack) {
22855
22920
  attributes["error.stack"] = error48.stack;
22921
+ const frame = parseTopStackFrame(error48.stack);
22922
+ if (frame) {
22923
+ attributes[GLASSTRACE_ATTRIBUTE_NAMES.SOURCE_FILE] = frame.file;
22924
+ attributes[GLASSTRACE_ATTRIBUTE_NAMES.SOURCE_LINE] = frame.line;
22925
+ }
22856
22926
  }
22857
22927
  }
22858
22928
  span.addEvent("glasstrace.error", attributes);