@glasstrace/sdk 1.8.0 → 1.9.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 (75) hide show
  1. package/dist/async-context/index.cjs +15005 -0
  2. package/dist/async-context/index.cjs.map +1 -0
  3. package/dist/async-context/index.d.cts +174 -0
  4. package/dist/async-context/index.d.ts +174 -0
  5. package/dist/async-context/index.js +13 -0
  6. package/dist/{capture-error-Dzz7_-v4.d.ts → capture-error-BeuEXXJO.d.cts} +2 -2
  7. package/dist/{capture-error-C95zvSvF.d.cts → capture-error-D02pzB7q.d.ts} +2 -2
  8. package/dist/chunk-CL3OVHPO.js +23 -0
  9. package/dist/chunk-CL3OVHPO.js.map +1 -0
  10. package/dist/{chunk-WL6BXEJ5.js → chunk-DKV53A2C.js} +2 -2
  11. package/dist/{chunk-3PJP5Y3U.js → chunk-GWIEUBFR.js} +3 -3
  12. package/dist/{chunk-H57MQGNU.js → chunk-H6WJ63X2.js} +2 -2
  13. package/dist/{chunk-NN5YCETI.js → chunk-HD6JIFKN.js} +2 -2
  14. package/dist/{chunk-P45NZR4J.js → chunk-JHUNLPSS.js} +35 -1
  15. package/dist/{chunk-P45NZR4J.js.map → chunk-JHUNLPSS.js.map} +1 -1
  16. package/dist/{chunk-UQKI476D.js → chunk-M6EWJCAT.js} +2 -2
  17. package/dist/chunk-QHV7NFON.js +130 -0
  18. package/dist/chunk-QHV7NFON.js.map +1 -0
  19. package/dist/{chunk-M2TLX6NM.js → chunk-QXITSNYM.js} +3 -3
  20. package/dist/chunk-RQ5BIWDT.js +119 -0
  21. package/dist/chunk-RQ5BIWDT.js.map +1 -0
  22. package/dist/{chunk-JJL2M64Z.js → chunk-XEPC4NFL.js} +19 -10
  23. package/dist/chunk-XEPC4NFL.js.map +1 -0
  24. package/dist/cli/init.cjs +4 -4
  25. package/dist/cli/init.cjs.map +1 -1
  26. package/dist/cli/init.js +7 -7
  27. package/dist/cli/mcp-add.cjs +1 -1
  28. package/dist/cli/mcp-add.cjs.map +1 -1
  29. package/dist/cli/mcp-add.js +3 -3
  30. package/dist/cli/uninit.js +3 -3
  31. package/dist/cli/upgrade-instructions.cjs +1 -1
  32. package/dist/cli/upgrade-instructions.js +3 -3
  33. package/dist/cli/validate.cjs.map +1 -1
  34. package/dist/cli/validate.js +2 -2
  35. package/dist/{edge-entry-AWO70gje.d.ts → correlation-id-B_K8adD6.d.ts} +1 -1
  36. package/dist/{edge-entry-DaeG7D7S.d.cts → correlation-id-NAapJ5jn.d.cts} +1 -1
  37. package/dist/edge-entry.cjs +295 -26
  38. package/dist/edge-entry.cjs.map +1 -1
  39. package/dist/edge-entry.d.cts +5 -2
  40. package/dist/edge-entry.d.ts +5 -2
  41. package/dist/edge-entry.js +12 -3
  42. package/dist/index.cjs +55 -5
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/{index.d-Dq33YwFT.d.cts → index.d-CkTf_boH.d.cts} +1 -1
  45. package/dist/{index.d-Dq33YwFT.d.ts → index.d-CkTf_boH.d.ts} +1 -1
  46. package/dist/index.d.cts +7 -4
  47. package/dist/index.d.ts +7 -4
  48. package/dist/index.js +6 -5
  49. package/dist/index.js.map +1 -1
  50. package/dist/middleware/index.cjs +15014 -0
  51. package/dist/middleware/index.cjs.map +1 -0
  52. package/dist/middleware/index.d.cts +183 -0
  53. package/dist/middleware/index.d.ts +183 -0
  54. package/dist/middleware/index.js +13 -0
  55. package/dist/middleware/index.js.map +1 -0
  56. package/dist/node-entry.cjs +55 -5
  57. package/dist/node-entry.cjs.map +1 -1
  58. package/dist/node-entry.d.cts +3 -3
  59. package/dist/node-entry.d.ts +3 -3
  60. package/dist/node-entry.js +8 -7
  61. package/dist/node-subpath.cjs.map +1 -1
  62. package/dist/node-subpath.d.cts +1 -1
  63. package/dist/node-subpath.d.ts +1 -1
  64. package/dist/node-subpath.js +3 -3
  65. package/dist/{source-map-uploader-XFUEVV7I.js → source-map-uploader-MMJ2WCL4.js} +3 -3
  66. package/dist/source-map-uploader-MMJ2WCL4.js.map +1 -0
  67. package/package.json +13 -1
  68. package/dist/chunk-JJL2M64Z.js.map +0 -1
  69. /package/dist/{source-map-uploader-XFUEVV7I.js.map → async-context/index.js.map} +0 -0
  70. /package/dist/{chunk-WL6BXEJ5.js.map → chunk-DKV53A2C.js.map} +0 -0
  71. /package/dist/{chunk-3PJP5Y3U.js.map → chunk-GWIEUBFR.js.map} +0 -0
  72. /package/dist/{chunk-H57MQGNU.js.map → chunk-H6WJ63X2.js.map} +0 -0
  73. /package/dist/{chunk-NN5YCETI.js.map → chunk-HD6JIFKN.js.map} +0 -0
  74. /package/dist/{chunk-UQKI476D.js.map → chunk-M6EWJCAT.js.map} +0 -0
  75. /package/dist/{chunk-M2TLX6NM.js.map → chunk-QXITSNYM.js.map} +0 -0
