brass-runtime 1.17.0 → 1.18.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 (120) hide show
  1. package/README.md +36 -3
  2. package/dist/agent/cli/main.cjs +31 -32
  3. package/dist/agent/cli/main.js +3 -4
  4. package/dist/agent/cli/main.mjs +3 -4
  5. package/dist/agent/index.cjs +4 -5
  6. package/dist/agent/index.d.ts +1 -1
  7. package/dist/agent/index.js +3 -4
  8. package/dist/agent/index.mjs +3 -4
  9. package/dist/{chunk-7X3K5RMS.js → chunk-22HZQG5F.js} +9 -11
  10. package/dist/{chunk-GLE2WY7Z.cjs → chunk-2JHJ4YHS.cjs} +417 -124
  11. package/dist/{chunk-Q2I37RP3.cjs → chunk-2OW6IFY2.cjs} +44 -323
  12. package/dist/{chunk-7ZPEZ57L.cjs → chunk-5LC7V2OZ.cjs} +18 -20
  13. package/dist/{chunk-AGR5B2BC.cjs → chunk-5RZ7YITF.cjs} +564 -12
  14. package/dist/{chunk-DNFJLJMW.mjs → chunk-6MLAZPBL.mjs} +48 -24
  15. package/dist/{chunk-EJ6BPYVR.mjs → chunk-6V2AWT4R.mjs} +1 -1
  16. package/dist/{chunk-3AYM6WPJ.js → chunk-7DU7IQHK.js} +20 -299
  17. package/dist/{chunk-SK7UZRNI.mjs → chunk-7GBJYOX7.mjs} +528 -23
  18. package/dist/chunk-7TKI527D.cjs +123 -0
  19. package/dist/{chunk-52OB2ROS.js → chunk-7VQLEN37.js} +2 -4
  20. package/dist/{chunk-KH4SYAOS.mjs → chunk-B5FKOLTB.mjs} +20 -299
  21. package/dist/{chunk-FHQGHPMO.mjs → chunk-BC6Q6BCO.mjs} +2 -4
  22. package/dist/{chunk-4P2HHGAX.mjs → chunk-COOW7BJX.mjs} +32 -11
  23. package/dist/{chunk-2HQTDLHF.mjs → chunk-EEN5OTCR.mjs} +555 -3
  24. package/dist/{chunk-KZJQ723N.cjs → chunk-EICAJDNX.cjs} +13 -15
  25. package/dist/chunk-ELIECDYN.cjs +33 -0
  26. package/dist/{chunk-GYM3LLGS.mjs → chunk-H626ZTDZ.mjs} +399 -106
  27. package/dist/{chunk-C3MDXTRZ.js → chunk-HCJ4S3YB.js} +48 -24
  28. package/dist/{chunk-7JIJOVCT.js → chunk-IPSMXUWA.js} +2 -4
  29. package/dist/{chunk-4ROBZFL6.cjs → chunk-J6DUHITE.cjs} +6 -8
  30. package/dist/{chunk-6RY2FFN4.mjs → chunk-JWIEMBE6.mjs} +9 -11
  31. package/dist/{chunk-PD4EJTQC.cjs → chunk-KNTJ7FQB.cjs} +5 -5
  32. package/dist/chunk-KTGDLBLD.mjs +123 -0
  33. package/dist/chunk-LSYQ3C2M.js +33 -0
  34. package/dist/{chunk-RKGKFN2A.js → chunk-OW5VHAOE.js} +1 -1
  35. package/dist/{chunk-EOC4UHBS.mjs → chunk-RBHNOKH4.mjs} +2 -2
  36. package/dist/{chunk-6IXXWIUM.js → chunk-S4HXADU4.js} +555 -3
  37. package/dist/{chunk-FH2X7BVP.js → chunk-TTSPIU3U.js} +399 -106
  38. package/dist/{chunk-5QC7LRZ3.js → chunk-UAKAF32U.js} +2 -2
  39. package/dist/{chunk-CZIVE6NT.cjs → chunk-UUMKZJRJ.cjs} +48 -24
  40. package/dist/{chunk-MBEJI5HF.mjs → chunk-WCBNXPN6.mjs} +2 -4
  41. package/dist/{chunk-52PPNNI4.cjs → chunk-WGE2FEZE.cjs} +2 -2
  42. package/dist/{chunk-WBGRHGBP.cjs → chunk-WI7GZF3B.cjs} +114 -93
  43. package/dist/chunk-WUDHOZIH.js +6234 -0
  44. package/dist/{chunk-F6XWZQY4.cjs → chunk-WVSZOPGQ.cjs} +583 -78
  45. package/dist/chunk-XPIMJQYS.cjs +6234 -0
  46. package/dist/{chunk-VWIPB6I5.js → chunk-YGR2IN4R.js} +528 -23
  47. package/dist/chunk-YM3EDNYD.js +123 -0
  48. package/dist/chunk-YWLLH27R.mjs +33 -0
  49. package/dist/{chunk-BKK77SBA.js → chunk-YZ5LQ32F.js} +32 -11
  50. package/dist/chunk-Z3ZZMQUZ.mjs +6234 -0
  51. package/dist/core/index.cjs +37 -9
  52. package/dist/core/index.d.ts +19 -152
  53. package/dist/core/index.js +86 -58
  54. package/dist/core/index.mjs +86 -58
  55. package/dist/defaultClient-Cid0JoUR.d.ts +1648 -0
  56. package/dist/{effect-DIUHZ9IN.d.ts → effect-DnGUuhw6.d.ts} +22 -1
  57. package/dist/http/index.cjs +206 -59
  58. package/dist/http/index.d.ts +55 -819
  59. package/dist/http/index.js +220 -73
  60. package/dist/http/index.mjs +220 -73
  61. package/dist/http/testing.cjs +31 -10
  62. package/dist/http/testing.d.ts +16 -5
  63. package/dist/http/testing.js +29 -8
  64. package/dist/http/testing.mjs +29 -8
  65. package/dist/index.cjs +116 -88
  66. package/dist/index.d.ts +9 -8
  67. package/dist/index.js +87 -59
  68. package/dist/index.mjs +87 -59
  69. package/dist/{schedule-CK3Ml_7p.d.ts → layer-D2LFcBVx.d.ts} +176 -2
  70. package/dist/observability/index.cjs +20 -7
  71. package/dist/observability/index.d.ts +32 -8
  72. package/dist/observability/index.js +19 -6
  73. package/dist/observability/index.mjs +19 -6
  74. package/dist/perf/cli.cjs +26 -28
  75. package/dist/perf/cli.js +11 -13
  76. package/dist/perf/cli.mjs +11 -13
  77. package/dist/perf/index.cjs +13 -15
  78. package/dist/perf/index.js +11 -13
  79. package/dist/perf/index.mjs +11 -13
  80. package/dist/schema/index.cjs +2 -2
  81. package/dist/schema/index.js +1 -1
  82. package/dist/schema/index.mjs +1 -1
  83. package/dist/{server-D6JZ15_e.d.ts → server-Bf1zNYZk.d.ts} +5 -5
  84. package/dist/{stream-B4oK9JFP.d.ts → stream-I7bkvF7a.d.ts} +1 -1
  85. package/dist/{tracer-Hwt1cl7h.d.ts → tracer-DF83nLn6.d.ts} +2 -2
  86. package/dist/{tracing-DqbTKGcf.d.ts → tracing-CWV4gT0u.d.ts} +1 -1
  87. package/docs/README.md +2 -0
  88. package/docs/ai/PUBLIC_API.md +28 -7
  89. package/docs/articles/brass-runtime-http-observability.md +467 -0
  90. package/docs/frameworks/angular.md +51 -0
  91. package/docs/frameworks/express.md +58 -0
  92. package/docs/frameworks/fastify.md +49 -0
  93. package/docs/frameworks/nestjs.md +53 -0
  94. package/docs/frameworks/nextjs.md +55 -0
  95. package/docs/frameworks/react.md +44 -0
  96. package/docs/frameworks/vanilla.md +56 -0
  97. package/docs/guides/layers.md +130 -0
  98. package/docs/http-recipes.md +31 -1
  99. package/docs/http.md +50 -1
  100. package/docs/observability.md +132 -0
  101. package/docs/performance-profiler.md +6 -2
  102. package/docs/recipes/layers.md +46 -2
  103. package/docs/recipes/testing.md +25 -0
  104. package/package.json +6 -2
  105. package/dist/chunk-3LOYJFRR.cjs +0 -300
  106. package/dist/chunk-3Y2RIUMM.js +0 -300
  107. package/dist/chunk-5EC274J5.cjs +0 -2874
  108. package/dist/chunk-5VRJNBLZ.mjs +0 -2874
  109. package/dist/chunk-62AZW6UT.cjs +0 -313
  110. package/dist/chunk-74ZTY6CP.js +0 -2871
  111. package/dist/chunk-7CMJS3QE.mjs +0 -2871
  112. package/dist/chunk-A2OM6NEH.mjs +0 -194
  113. package/dist/chunk-B33ICAKP.js +0 -313
  114. package/dist/chunk-JF5WGYJJ.cjs +0 -194
  115. package/dist/chunk-KN32XNTH.mjs +0 -313
  116. package/dist/chunk-KQLYONSE.cjs +0 -2871
  117. package/dist/chunk-L2SYFEBS.js +0 -194
  118. package/dist/chunk-MIIYDLGM.js +0 -2874
  119. package/dist/chunk-PWC3RBQE.mjs +0 -300
  120. package/dist/client-CZHU674n.d.ts +0 -820
