@glasstrace/sdk 1.2.1 → 1.3.1

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 (54) hide show
  1. package/README.md +47 -0
  2. package/dist/{chunk-CTJO7PUZ.js → chunk-5PFPEA4C.js} +75 -9
  3. package/dist/chunk-5PFPEA4C.js.map +1 -0
  4. package/dist/{chunk-2GCN27SI.js → chunk-CRM3EYOL.js} +2 -2
  5. package/dist/{chunk-MD5XPCTQ.js → chunk-DW2UJUNB.js} +2 -2
  6. package/dist/chunk-DW2UJUNB.js.map +1 -0
  7. package/dist/{chunk-YMLMZCPR.js → chunk-JFR42QG5.js} +2 -2
  8. package/dist/{chunk-EBYISKQP.js → chunk-MQHLWSIX.js} +2 -1
  9. package/dist/{chunk-EBYISKQP.js.map → chunk-MQHLWSIX.js.map} +1 -1
  10. package/dist/{chunk-NFPDYME5.js → chunk-USLH3OTM.js} +3 -3
  11. package/dist/{chunk-NFPDYME5.js.map → chunk-USLH3OTM.js.map} +1 -1
  12. package/dist/{chunk-HV5ID2WJ.js → chunk-X4IK6KES.js} +3 -3
  13. package/dist/{chunk-47B2G3FE.js → chunk-XS3BO7RY.js} +2 -2
  14. package/dist/cli/init.cjs +1 -1
  15. package/dist/cli/init.cjs.map +1 -1
  16. package/dist/cli/init.js +6 -6
  17. package/dist/cli/mcp-add.cjs.map +1 -1
  18. package/dist/cli/mcp-add.js +2 -2
  19. package/dist/cli/uninit.cjs.map +1 -1
  20. package/dist/cli/uninit.js +3 -3
  21. package/dist/cli/validate.cjs.map +1 -1
  22. package/dist/cli/validate.js +2 -2
  23. package/dist/{edge-entry-DYl05SJ-.d.cts → edge-entry-DT9OhPTC.d.cts} +1 -1
  24. package/dist/{edge-entry-CFq085RZ.d.ts → edge-entry-shCc8_Y1.d.ts} +1 -1
  25. package/dist/edge-entry.cjs +1 -0
  26. package/dist/edge-entry.cjs.map +1 -1
  27. package/dist/edge-entry.d.cts +2 -2
  28. package/dist/edge-entry.d.ts +2 -2
  29. package/dist/edge-entry.js +2 -2
  30. package/dist/index.cjs +74 -4
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/{index.d-CYYe3PxB.d.cts → index.d-DiI6uVEW.d.cts} +1 -1
  33. package/dist/{index.d-CYYe3PxB.d.ts → index.d-DiI6uVEW.d.ts} +1 -1
  34. package/dist/index.d.cts +4 -4
  35. package/dist/index.d.ts +4 -4
  36. package/dist/index.js +5 -5
  37. package/dist/node-entry.cjs +74 -4
  38. package/dist/node-entry.cjs.map +1 -1
  39. package/dist/node-entry.d.cts +2 -2
  40. package/dist/node-entry.d.ts +2 -2
  41. package/dist/node-entry.js +7 -7
  42. package/dist/node-subpath.cjs.map +1 -1
  43. package/dist/node-subpath.d.cts +1 -1
  44. package/dist/node-subpath.d.ts +1 -1
  45. package/dist/node-subpath.js +3 -3
  46. package/dist/{source-map-uploader-RA4Z7TWA.js → source-map-uploader-LACAGKIW.js} +3 -3
  47. package/package.json +1 -1
  48. package/dist/chunk-CTJO7PUZ.js.map +0 -1
  49. package/dist/chunk-MD5XPCTQ.js.map +0 -1
  50. /package/dist/{chunk-2GCN27SI.js.map → chunk-CRM3EYOL.js.map} +0 -0
  51. /package/dist/{chunk-YMLMZCPR.js.map → chunk-JFR42QG5.js.map} +0 -0
  52. /package/dist/{chunk-HV5ID2WJ.js.map → chunk-X4IK6KES.js.map} +0 -0
  53. /package/dist/{chunk-47B2G3FE.js.map → chunk-XS3BO7RY.js.map} +0 -0
  54. /package/dist/{source-map-uploader-RA4Z7TWA.js.map → source-map-uploader-LACAGKIW.js.map} +0 -0
