@glasstrace/sdk 1.5.1 → 1.6.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 (44) hide show
  1. package/README.md +108 -0
  2. package/dist/{chunk-YLY7AGLC.js → chunk-3PJP5Y3U.js} +3 -3
  3. package/dist/{chunk-Q42BY5BA.js → chunk-H57MQGNU.js} +2 -2
  4. package/dist/{chunk-TANUWTFO.js → chunk-M2TLX6NM.js} +3 -3
  5. package/dist/{chunk-MMKFFF2L.js → chunk-NN5YCETI.js} +2 -2
  6. package/dist/{chunk-4WI7B5FQ.js → chunk-P45NZR4J.js} +21 -1
  7. package/dist/chunk-P45NZR4J.js.map +1 -0
  8. package/dist/{chunk-QU26IKIJ.js → chunk-UQKI476D.js} +2 -2
  9. package/dist/{chunk-MFYOQOD7.js → chunk-WL6BXEJ5.js} +2 -2
  10. package/dist/{chunk-MLRQTCCK.js → chunk-ZU5XO77C.js} +205 -28
  11. package/dist/chunk-ZU5XO77C.js.map +1 -0
  12. package/dist/cli/init.cjs +4 -4
  13. package/dist/cli/init.cjs.map +1 -1
  14. package/dist/cli/init.js +7 -7
  15. package/dist/cli/mcp-add.cjs +1 -1
  16. package/dist/cli/mcp-add.cjs.map +1 -1
  17. package/dist/cli/mcp-add.js +3 -3
  18. package/dist/cli/uninit.js +3 -3
  19. package/dist/cli/upgrade-instructions.cjs +1 -1
  20. package/dist/cli/upgrade-instructions.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.cjs +20 -0
  24. package/dist/edge-entry.cjs.map +1 -1
  25. package/dist/edge-entry.js +2 -2
  26. package/dist/index.cjs +220 -23
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.js +5 -5
  29. package/dist/node-entry.cjs +220 -23
  30. package/dist/node-entry.cjs.map +1 -1
  31. package/dist/node-entry.js +7 -7
  32. package/dist/node-subpath.cjs.map +1 -1
  33. package/dist/node-subpath.js +3 -3
  34. package/dist/{source-map-uploader-PB3M4PPP.js → source-map-uploader-XFUEVV7I.js} +3 -3
  35. package/package.json +1 -1
  36. package/dist/chunk-4WI7B5FQ.js.map +0 -1
  37. package/dist/chunk-MLRQTCCK.js.map +0 -1
  38. /package/dist/{chunk-YLY7AGLC.js.map → chunk-3PJP5Y3U.js.map} +0 -0
  39. /package/dist/{chunk-Q42BY5BA.js.map → chunk-H57MQGNU.js.map} +0 -0
  40. /package/dist/{chunk-TANUWTFO.js.map → chunk-M2TLX6NM.js.map} +0 -0
  41. /package/dist/{chunk-MMKFFF2L.js.map → chunk-NN5YCETI.js.map} +0 -0
  42. /package/dist/{chunk-QU26IKIJ.js.map → chunk-UQKI476D.js.map} +0 -0
  43. /package/dist/{chunk-MFYOQOD7.js.map → chunk-WL6BXEJ5.js.map} +0 -0
  44. /package/dist/{source-map-uploader-PB3M4PPP.js.map → source-map-uploader-XFUEVV7I.js.map} +0 -0
package/README.md CHANGED
@@ -349,6 +349,114 @@ body data. If your account enables the flag but a span never carries
349
349
  the internal attribute (no adapter set it), the public attribute is
350
350
  still absent. The default is "off, twice".
351
351
 