@@ -1,6 +1,9 @@
1
- export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './edge-entry-DaeG7D7S.cjs';
2
- import './index.d-Dq33YwFT.cjs';
1
+ export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-NAapJ5jn.cjs';
2
+ export { RequestMiddlewareFunction, TracedRequestMiddlewareOptions, tracedRequestMiddleware } from './middleware/index.cjs';
3
+ export { WithAsyncCausalityOptions, withAsyncCausality } from './async-context/index.cjs';
4
+ import './index.d-CkTf_boH.cjs';
3
5
  import './v4/classic/external.cjs';
4
6
  import './export/ReadableSpan';
5
7
  import './Span';
6
8
  import './SpanProcessor';
9
+ import './common/Attributes';
@@ -1,6 +1,9 @@
1
- export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './edge-entry-AWO70gje.js';
2
- import './index.d-Dq33YwFT.js';
1
+ export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-B_K8adD6.js';
2
+ export { RequestMiddlewareFunction, TracedRequestMiddlewareOptions, tracedRequestMiddleware } from './middleware/index.js';
3
+ export { WithAsyncCausalityOptions, withAsyncCausality } from './async-context/index.js';
4
+ import './index.d-CkTf_boH.js';
3
5
  import './v4/classic/external.cjs';
4
6
  import './export/ReadableSpan';
5
7
  import './Span';
6
8
  import './SpanProcessor';
9
+ import './common/Attributes';
@@ -1,14 +1,23 @@
1
+ import {
2
+ tracedRequestMiddleware
3
+ } from "./chunk-QHV7NFON.js";
4
+ import {
5
+ withAsyncCausality
6
+ } from "./chunk-RQ5BIWDT.js";
1
7
  import {
2
8
  GlasstraceSpanProcessor,
3
9
  SdkError,
4
10
  captureCorrelationId
5
- } from "./chunk-H57MQGNU.js";
11
+ } from "./chunk-H6WJ63X2.js";
12
+ import "./chunk-CL3OVHPO.js";
6
13
  import "./chunk-DQ25VOKK.js";
7
- import "./chunk-P45NZR4J.js";
14
+ import "./chunk-JHUNLPSS.js";
8
15
  import "./chunk-NSBPE2FW.js";
9
16
  export {
10
17
  GlasstraceSpanProcessor,
11
18
  SdkError,
12
- captureCorrelationId
19
+ captureCorrelationId,
20
+ tracedRequestMiddleware,
21
+ withAsyncCausality
13
22
  };
14
23
  //# sourceMappingURL=edge-entry.js.map