@@ -0,0 +1,123 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkMVGUEJ5Zcjs = require('./chunk-MVGUEJ5Z.cjs');
6
+
7
+ // src/core/runtime/circuitBreaker.ts
8
+ function makeCircuitBreaker(config = {}) {
9
+ const failureThreshold = _nullishCoalesce(config.failureThreshold, () => ( 5));
10
+ const resetTimeoutMs = _nullishCoalesce(config.resetTimeoutMs, () => ( 3e4));
11
+ const successThreshold = _nullishCoalesce(config.successThreshold, () => ( 1));
12
+ const isFailure = _nullishCoalesce(config.isFailure, () => ( (() => true)));
13
+ const onStateChange = config.onStateChange;
14
+ let currentState = "closed";
15
+ let consecutiveFailures = 0;
16
+ let consecutiveSuccesses = 0;
17
+ let openedAt = 0;
18
+ let totalRequests = 0;
19
+ let totalFailures = 0;
20
+ let totalSuccesses = 0;
21
+ let totalRejected = 0;
22
+ let lastFailureTime = null;
23
+ let lastSuccessTime = null;
24
+ const transition = (to) => {
25
+ if (currentState === to) return;
26
+ const from = currentState;
27
+ currentState = to;
28
+ _optionalChain([onStateChange, 'optionalCall', _ => _(from, to)]);
29
+ };
30
+ const onSuccess = () => {
31
+ totalSuccesses++;
32
+ lastSuccessTime = Date.now();
33
+ consecutiveFailures = 0;
34
+ if (currentState === "half-open") {
35
+ consecutiveSuccesses++;
36
+ if (consecutiveSuccesses >= successThreshold) {
37
+ consecutiveSuccesses = 0;
38
+ transition("closed");
39
+ }
40
+ }
41
+ };
42
+ const onFailure = (error) => {
43
+ if (!isFailure(error)) {
44
+ onSuccess();
45
+ return;
46
+ }
47
+ totalFailures++;
48
+ lastFailureTime = Date.now();
49
+ consecutiveSuccesses = 0;
50
+ consecutiveFailures++;
51
+ if (currentState === "half-open") {
52
+ openedAt = Date.now();
53
+ transition("open");
54
+ } else if (currentState === "closed" && consecutiveFailures >= failureThreshold) {
55
+ openedAt = Date.now();
56
+ transition("open");
57
+ }
58
+ };
59
+ const shouldAllow = () => {
60
+ switch (currentState) {
61
+ case "closed":
62
+ return true;
63
+ case "open": {
64
+ const elapsed = Date.now() - openedAt;
65
+ if (elapsed >= resetTimeoutMs) {
66
+ transition("half-open");
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+ case "half-open":
72
+ return true;
73
+ }
74
+ };
75
+ const protect = (effect) => {
76
+ totalRequests++;
77
+ if (!shouldAllow()) {
78
+ totalRejected++;
79
+ return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, {
80
+ _tag: "CircuitBreakerOpen",
81
+ openSince: openedAt,
82
+ failures: consecutiveFailures
83
+ });
84
+ }
85
+ return _chunkMVGUEJ5Zcjs.asyncFold.call(void 0,
86
+ effect,
87
+ (error) => {
88
+ onFailure(error);
89
+ return _chunkMVGUEJ5Zcjs.asyncFail.call(void 0, error);
90
+ },
91
+ (value) => {
92
+ onSuccess();
93
+ return _chunkMVGUEJ5Zcjs.asyncSucceed.call(void 0, value);
94
+ }
95
+ );
96
+ };
97
+ const stats = () => ({
98
+ state: currentState,
99
+ failures: consecutiveFailures,
100
+ successes: consecutiveSuccesses,
101
+ totalRequests,
102
+ totalFailures,
103
+ totalSuccesses,
104
+ totalRejected,
105
+ lastFailureTime,
106
+ lastSuccessTime
107
+ });
108
+ const reset = () => {
109
+ consecutiveFailures = 0;
110
+ consecutiveSuccesses = 0;
111
+ transition("closed");
112
+ };
113
+ return {
114
+ state: () => currentState,
115
+ protect,
116
+ stats,
117
+ reset
118
+ };
119
+ }
120
+
121
+
122
+
123
+ exports.makeCircuitBreaker = makeCircuitBreaker;
@@ -2,11 +2,9 @@ import {
2
2
  race
3
3
  } from "./chunk-UCUBNWM2.js";
4
4
  import {
5
+ fromPromiseAbortable,
5
6
  withScopeAsync
6
- } from "./chunk-L2SYFEBS.js";
7
- import {
8
- fromPromiseAbortable
9
- } from "./chunk-FH2X7BVP.js";
7
+ } from "./chunk-TTSPIU3U.js";
10
8
  import {
11
9
  Cause,
12
10
  Exit,
@@ -1,12 +1,10 @@
1
1
  import {
2
- ensuring
3
- } from "./chunk-KN32XNTH.mjs";
2
+ makeRuntimeEventRecord
3
+ } from "./chunk-6V2AWT4R.mjs";
4
4
  import {
5
+ layerEffect,
5
6
  makeScheduleDriver
6
- } from "./chunk-2HQTDLHF.mjs";
7
- import {
8
- makeRuntimeEventRecord
9
- } from "./chunk-EJ6BPYVR.mjs";
7
+ } from "./chunk-EEN5OTCR.mjs";
10
8
  import {
11
9
  Runtime,
12
10
  getCurrentFiber,
@@ -14,7 +12,7 @@ import {
14
12
  runtimeClockFromEnv,
15
13
  toPromise,
16
14
  unsafeRunAsync
17
- } from "./chunk-GYM3LLGS.mjs";
15
+ } from "./chunk-H626ZTDZ.mjs";
18
16
  import {
19
17
  Cause,
20
18
  Exit,
@@ -24,9 +22,11 @@ import {
24
22
  asyncFold,
25
23
  asyncMap,
26
24
  asyncSucceed,
27
- asyncSync,
28
- unit
25
+ asyncSync
29
26
  } from "./chunk-36I3M4UC.mjs";
27
+ import {
28
+ parseConfig
29
+ } from "./chunk-6MLAZPBL.mjs";
30
30
 
31
31
  // src/core/types/cancel.ts
32
32
  function makeCancelToken() {
@@ -636,275 +636,19 @@ function neverEffect() {
636
636
  });
637
637
  }