352
+ ## Capturing error evidence
353
+
354
+ For server-side errors, the SDK promotes a curated set of OTel
355
+ attributes into the `glasstrace.error.*` family so product
356
+ consumers can render bounded, sanitized error evidence without
357
+ having to parse raw stack traces or framework HTML themselves.
358
+
359
+ ### Bounded stack capture
360
+
361
+ When an OTel `recordException()` event (or a span attribute carrying
362
+ `exception.stacktrace`) is observed on a failed span, the SDK
363
+ emits the stack as `glasstrace.error.stack` with two sibling
364
+ booleans:
365
+
366
+ | Attribute | Meaning |
367
+ |---|---|
368
+ | `glasstrace.error.stack` | The bounded stack string (sanitized, then truncated). Treat this as input for product-side `StackSummary` parsing, not as a final agent-facing artifact. |
369
+ | `glasstrace.error.stack.truncated` | `true` if the original exceeded the byte budget and `...[stack truncated]` was appended. |
370
+ | `glasstrace.error.stack.redacted` | `true` if at least one sanitization rule modified the stack content (path normalization, URL query stripping, or credential redaction). |
371
+
372
+ Sanitization runs **before** truncation so credentials straddling
373
+ the truncation boundary are still removed from the visible portion.
374
+ The sanitizer:
375
+
376
+ - **Normalizes absolute paths.** A frame like
377
+ `at handler (/Users/erik/proj/src/api/handler.ts:5:1)` becomes
378
+ `at handler (<path>/src/api/handler.ts:5:1)`. The keep-from
379
+ marker set is `node_modules`, `.next`, `.glasstrace`, `src`,
380
+ `dist`, `build`, `lib`, `app`, `pages` (priority order). When no
381
+ marker matches, the path collapses to its basename so
382
+ `/var/private/secret/data.js` becomes `<path>/data.js`.
383
+ - **Strips URL query strings and fragments.**
384
+ `https://api.example.com/users?token=secret` becomes
385
+ `https://api.example.com/users`.
386
+ - **Redacts credentials** using the same pattern set as
387
+ response-body capture: `Bearer …`, JWT-shaped tokens,
388
+ Glasstrace API key prefixes (`gt_dev_*` / `gt_anon_*`), AWS
389
+ access keys (`AKIA…` / `ASIA…`), and `apikey`/`secret`/
390
+ `password`/`token` key-value pairs.
391
+
392
+ The byte budget is 8192 UTF-8 bytes. Truncation respects codepoint
393
+ boundaries so multi-byte characters are never split mid-sequence.
394
+
395
+ ### Source provenance
396
+
397
+ When the exporter emits any of the new
398
+ `glasstrace.error.{message,code,stack,original_path,fallback_route}`
399
+ attributes, it also sets `glasstrace.error.source` to name the
400
+ surface that supplied the facts:
401
+
402
+ | Value | Source |
403
+ |---|---|
404
+ | `otel_exception` | OTel `recordException()` event (event name `"exception"`). |
405
+ | `otel_event` | An OTel-shape `exception.*` attribute set on the span itself instead of on an event. |
406
+ | `glasstrace_attribute` | A `glasstrace.error.*` attribute set explicitly by an adapter or user code. |
407
+ | `framework_runtime` | Reserved for a future framework-runtime probe. |
408
+ | `framework_fallback` | The framework rewrote the route to a fallback (e.g., `/_error`); see below. |
409
+ | `response_body` | Reserved for cases where the response body is the only error-bearing surface. |
410
+
411
+ Product consumers use the source to decide how to render
412
+ evidence (an `otel_exception` source can show the raw type and
413
+ message; `framework_fallback` is a softer signal that benefits
414
+ from the original-path context).
415
+
416
+ ### Framework fallback markers
417
+
418
+ When a request reaches a framework fallback route — Next.js
419
+ `/_error`, `/_not-found`, `/_404`, `/_500` — the SDK preserves
420
+ the originally requested path so product consumers don't lose the
421
+ URL the user actually hit. Three additional attributes land on
422
+ the span:
423
+
424
+ | Attribute | Example |
425
+ |---|---|
426
+ | `glasstrace.error.original_path` | `/api/storage/missing/avatar.png` (path-only; no query, no fragment) |
427
+ | `glasstrace.error.fallback_route` | `/_error` |
428
+ | `glasstrace.error.framework.kind` | `"fallback"` |
429
+
430
+ The existing `glasstrace.route` attribute continues to carry
431
+ whatever the framework instrumentation reported (typically the
432
+ fallback route itself), so existing consumers are unaffected.
433
+ Product-side projection should prefer `glasstrace.error.original_path`
434
+ when present and fall back to `glasstrace.route` otherwise. The
435
+ markers fire only when the SDK observed a different requested URL
436
+ than the route — a real visit to `/_error` (an app could have a
437
+ real such page) is not flagged.
438
+
439
+ ### What the SDK does NOT do
440
+
441
+ For agent-facing protection, several things are explicitly *not*
442
+ emitted from the SDK side:
443
+
444
+ - **No raw `exception.stacktrace`.** The string is always
445
+ sanitized before promotion to `glasstrace.error.stack`, and the
446
+ source-attribute path that bypassed enrichment never appears in
447
+ agent-facing MCP output (product ingestion projects only the
448
+ `glasstrace.*` family).
449
+ - **No fabricated stack frames** when `exception.stacktrace` was
450
+ not observed. Missing stack evidence stays missing; the
451
+ `glasstrace.error.stack*` attributes are simply absent.
452
+ - **No compile-diagnostic capture** in this version. If the SDK
453
+ cannot observe a Next.js compile error in the running mode, no
454
+ diagnostic is fabricated from the route name or status code.
455
+ Compile-diagnostic capture is a future feature gated on a
456
+ separate account capture-policy class.
457
+ - **No structured application logs.** Application logs are
458
+ outside the trace-evidence contract.
459
+
352
460
  ## Capturing side-effect evidence
353
461
 
354
462
  When debugging a bug whose root cause is which side-effect operation
@@ -5,10 +5,10 @@ import {
5
5
  isDevApiKey,
6
6
  readEnvLocalApiKey,
7
7
  writeAndFsyncTempSync
8
- } from "./chunk-MFYOQOD7.js";
8
+ } from "./chunk-WL6BXEJ5.js";
9
9
  import {
10
10
  AnonApiKeySchema
11
- } from "./chunk-4WI7B5FQ.js";
11
+ } from "./chunk-P45NZR4J.js";
12
12
  import {
13
13
  NEXT_CONFIG_NAMES
14
14
  } from "./chunk-NB7GJE4S.js";