package/dist/index.cjs CHANGED
@@ -14683,6 +14683,40 @@ var init_dist = __esm({
14683
14683
  ELEMENT_FINGERPRINT: "glasstrace.element.fingerprint",
14684
14684
  ELEMENT_CONFIDENCE: "glasstrace.element.confidence",
14685
14685
  TAB_ID: "glasstrace.tab.id",
14686
+ // Causal evidence (SDK-046 / DISC-1537 + DISC-1539).
14687
+ //
14688
+ // The SDK emits `glasstrace.causal.*` attributes on spans that
14689
+ // carry instrumentation-time evidence about a span's relationship
14690
+ // to its owning request trace. Two families are defined here:
14691
+ //
14692
+ // - `MIDDLEWARE_FOR_REQUEST` — middleware-ownership marker. Set
14693
+ // on a middleware-only span by `tracedRequestMiddleware()` from
14694
+ // `@glasstrace/sdk/middleware`. Carries the originating
14695
+ // request's normalized path so the product-side trace-summary
14696
+ // transform can link the middleware span to the owning HTTP
14697
+ // request trace even when the middleware runs in an edge
14698
+ // runtime that does not propagate AsyncLocalStorage parents.
14699
+ //
14700
+ // - `POST_RESPONSE_ASYNC` — post-response async marker. Set on a
14701
+ // span emitted from inside `withAsyncCausality()` from
14702
+ // `@glasstrace/sdk/async-context`. Carries the originating
14703
+ // request's trace ID (32-character hex) captured at the call
14704
+ // site so async work scheduled via Next.js `after()`, queues,
14705
+ // or webhooks can be linked back to its originating request.
14706
+ // Companion booleans `CAUSAL_AFFECTS_HTTP_STATUS` /
14707
+ // `CAUSAL_AFFECTS_HTTP_DURATION` document whether the async
14708
+ // work participates in the root request's outcome (default
14709
+ // `false` — non-outcome async work).
14710
+ //
14711
+ // Wire keys live under the `glasstrace.causal.*` namespace so they
14712
+ // are namespace-distinct from `glasstrace.error.*`,
14713
+ // `glasstrace.http.*`, `glasstrace.trpc.*`, and the side-effect
14714
+ // family below. Adding these constants is a `@glasstrace/protocol`
14715
+ // minor bump; existing entries are untouched.
14716
+ CAUSAL_MIDDLEWARE_FOR_REQUEST: "glasstrace.causal.middleware_for_request",
14717
+ CAUSAL_POST_RESPONSE_ASYNC: "glasstrace.causal.post_response_async",
14718
+ CAUSAL_AFFECTS_HTTP_STATUS: "glasstrace.causal.affects_http_status",
14719
+ CAUSAL_AFFECTS_HTTP_DURATION: "glasstrace.causal.affects_http_duration",
14686
14720
  // Side-effect evidence (SDK-049 / SCHEMA-036).
14687
14721
  // Top-level operation attributes attached to the active span when a
14688
14722
  // side-effect is recorded via `recordSideEffect()`. The wire-string
@@ -18896,6 +18930,16 @@ function getCoexistenceState() {
18896
18930
  return coexistenceState;
18897
18931
  }
18898
18932
 
18933
+ // src/optional-lifecycle.ts
18934
+ var EMIT_BRIDGE = /* @__PURE__ */ Symbol.for("glasstrace.lifecycle.emit-bridge");
18935
+ function _registerLifecycleEmitForBridge(emit) {
18936
+ try {
18937
+ const slot = { emit };
18938
+ globalThis[EMIT_BRIDGE] = slot;
18939
+ } catch {
18940
+ }
18941
+ }
18942
+
18899
18943
  // src/lifecycle.ts
18900
18944
  var CoreState = {
18901
18945
  IDLE: "IDLE",
@@ -18990,6 +19034,12 @@ function initLifecycle(options) {
18990
19034
  }
18991
19035
  _logger = options.logger;
18992
19036
  _initialized = true;
19037
+ _registerLifecycleEmitForBridge((event, payload) => {
19038
+ emitLifecycleEvent(
19039
+ event,
19040
+ payload
19041
+ );
19042
+ });
18993
19043
  }
18994
19044
  function warnIfNotInitialized() {
18995
19045
  if (!_initialized && !_initWarned) {
@@ -23473,11 +23523,11 @@ function registerGlasstrace(options) {
23473
23523
  setCoreState(CoreState.REGISTERING);
23474
23524
  maybeWarnStaleAgentInstructions({
23475
23525
  projectRoot: process.cwd(),
23476
- sdkVersion: "1.8.0"
23526
+ sdkVersion: "1.9.0"
23477
23527
  });
23478
23528
  startRuntimeStateWriter({
23479
23529
  projectRoot: process.cwd(),
23480
- sdkVersion: "1.8.0"
23530
+ sdkVersion: "1.9.0"
23481
23531
  });
23482
23532
  const config2 = resolveConfig(options);
23483
23533
  if (config2.verbose) {
@@ -23644,8 +23694,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
23644
23694
  if (config2.verbose) {
23645
23695
  console.info("[glasstrace] Background init firing.");
23646
23696
  }
23647
- const healthReport = collectHealthReport("1.8.0");
23648
- const initResult = await performInit(config2, anonKeyForInit, "1.8.0", healthReport);
23697
+ const healthReport = collectHealthReport("1.9.0");
23698
+ const initResult = await performInit(config2, anonKeyForInit, "1.9.0", healthReport);
23649
23699
  if (generation !== registrationGeneration) return;
23650
23700
  const currentState = getCoreState();
23651
23701
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -23668,7 +23718,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
23668
23718
  }
23669
23719
  maybeInstallConsoleCapture();
23670
23720
  if (didLastInitSucceed()) {
23671
- startHeartbeat(config2, anonKeyForInit, "1.8.0", generation, (newApiKey, accountId) => {
23721
+ startHeartbeat(config2, anonKeyForInit, "1.9.0", generation, (newApiKey, accountId) => {
23672
23722
  setAuthState(AuthState.CLAIMING);
23673
23723
  emitLifecycleEvent("auth:claim_started", { accountId });
23674
23724
  setResolvedApiKey(newApiKey);