@glasstrace/sdk 1.2.0 → 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 (43) hide show
  1. package/README.md +47 -0
  2. package/dist/{chunk-JKI4OCFV.js → chunk-A63WX7NR.js} +3 -3
  3. package/dist/{chunk-6RNBUUBR.js → chunk-AGCYKZFY.js} +2 -2
  4. package/dist/{chunk-4EZ6JTDG.js → chunk-AKZGMT33.js} +2 -2
  5. package/dist/{chunk-TWTWRJ25.js → chunk-AYUL5QMZ.js} +2 -2
  6. package/dist/{chunk-DST4UBXU.js → chunk-FMEWG3FY.js} +2 -2
  7. package/dist/{chunk-TWHCJKRS.js → chunk-FVHVDBGX.js} +3 -3
  8. package/dist/{chunk-X5MAXP5T.js → chunk-GTPTKN5A.js} +6 -3
  9. package/dist/{chunk-X5MAXP5T.js.map → chunk-GTPTKN5A.js.map} +1 -1
  10. package/dist/{chunk-6RIH6SFM.js → chunk-JMYKR5Z3.js} +89 -17
  11. package/dist/chunk-JMYKR5Z3.js.map +1 -0
  12. package/dist/cli/init.cjs +5 -3
  13. package/dist/cli/init.cjs.map +1 -1
  14. package/dist/cli/init.js +6 -6
  15. package/dist/cli/mcp-add.cjs +4 -2
  16. package/dist/cli/mcp-add.cjs.map +1 -1
  17. package/dist/cli/mcp-add.js +2 -2
  18. package/dist/cli/uninit.js +3 -3
  19. package/dist/cli/validate.cjs +4 -2
  20. package/dist/cli/validate.cjs.map +1 -1
  21. package/dist/cli/validate.js +2 -2
  22. package/dist/edge-entry.cjs +5 -2
  23. package/dist/edge-entry.cjs.map +1 -1
  24. package/dist/edge-entry.js +2 -2
  25. package/dist/index.cjs +92 -14
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.js +5 -5
  28. package/dist/node-entry.cjs +92 -14
  29. package/dist/node-entry.cjs.map +1 -1
  30. package/dist/node-entry.js +7 -7
  31. package/dist/node-subpath.cjs +4 -2
  32. package/dist/node-subpath.cjs.map +1 -1
  33. package/dist/node-subpath.js +3 -3
  34. package/dist/{source-map-uploader-DPUUCLNW.js → source-map-uploader-M2P5CDOB.js} +3 -3
  35. package/package.json +1 -1
  36. package/dist/chunk-6RIH6SFM.js.map +0 -1
  37. /package/dist/{chunk-JKI4OCFV.js.map → chunk-A63WX7NR.js.map} +0 -0
  38. /package/dist/{chunk-6RNBUUBR.js.map → chunk-AGCYKZFY.js.map} +0 -0
  39. /package/dist/{chunk-4EZ6JTDG.js.map → chunk-AKZGMT33.js.map} +0 -0
  40. /package/dist/{chunk-TWTWRJ25.js.map → chunk-AYUL5QMZ.js.map} +0 -0
  41. /package/dist/{chunk-DST4UBXU.js.map → chunk-FMEWG3FY.js.map} +0 -0
  42. /package/dist/{chunk-TWHCJKRS.js.map → chunk-FVHVDBGX.js.map} +0 -0
  43. /package/dist/{source-map-uploader-DPUUCLNW.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-JKI4OCFV.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-TWTWRJ25.js";
46
+ } from "./chunk-AYUL5QMZ.js";
47
47
  import {
48
48
  GLASSTRACE_ATTRIBUTE_NAMES,
49
49
  deriveSessionId
50
- } from "./chunk-X5MAXP5T.js";
50
+ } from "./chunk-GTPTKN5A.js";
51
51
  import {
52
52
  __require
53
53
  } from "./chunk-NSBPE2FW.js";
@@ -144,16 +144,22 @@ var ERROR_RESPONSE_BODY_TRUNCATION_MARKER = "...[truncated]";
144
144
  var REDACTED = "[REDACTED]";
145
145
  var ERROR_STATUS_MIN = 400;
146
146
  var ERROR_STATUS_MAX = 599;