@@ -917,4 +917,4 @@ export {
917
917
  writeShutdownMarker,
918
918
  runUninit
919
919
  };
920
- //# sourceMappingURL=chunk-YLY7AGLC.js.map
920
+ //# sourceMappingURL=chunk-3PJP5Y3U.js.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-DQ25VOKK.js";
4
4
  import {
5
5
  GLASSTRACE_ATTRIBUTE_NAMES
6
- } from "./chunk-4WI7B5FQ.js";
6
+ } from "./chunk-P45NZR4J.js";
7
7
 
8
8
  // src/errors.ts
9
9
  var SdkError = class extends Error {
@@ -102,4 +102,4 @@ export {
102
102
  GlasstraceSpanProcessor,
103
103
  captureCorrelationId
104
104
  };
105
- //# sourceMappingURL=chunk-Q42BY5BA.js.map
105
+ //# sourceMappingURL=chunk-H57MQGNU.js.map
@@ -2,12 +2,12 @@ import {
2
2
  atomicWriteFile,
3
3
  refreshGenericMcpConfigAtRuntime,
4
4
  resolveEffectiveMcpCredential
5
- } from "./chunk-MFYOQOD7.js";
5
+ } from "./chunk-WL6BXEJ5.js";
6
6
  import {
7
7
  DEFAULT_CAPTURE_CONFIG,
8
8
  SdkCachedConfigSchema,
9
9
  SdkInitResponseSchema
10
- } from "./chunk-4WI7B5FQ.js";
10
+ } from "./chunk-P45NZR4J.js";
11
11
  import {
12
12
  __require
13
13
  } from "./chunk-NSBPE2FW.js";
@@ -692,4 +692,4 @@ export {
692
692
  didLastInitSucceed,
693
693
  verifyInitReachable
694
694
  };
695
- //# sourceMappingURL=chunk-TANUWTFO.js.map
695
+ //# sourceMappingURL=chunk-M2TLX6NM.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createBuildHash
3
- } from "./chunk-4WI7B5FQ.js";
3
+ } from "./chunk-P45NZR4J.js";
4
4
 
5
5
  // src/import-graph.ts
6
6
  import * as fs from "node:fs/promises";
@@ -175,4 +175,4 @@ export {
175
175
  extractImports,
176
176
  buildImportGraph
177
177
  };
178
- //# sourceMappingURL=chunk-MMKFFF2L.js.map
178
+ //# sourceMappingURL=chunk-NN5YCETI.js.map
@@ -13850,6 +13850,26 @@ var GLASSTRACE_ATTRIBUTE_NAMES = {
13850
13850
  ERROR_CODE: "glasstrace.error.code",
13851
13851
  ERROR_CATEGORY: "glasstrace.error.category",
13852
13852
  ERROR_FIELD: "glasstrace.error.field",
13853
+ // Error evidence v1 (SDK-041 / DISC-1535).
13854
+ // Additive to the existing `glasstrace.error.*` family. Bounded
13855
+ // stacktrace input for the product-side StackSummary parser
13856
+ // (SCHEMA-033); plus framework-fallback markers so the original
13857
+ // request path is preserved when Next.js (or another framework)
13858
+ // rewrites the route to a fallback like `/_error` or `/_not-found`;
13859
+ // plus a source-provenance enum so product can tell which surface
13860
+ // emitted each error fact (`exception.message` event vs span attr
13861
+ // vs response body vs framework runtime).
13862
+ //
13863
+ // Wire keys remain in `glasstrace.error.*` for namespace consistency
13864
+ // with the Tier-1 `error.message` / `error.code` / `error.category`
13865
+ // attributes already in this registry.
13866
+ ERROR_STACK: "glasstrace.error.stack",
13867
+ ERROR_STACK_TRUNCATED: "glasstrace.error.stack.truncated",
13868
+ ERROR_STACK_REDACTED: "glasstrace.error.stack.redacted",
13869
+ ERROR_SOURCE: "glasstrace.error.source",
13870
+ ERROR_FRAMEWORK_KIND: "glasstrace.error.framework.kind",
13871
+ ERROR_ORIGINAL_PATH: "glasstrace.error.original_path",
13872
+ ERROR_FALLBACK_ROUTE: "glasstrace.error.fallback_route",
13853
13873
  ORM_PROVIDER: "glasstrace.orm.provider",
13854
13874
  ORM_MODEL: "glasstrace.orm.model",
13855
13875
  ORM_OPERATION: "glasstrace.orm.operation",
@@ -14238,4 +14258,4 @@ export {
14238
14258
  SIDE_EFFECT_OPERATION_STATUSES,
14239
14259
  SIDE_EFFECT_OPERATION_PHASES
14240
14260
  };
14241
- //# sourceMappingURL=chunk-4WI7B5FQ.js.map
14261
+ //# sourceMappingURL=chunk-P45NZR4J.js.map