@@ -3,7 +3,7 @@ import * as z from './v4/classic/external.cjs';
3
3
  /**
4
4
  * Anonymous API key: `gt_anon_` + 48 hex chars.
5
5
  *
6
- * @drift-check ../glasstrace-product/docs/component-designs/sdk-2.0.md §1.2 Lens B — SDK-Facing Security Primitives (row `Anon API key gt_anon_[a-f0-9]{48}`)
6
+ * @drift-check ../glasstrace-product/docs/component-designs/sdk-architecture.md §1.2 Lens B — SDK-Facing Security Primitives (row `Anon API key gt_anon_[a-f0-9]{48}`)
7
7
  */
8
8
  declare const AnonApiKeySchema: z.core.$ZodBranded<z.ZodString, "AnonApiKey", "out">;
9
9
  type AnonApiKey = z.infer<typeof AnonApiKeySchema>;
@@ -3,7 +3,7 @@ import * as z from './v4/classic/external.cjs';
3
3
  /**
4
4
  * Anonymous API key: `gt_anon_` + 48 hex chars.
5
5
  *
6
- * @drift-check ../glasstrace-product/docs/component-designs/sdk-2.0.md §1.2 Lens B — SDK-Facing Security Primitives (row `Anon API key gt_anon_[a-f0-9]{48}`)
6
+ * @drift-check ../glasstrace-product/docs/component-designs/sdk-architecture.md §1.2 Lens B — SDK-Facing Security Primitives (row `Anon API key gt_anon_[a-f0-9]{48}`)
7
7
  */
8
8
  declare const AnonApiKeySchema: z.core.$ZodBranded<z.ZodString, "AnonApiKey", "out">;
9
9
  type AnonApiKey = z.infer<typeof AnonApiKeySchema>;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as SessionManager } from './edge-entry-DYl05SJ-.cjs';
2
- export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId, g as getDateString, b as getOrigin } from './edge-entry-DYl05SJ-.cjs';
3
- import { G as GlasstraceEnvVars, a as GlasstraceOptions, A as AnonApiKey, S as SdkInitResponse, C as CaptureConfig, b as SdkHealthReport, I as ImportGraphPayload, c as SdkDiagnosticCode } from './index.d-CYYe3PxB.cjs';
4
- export { d as deriveSessionId } from './index.d-CYYe3PxB.cjs';
1
+ import { a as SessionManager } from './edge-entry-DT9OhPTC.cjs';
2
+ export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId, g as getDateString, b as getOrigin } from './edge-entry-DT9OhPTC.cjs';
3
+ import { G as GlasstraceEnvVars, a as GlasstraceOptions, A as AnonApiKey, S as SdkInitResponse, C as CaptureConfig, b as SdkHealthReport, I as ImportGraphPayload, c as SdkDiagnosticCode } from './index.d-DiI6uVEW.cjs';
4
+ export { d as deriveSessionId } from './index.d-DiI6uVEW.cjs';
5
5
  import { ReadableSpan } from './export/ReadableSpan';
6
6
  import { SpanExporter } from './export/SpanExporter';
7
7
  import { ExportResult } from './ExportResult';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as SessionManager } from './edge-entry-CFq085RZ.js';
2
- export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId, g as getDateString, b as getOrigin } from './edge-entry-CFq085RZ.js';
3
- import { G as GlasstraceEnvVars, a as GlasstraceOptions, A as AnonApiKey, S as SdkInitResponse, C as CaptureConfig, b as SdkHealthReport, I as ImportGraphPayload, c as SdkDiagnosticCode } from './index.d-CYYe3PxB.js';
4
- export { d as deriveSessionId } from './index.d-CYYe3PxB.js';
1
+ import { a as SessionManager } from './edge-entry-shCc8_Y1.js';
2
+ export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId, g as getDateString, b as getOrigin } from './edge-entry-shCc8_Y1.js';
3
+ import { G as GlasstraceEnvVars, a as GlasstraceOptions, A as AnonApiKey, S as SdkInitResponse, C as CaptureConfig, b as SdkHealthReport, I as ImportGraphPayload, c as SdkDiagnosticCode } from './index.d-DiI6uVEW.js';
4
+ export { d as deriveSessionId } from './index.d-DiI6uVEW.js';
5
5
  import { ReadableSpan } from './export/ReadableSpan';
6
6
  import { SpanExporter } from './export/SpanExporter';
7
7
  import { ExportResult } from './ExportResult';