147
- function isHttpErrorStatus(status) {
147
+ function coerceHttpStatus(value) {
148
148
  let numeric;
149
- if (typeof status === "number") {
150
- numeric = status;
151
- } else if (typeof status === "string" && status.length > 0) {
152
- numeric = Number(status);
149
+ if (typeof value === "number") {
150
+ numeric = value;
151
+ } else if (typeof value === "string") {
152
+ const trimmed = value.trim();
153
+ if (trimmed.length === 0) return void 0;
154
+ numeric = Number(trimmed);
153
155
  } else {
154
- return false;
156
+ return void 0;
155
157
  }
156
- if (!Number.isFinite(numeric)) return false;
158
+ return Number.isFinite(numeric) ? numeric : void 0;
159
+ }
160
+ function isHttpErrorStatus(status) {
161
+ const numeric = coerceHttpStatus(status);
162
+ if (numeric === void 0) return false;
157
163
  return numeric >= ERROR_STATUS_MIN && numeric <= ERROR_STATUS_MAX;
158
164
  }
159
165
  var REDACTION_PATTERNS = [
@@ -258,6 +264,19 @@ function prepareErrorResponseBody(body) {
258
264
  return truncateErrorResponseBody(sanitized);
259
265
  }
260
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
+
261
280
  // src/enriching-exporter.ts
262
281
  var ATTR = GLASSTRACE_ATTRIBUTE_NAMES;
263
282
  var API_KEY_PENDING = "pending";
@@ -373,6 +392,10 @@ var GlasstraceExporter = class {
373
392
  if (env) {
374
393
  extra[ATTR.ENVIRONMENT] = env;
375
394
  }
395
+ const buildHash = getBuildHash();
396
+ if (buildHash) {
397
+ extra[ATTR.BUILD_HASH] = buildHash;
398
+ }
376
399
  const existingCid = attrs["glasstrace.correlation.id"];
377
400
  if (typeof existingCid === "string") {
378
401
  extra[ATTR.CORRELATION_ID] = existingCid;
@@ -413,7 +436,7 @@ var GlasstraceExporter = class {
413
436
  }
414
437
  }
415
438
  }
416
- const statusCode = attrs["http.status_code"] ?? attrs["http.response.status_code"];
439
+ const statusCode = coerceHttpStatus(attrs["http.status_code"]) ?? coerceHttpStatus(attrs["http.response.status_code"]);
417
440
  if (statusCode !== void 0) {
418
441
  extra[ATTR.HTTP_STATUS_CODE] = statusCode;
419
442
  }
@@ -4201,7 +4224,7 @@ function registerGlasstrace(options) {
4201
4224
  setCoreState(CoreState.REGISTERING);
4202
4225
  startRuntimeStateWriter({
4203
4226
  projectRoot: process.cwd(),
4204
- sdkVersion: "1.2.0"
4227
+ sdkVersion: "1.3.0"
4205
4228
  });
4206
4229
  const config = resolveConfig(options);
4207
4230
  if (config.verbose) {
@@ -4367,8 +4390,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4367
4390
  if (config.verbose) {
4368
4391
  console.info("[glasstrace] Background init firing.");
4369
4392
  }
4370
- const healthReport = collectHealthReport("1.2.0");
4371
- const initResult = await performInit(config, anonKeyForInit, "1.2.0", healthReport);
4393
+ const healthReport = collectHealthReport("1.3.0");
4394
+ const initResult = await performInit(config, anonKeyForInit, "1.3.0", healthReport);
4372
4395
  if (generation !== registrationGeneration) return;
4373
4396
  const currentState = getCoreState();
4374
4397
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -4391,7 +4414,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4391
4414
  }
4392
4415
  maybeInstallConsoleCapture();
4393
4416
  if (didLastInitSucceed()) {
4394
- startHeartbeat(config, anonKeyForInit, "1.2.0", generation, (newApiKey, accountId) => {
4417
+ startHeartbeat(config, anonKeyForInit, "1.3.0", generation, (newApiKey, accountId) => {
4395
4418
  setAuthState(AuthState.CLAIMING);
4396
4419
  emitLifecycleEvent("auth:claim_started", { accountId });
4397
4420
  setResolvedApiKey(newApiKey);
@@ -4686,7 +4709,7 @@ async function handleSourceMapUpload(distDir) {
4686
4709
  );
4687
4710
  return;
4688
4711
  }
4689
- const { discoverSourceMapFiles, computeBuildHash, uploadSourceMaps } = await import("./source-map-uploader-DPUUCLNW.js");
4712
+ const { discoverSourceMapFiles, computeBuildHash, uploadSourceMaps } = await import("./source-map-uploader-M2P5CDOB.js");
4690
4713
  const files = await discoverSourceMapFiles(distDir);
4691
4714
  if (files.length === 0) {
4692
4715
  console.info("[glasstrace] No source map files found. Skipping upload.");
@@ -4705,6 +4728,50 @@ async function handleSourceMapUpload(distDir) {
4705
4728
  }
4706
4729
  }
4707
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
+
4708
4775
  // src/capture-error.ts
4709
4776
  function captureError(error) {
4710
4777
  try {
@@ -4717,6 +4784,11 @@ function captureError(error) {
4717
4784
  attributes["error.type"] = error.constructor.name;
4718
4785
  if (error.stack) {
4719
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
+ }
4720
4792
  }
4721
4793
  }
4722
4794
  span.addEvent("glasstrace.error", attributes);
@@ -4740,4 +4812,4 @@ export {
4740
4812
  withGlasstraceConfig,
4741
4813
  captureError
4742
4814
  };
4743
- //# sourceMappingURL=chunk-6RIH6SFM.js.map
4815
+ //# sourceMappingURL=chunk-JMYKR5Z3.js.map