638
638
 
639
- // src/core/runtime/layer.ts
640
- var MissingLayerServiceError = class extends Error {
641
- _tag = "MissingLayerService";
642
- serviceName;
643
- constructor(serviceName) {
644
- super(`Missing layer service '${serviceName}'. Add a layer that provides this ServiceTag or pass a LayerContext containing it.`);
645
- this.name = "MissingLayerServiceError";
646
- this.serviceName = serviceName;
647
- }
648
- };
649
- function formatLayerError(error) {
650
- if (error instanceof MissingLayerServiceError) return error.message;
651
- if (isObjectRecord(error) && error._tag === "MissingLayerService" && typeof error.serviceName === "string") {
652
- return `Missing layer service '${error.serviceName}'. Add the provider layer before using the service.`;
653
- }
654
- return error instanceof Error ? error.message : String(error);
655
- }
656
- function makeServiceTag(name) {
657
- return {
658
- _tag: "ServiceTag",
659
- key: Symbol(name),
660
- name
661
- };
662
- }
663
- var serviceTag = makeServiceTag;
664
- var defineService = makeServiceTag;
665
- var LayerContext = class _LayerContext {
666
- services;
667
- constructor(entries) {
668
- if (entries instanceof Map) {
669
- this.services = new Map(entries);
670
- return;
671
- }
672
- this.services = /* @__PURE__ */ new Map();
673
- if (!entries) return;
674
- for (const [tag, service] of entries) this.services.set(tag.key, service);
675
- }
676
- static empty() {
677
- return new _LayerContext();
678
- }
679
- get(tag) {
680
- return this.services.get(tag.key);
681
- }
682
- unsafeGet(tag) {
683
- if (!this.services.has(tag.key)) {
684
- throw new MissingLayerServiceError(tag.name);
685
- }
686
- return this.services.get(tag.key);
687
- }
688
- has(tag) {
689
- return this.services.has(tag.key);
690
- }
691
- add(tag, service) {
692
- const next = new Map(this.services);
693
- next.set(tag.key, service);
694
- return new _LayerContext(next);
695
- }
696
- merge(other) {
697
- const next = new Map(this.services);
698
- for (const [key, service] of other.services) next.set(key, service);
699
- return new _LayerContext(next);
700
- }
701
- size() {
702
- return this.services.size;
703
- }
704
- };
705
- function makeLayerScope() {
706
- const cache = /* @__PURE__ */ new WeakMap();
707
- const finalizers = [];
708
- let closed = false;
709
- const scope = {
710
- get: (l, deps) => {
711
- if (closed) return asyncFail(new Error("LayerScope is closed"));
712
- if (cache.has(l)) return asyncSucceed(cache.get(l));
713
- const built = l.buildScoped ? l.buildScoped(deps, scope) : asyncFlatMap(
714
- l.build(deps),
715
- ({ service, release }) => asyncFlatMap(scope.addFinalizer(release), () => asyncSucceed(service))
716
- );
717
- return asyncFlatMap(
718
- built,
719
- (service) => asyncSync(() => {
720
- cache.set(l, service);
721
- return service;
722
- })
723
- );
724
- },
725
- close: () => {
726
- if (closed) return unit();
727
- closed = true;
728
- return releaseAll(finalizers);
729
- },
730
- size: () => finalizers.length,
731
- addFinalizer: (release) => asyncSync(() => {
732
- if (!closed) finalizers.push(release);
733
- })
734
- };
735
- return scope;
736
- }
737
- function releaseAll(finalizers) {
738
- const next = finalizers.pop();
739
- if (!next) return unit();
740
- return asyncFold(
741
- next(),
742
- () => releaseAll(finalizers),
743
- () => releaseAll(finalizers)
744
- );
745
- }
746
- function mergeServices(a, b) {
747
- if (a instanceof LayerContext && b instanceof LayerContext) {
748
- return a.merge(b);
749
- }
750
- if (isObjectRecord(a) && isObjectRecord(b)) {
751
- return { ...a, ...b };
752
- }
753
- return Object.assign({}, a, b);
754
- }
755
- function isObjectRecord(value) {
756
- return typeof value === "object" && value !== null;
757
- }
758
- function layer(acquire, release) {
759
- return {
760
- _tag: "Layer",
761
- build: (_deps) => asyncFlatMap(acquire(), (service) => asyncSucceed({
762
- service,
763
- release: release ? () => release(service) : () => unit()
764
- }))
765
- };
766
- }
767
- function layerValue(tag, value) {
768
- return layerEffect(tag, () => asyncSucceed(value));
769
- }
770
- function layerEffect(tag, acquire, release) {
771
- return {
772
- _tag: "Layer",
773
- build: (deps = LayerContext.empty()) => asyncFlatMap(acquire(deps), (service) => asyncSucceed({
774
- service: deps.add(tag, service),
775
- release: release ? () => release(service) : () => unit()
776
- }))
777
- };
778
- }
779
- var layerFromContext = layerEffect;
780
- var defineLayer = layerEffect;
781
- function getService(tag) {
782
- return asyncSync((context) => context.unsafeGet(tag));
783
- }
784
- function layerFrom() {
785
- return (acquire, release) => ({
786
- _tag: "Layer",
787
- build: (deps) => asyncFlatMap(acquire(deps), (service) => asyncSucceed({
788
- service,
789
- release: release ? () => release(service) : () => unit()
790
- }))
791
- });
792
- }
793
- function layerSucceed(value) {
794
- return {
795
- _tag: "Layer",
796
- build: () => asyncSucceed({ service: value, release: () => unit() })
797
- };
798
- }
799
- function layerFail(error) {
800
- return {
801
- _tag: "Layer",
802
- build: () => asyncFail(error)
803
- };
804
- }
805
- function compose(from, to) {
806
- return {
807
- _tag: "Layer",
808
- buildScoped: (deps, scope) => asyncFlatMap(
809
- scope.get(from, deps),
810
- (mid) => scope.get(to, mid)
811
- ),
812
- build: (deps) => asyncFlatMap(
813
- from.build(deps),
814
- ({ service: mid, release: releaseMid }) => asyncFold(
815
- to.build(mid),
816
- (error) => asyncFlatMap(releaseMid(), () => asyncFail(error)),
817
- ({ service: out, release: releaseOut }) => asyncSucceed({
818
- service: out,
819
- release: () => asyncFlatMap(releaseOut(), () => releaseMid())
820
- })
821
- )
822
- )
823
- };
824
- }
825
- function merge(left, right) {
826
- return {
827
- _tag: "Layer",
828
- buildScoped: (deps, scope) => asyncFlatMap(
829
- scope.get(left, deps),
830
- (a) => asyncFlatMap(
831
- scope.get(right, deps),
832
- (b) => asyncSucceed(mergeServices(a, b))
833
- )
834
- ),
835
- build: (deps) => asyncFlatMap(
836
- left.build(deps),
837
- ({ service: a, release: releaseA }) => asyncFold(
838
- right.build(deps),
839
- (error) => asyncFlatMap(releaseA(), () => asyncFail(error)),
840
- ({ service: b, release: releaseB }) => asyncSucceed({
841
- service: mergeServices(a, b),
842
- release: () => asyncFlatMap(releaseB(), () => releaseA())
843
- })
844
- )
845
- )
846
- };
847
- }
848
- function mapLayer(l, f) {
849
- return {
850
- _tag: "Layer",
851
- buildScoped: (deps, scope) => asyncFlatMap(
852
- scope.get(l, deps),
853
- (service) => asyncSucceed(f(service))
854
- ),
855
- build: (deps) => asyncFlatMap(
856
- l.build(deps),
857
- ({ service, release }) => asyncSucceed({ service: f(service), release })
639
+ // src/core/runtime/configLayer.ts
640
+ function makeConfigLayer(tag, schema, source, options = {}) {
641
+ return layerEffect(
642
+ tag,
643
+ (context) => asyncSync(
644
+ () => parseConfig(options.name ?? tag.name, schema, readConfigSource(source, context))
858
645
  )
859
- };
860
- }
861
- function buildLayer(l, deps) {
862
- const scope = makeLayerScope();
863
- return asyncFold(
864
- scope.get(l, deps),
865
- (error) => asyncFlatMap(scope.close(), () => asyncFail(error)),
866
- (service) => asyncSucceed({
867
- service,
868
- scope,
869
- close: scope.close,
870
- use: (body) => body(service)
871
- })
872
646
  );
873
647
  }
874
- function provideLayer(l, use, deps) {
875
- return asyncFlatMap(
876
- buildLayer(l, deps ?? {}),
877
- ({ service, close }) => ensuring(
878
- use(service),
879
- () => close()
880
- )
881
- );
648
+ var defineConfigLayer = makeConfigLayer;
649
+ function readConfigSource(source, context) {
650
+ return typeof source === "function" ? source(context) : source;
882
651
  }
883
- function provideLayerContext(l, use, deps = LayerContext.empty()) {
884
- return provideLayer(l, use, deps);
885
- }
886
- var provide = provideLayer;
887
- var provideContext = provideLayerContext;
888
- var Layer = Object.freeze({
889
- make: layer,
890
- from: layerFrom,
891
- succeed: layerSucceed,
892
- fail: layerFail,
893
- value: layerValue,
894
- effect: layerEffect,
895
- define: defineLayer,
896
- fromContext: layerFromContext,
897
- compose,
898
- merge,
899
- map: mapLayer,
900
- provide: provideLayer,
901
- provideContext: provideLayerContext,
902
- build: buildLayer,
903
- scope: makeLayerScope,
904
- context: LayerContext.empty,
905
- tag: makeServiceTag,
906
- service: getService
907
- });
908
652
 
909
653
  // src/core/runtime/workerPool.ts
910
654
  function makeWorkerPool(config = {}) {
@@ -1586,31 +1330,8 @@ export {
1586
1330
  flakyEffect,
1587
1331
  delayedEffect,
1588
1332
  neverEffect,
1589
- MissingLayerServiceError,
1590
- formatLayerError,
1591
- makeServiceTag,
1592
- serviceTag,
1593
- defineService,
1594
- LayerContext,
1595
- makeLayerScope,
1596
- layer,
1597
- layerValue,
1598
- layerEffect,
1599
- layerFromContext,
1600
- defineLayer,
1601
- getService,
1602
- layerFrom,
1603
- layerSucceed,
1604
- layerFail,
1605
- compose,
1606
- merge,
1607
- mapLayer,
1608
- buildLayer,
1609
- provideLayer,
1610
- provideLayerContext,
1611
- provide,
1612
- provideContext,
1613
- Layer,
1333
+ makeConfigLayer,
1334
+ defineConfigLayer,
1614
1335
  makeWorkerPool,
1615
1336
  makeTracer,
1616
1337
  consoleJsonLogger,
@@ -2,13 +2,11 @@ import {
2
2
  raceWith
3
3
  } from "./chunk-B5JD23U7.mjs";
4
4
  import {
5
- Scope
6
- } from "./chunk-A2OM6NEH.mjs";
7
- import {
5
+ Scope,
8
6
  getCurrentFiber,
9
7
  unsafeGetCurrentRuntime,
10
8
  unsafeRunFoldWithEnv
11
- } from "./chunk-GYM3LLGS.mjs";
9
+ } from "./chunk-H626ZTDZ.mjs";
12
10
  import {
13
11
  Cause,
14
12
  Exit,
@@ -2,14 +2,14 @@ import {
2
2
  EventBus,
3
3
  InMemoryTracer,
4
4
  makeMetrics
5
- } from "./chunk-EJ6BPYVR.mjs";
5
+ } from "./chunk-6V2AWT4R.mjs";
6
6
  import {
7
7
  Runtime,
8
8
  ctxExtend,
9
9
  ctxToObject,
10
10
  emptyContext,
11
11
  getCurrentFiber
12
- } from "./chunk-GYM3LLGS.mjs";
12
+ } from "./chunk-H626ZTDZ.mjs";
13
13
  import {
14
14
  asyncFail,
15
15
  asyncFlatMap,
@@ -20,7 +20,7 @@ import {
20
20
  import {
21
21
  Schema,
22
22
  parseConfig
23
- } from "./chunk-DNFJLJMW.mjs";
23
+ } from "./chunk-6MLAZPBL.mjs";
24
24
 
25
25
  // src/observability/health.ts
26
26
  function snapshotRuntimeHealth(options = {}) {
@@ -881,24 +881,25 @@ function normalizeLogAttributes(fields) {
881
881
  }
882
882
 
883
883
  // src/observability/sampling.ts
884
- var alwaysOnSampler = {
884
+ var TRACE_SAMPLER_RATIO = /* @__PURE__ */ Symbol.for("brass-runtime.traceSampler.ratio");
885
+ var alwaysOnSampler = withRatio({
885
886
  shouldSample: () => true
886
- };
887
- var alwaysOffSampler = {
887
+ }, 1);
888
+ var alwaysOffSampler = withRatio({
888
889
  shouldSample: () => false
889
- };
890
+ }, 0);
890
891
  function ratioSampler(ratio2) {
891
892
  const bounded = clampRatio(ratio2);
892
893
  if (bounded >= 1) return alwaysOnSampler;
893
894
  if (bounded <= 0) return alwaysOffSampler;
894
- return {
895
+ return withRatio({
895
896
  shouldSample: (input) => traceRatio(input.traceId) < bounded
896
- };
897
+ }, bounded);
897
898
  }
898
899
  function makeTraceSampler(options = {}) {
899
900
  const fallback = options.sampler ?? ratioSampler(options.ratio ?? 1);
900
901
  const rules = options.rules ?? [];
901
- return {
902
+ const sampler = {
902
903
  shouldSample(input) {
903
904
  for (const rule of rules) {
904
905
  if (!samplingRuleMatches(rule, input)) continue;
@@ -908,6 +909,8 @@ function makeTraceSampler(options = {}) {
908
909
  return shouldSampleWith(fallback, input);
909
910
  }
910
911
  };
912
+ const fallbackRatio = samplerRatio(fallback);
913
+ return rules.length === 0 && fallbackRatio !== void 0 ? withRatio(sampler, fallbackRatio) : sampler;
911
914
  }
912
915
  function resolveTraceSampling(config) {
913
916
  if (config === false) {
@@ -942,6 +945,22 @@ function matchText(pattern, value) {
942
945
  function isTraceSampler(value) {
943
946
  return typeof value === "function" || typeof value === "object" && value !== null && typeof value.shouldSample === "function";
944
947
  }
948
+ function samplerRatio(sampler) {
949
+ if (!sampler || typeof sampler === "function") return void 0;
950
+ const ratio2 = sampler[TRACE_SAMPLER_RATIO];
951
+ return typeof ratio2 === "number" && Number.isFinite(ratio2) ? ratio2 : void 0;
952
+ }
953
+ function withRatio(sampler, ratio2) {
954
+ try {
955
+ Object.defineProperty(sampler, TRACE_SAMPLER_RATIO, {
956
+ configurable: false,
957
+ enumerable: false,
958
+ value: ratio2
959
+ });
960
+ } catch {
961
+ }
962
+ return sampler;
963
+ }
945
964
  function traceRatio(traceId) {
946
965
  const normalized = normalizeTraceId(traceId);
947
966
  const head = normalized.slice(0, 8);
@@ -1538,7 +1557,9 @@ var httpObservabilityOptions = Schema.object({
1538
1557
  Schema.literal(false),
1539
1558
  Schema.object({
1540
1559
  name: Schema.union([Schema.string({ minLength: 1 }), fn]).optional(),
1541
- attributes: Schema.union([object, fn]).optional()
1560
+ attributes: Schema.union([object, fn]).optional(),
1561
+ events: Schema.boolean().optional(),
1562
+ sampleRate: ratio.optional()
1542
1563
  }, { unknownKeys: "passthrough" })
1543
1564
  ]).optional(),
1544
1565
  adaptiveLimiter: Schema.union([