package/dist/index.js CHANGED
@@ -12,12 +12,12 @@ import {
12
12
  registerGlasstrace,
13
13
  waitForReady,
14
14
  withGlasstraceConfig
15
- } from "./chunk-CTJO7PUZ.js";
15
+ } from "./chunk-5PFPEA4C.js";
16
16
  import {
17
17
  GlasstraceSpanProcessor,
18
18
  SdkError,
19
19
  captureCorrelationId
20
- } from "./chunk-2GCN27SI.js";
20
+ } from "./chunk-CRM3EYOL.js";
21
21
  import "./chunk-DQ25VOKK.js";
22
22
  import "./chunk-3TU62WD6.js";
23
23
  import {
@@ -27,7 +27,7 @@ import {
27
27
  performInit,
28
28
  saveCachedConfig,
29
29
  sendInitRequest
30
- } from "./chunk-HV5ID2WJ.js";
30
+ } from "./chunk-X4IK6KES.js";
31
31
  import {
32
32
  isAnonymousMode,
33
33
  isProductionDisabled,
@@ -37,10 +37,10 @@ import {
37
37
  import {
38
38
  getOrCreateAnonKey,
39
39
  readAnonKey
40
- } from "./chunk-MD5XPCTQ.js";
40
+ } from "./chunk-DW2UJUNB.js";
41
41
  import {
42
42
  deriveSessionId
43
- } from "./chunk-EBYISKQP.js";
43
+ } from "./chunk-MQHLWSIX.js";
44
44
  import "./chunk-NSBPE2FW.js";
45
45
  export {
46
46
  GlasstraceExporter,
@@ -14724,6 +14724,7 @@ var init_dist = __esm({
14724
14724
  FETCH_DURATION_MS: "glasstrace.fetch.duration_ms",
14725
14725
  FETCH_TARGET: "glasstrace.fetch.target",
14726
14726
  ENV_REFERENCED: "glasstrace.env.referenced",
14727
+ BUILD_HASH: "glasstrace.build.hash",
14727
14728
  SOURCE_FILE: "glasstrace.source.file",
14728
14729
  SOURCE_LINE: "glasstrace.source.line",
14729
14730
  SOURCE_MAPPED: "glasstrace.source.mapped",
@@ -18422,6 +18423,19 @@ function prepareErrorResponseBody(body) {
18422
18423
  return truncateErrorResponseBody(sanitized);
18423
18424
  }
18424
18425
 
18426
+ // src/build-info.ts
18427
+ var UNSET = "";
18428
+ function readBuildHashFromEnv() {
18429
+ const raw = process.env.GLASSTRACE_BUILD_HASH;
18430
+ if (typeof raw !== "string") return UNSET;
18431
+ const trimmed = raw.trim();
18432
+ return trimmed.length > 0 ? trimmed : UNSET;
18433
+ }
18434
+ var cachedBuildHash = readBuildHashFromEnv();
18435
+ function getBuildHash() {
18436
+ return cachedBuildHash === UNSET ? void 0 : cachedBuildHash;
18437
+ }
18438
+
18425
18439
  // src/enriching-exporter.ts
18426
18440
  var ATTR2 = GLASSTRACE_ATTRIBUTE_NAMES;
18427
18441
  var API_KEY_PENDING = "pending";
@@ -18537,6 +18551,10 @@ var GlasstraceExporter = class {
18537
18551
  if (env) {
18538
18552
  extra[ATTR2.ENVIRONMENT] = env;
18539
18553
  }
18554
+ const buildHash = getBuildHash();
18555
+ if (buildHash) {
18556
+ extra[ATTR2.BUILD_HASH] = buildHash;
18557
+ }
18540
18558
  const existingCid = attrs["glasstrace.correlation.id"];
18541
18559
  if (typeof existingCid === "string") {
18542
18560
  extra[ATTR2.CORRELATION_ID] = existingCid;
@@ -22569,7 +22587,7 @@ function registerGlasstrace(options) {
22569
22587
  setCoreState(CoreState.REGISTERING);
22570
22588
  startRuntimeStateWriter({
22571
22589
  projectRoot: process.cwd(),
22572
- sdkVersion: "1.2.1"
22590
+ sdkVersion: "1.3.1"
22573
22591
  });
22574
22592
  const config2 = resolveConfig(options);
22575
22593
  if (config2.verbose) {
@@ -22735,8 +22753,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22735
22753
  if (config2.verbose) {
22736
22754
  console.info("[glasstrace] Background init firing.");
22737
22755
  }
22738
- const healthReport = collectHealthReport("1.2.1");
22739
- const initResult = await performInit(config2, anonKeyForInit, "1.2.1", healthReport);
22756
+ const healthReport = collectHealthReport("1.3.1");
22757
+ const initResult = await performInit(config2, anonKeyForInit, "1.3.1", healthReport);
22740
22758
  if (generation !== registrationGeneration) return;
22741
22759
  const currentState = getCoreState();
22742
22760
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -22759,7 +22777,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22759
22777
  }
22760
22778
  maybeInstallConsoleCapture();
22761
22779
  if (didLastInitSucceed()) {
22762
- startHeartbeat(config2, anonKeyForInit, "1.2.1", generation, (newApiKey, accountId) => {
22780
+ startHeartbeat(config2, anonKeyForInit, "1.3.1", generation, (newApiKey, accountId) => {
22763
22781
  setAuthState(AuthState.CLAIMING);
22764
22782
  emitLifecycleEvent("auth:claim_started", { accountId });
22765
22783
  setResolvedApiKey(newApiKey);
@@ -22917,7 +22935,54 @@ async function handleSourceMapUpload(distDir) {
22917
22935
 
22918
22936
  // src/capture-error.ts
22919
22937
  init_esm();
22938
+ init_dist();
22920
22939
  init_error_nudge();
22940
+
22941
+ // src/stack-frame.ts
22942
+ var PAREN_FRAME = /^\s*at\s+(?:[^()]+\s+)?\(([^()\s]+):(\d+):(\d+)\)\s*$/;
22943
+ var BARE_FRAME = /^\s*at\s+(?:async\s+)?([^()\s]+):(\d+):(\d+)\s*$/;
22944
+ var INTERNAL_FRAME_PATTERNS = [
22945
+ /^node:/,
22946
+ /^node:internal\//,
22947
+ /[/\\]node_modules[/\\]@glasstrace[/\\]sdk[/\\]/,
22948
+ /[/\\]packages[/\\]sdk[/\\]src[/\\]capture-error\./,
22949
+ /[/\\]packages[/\\]sdk[/\\]src[/\\]stack-frame\./
22950
+ ];
22951
+ function isInternalFrame(file2) {
22952
+ return INTERNAL_FRAME_PATTERNS.some((re2) => re2.test(file2));
22953
+ }
22954
+ function parseTopStackFrame(stack) {
22955
+ if (typeof stack !== "string" || stack.length === 0) return null;
22956
+ let cursor = 0;
22957
+ while (cursor < stack.length) {
22958
+ const newlineAt = stack.indexOf("\n", cursor);
22959
+ const lineEnd = newlineAt === -1 ? stack.length : newlineAt;
22960
+ const line = stack.slice(cursor, lineEnd);
22961
+ cursor = lineEnd + 1;
22962
+ if (!/^\s*at\s/.test(line)) continue;
22963
+ let file2;
22964
+ let lineStr;
22965
+ const parenMatch = PAREN_FRAME.exec(line);
22966
+ if (parenMatch) {
22967
+ file2 = parenMatch[1];
22968
+ lineStr = parenMatch[2];
22969
+ } else {
22970
+ const bareMatch = BARE_FRAME.exec(line);
22971
+ if (bareMatch) {
22972
+ file2 = bareMatch[1];
22973
+ lineStr = bareMatch[2];
22974
+ }
22975
+ }
22976
+ if (!file2 || !lineStr) continue;
22977
+ if (isInternalFrame(file2)) continue;
22978
+ const lineNum = Number.parseInt(lineStr, 10);
22979
+ if (!Number.isFinite(lineNum) || lineNum <= 0) continue;
22980
+ return { file: file2, line: lineNum };
22981
+ }
22982
+ return null;
22983
+ }
22984
+
22985
+ // src/capture-error.ts
22921
22986
  function captureError(error48) {
22922
22987
  try {
22923
22988
  const span = trace.getSpan(context.active());
@@ -22929,6 +22994,11 @@ function captureError(error48) {
22929
22994
  attributes["error.type"] = error48.constructor.name;
22930
22995
  if (error48.stack) {
22931
22996
  attributes["error.stack"] = error48.stack;
22997
+ const frame = parseTopStackFrame(error48.stack);
22998
+ if (frame) {
22999
+ attributes[GLASSTRACE_ATTRIBUTE_NAMES.SOURCE_FILE] = frame.file;
23000
+ attributes[GLASSTRACE_ATTRIBUTE_NAMES.SOURCE_LINE] = frame.line;
23001
+ }
22932
23002
  }
22933
23003
  }
22934
23004
  span.addEvent("glasstrace.error", attributes);