@clayroach/effect 3.19.14-source-capture.7 → 3.19.14-source-trace.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.
- package/SourceLocation/package.json +6 -0
- package/dist/cjs/Effect.js +2 -28
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/FiberRef.js +12 -1
- package/dist/cjs/FiberRef.js.map +1 -1
- package/dist/cjs/Layer.js +2 -24
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/RuntimeFlags.js +1 -29
- package/dist/cjs/RuntimeFlags.js.map +1 -1
- package/dist/cjs/SourceLocation.js +60 -0
- package/dist/cjs/SourceLocation.js.map +1 -0
- package/dist/cjs/Tracer.js +1 -15
- package/dist/cjs/Tracer.js.map +1 -1
- package/dist/cjs/Utils.js +1 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/clock.js +1 -1
- package/dist/cjs/internal/clock.js.map +1 -1
- package/dist/cjs/internal/core.js +17 -50
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js +18 -30
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +16 -65
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/layer/circular.js +1 -5
- package/dist/cjs/internal/layer/circular.js.map +1 -1
- package/dist/cjs/internal/layer.js +1 -3
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/logger.js +25 -2
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/runtimeFlags.js +2 -11
- package/dist/cjs/internal/runtimeFlags.js.map +1 -1
- package/dist/cjs/internal/tracer.js +1 -114
- package/dist/cjs/internal/tracer.js.map +1 -1
- package/dist/dts/Config.d.ts +2 -2
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +8 -29
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/FiberRef.d.ts +12 -0
- package/dist/dts/FiberRef.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +0 -22
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/RuntimeFlags.d.ts +0 -28
- package/dist/dts/RuntimeFlags.d.ts.map +1 -1
- package/dist/dts/SourceLocation.d.ts +88 -0
- package/dist/dts/SourceLocation.d.ts.map +1 -0
- package/dist/dts/Tracer.d.ts +0 -15
- package/dist/dts/Tracer.d.ts.map +1 -1
- package/dist/dts/index.d.ts +6 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/layer.d.ts.map +1 -1
- package/dist/dts/internal/runtimeFlags.d.ts.map +1 -1
- package/dist/esm/Effect.js +0 -26
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/FiberRef.js +11 -0
- package/dist/esm/FiberRef.js.map +1 -1
- package/dist/esm/Layer.js +0 -22
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/RuntimeFlags.js +0 -28
- package/dist/esm/RuntimeFlags.js.map +1 -1
- package/dist/esm/SourceLocation.js +51 -0
- package/dist/esm/SourceLocation.js.map +1 -0
- package/dist/esm/Tracer.js +0 -14
- package/dist/esm/Tracer.js.map +1 -1
- package/dist/esm/Utils.js +1 -1
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/clock.js +1 -1
- package/dist/esm/internal/clock.js.map +1 -1
- package/dist/esm/internal/core.js +12 -45
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/effect/circular.js +18 -30
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +13 -60
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/layer/circular.js +0 -4
- package/dist/esm/internal/layer/circular.js.map +1 -1
- package/dist/esm/internal/layer.js +0 -2
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/logger.js +25 -2
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/runtimeFlags.js +1 -9
- package/dist/esm/internal/runtimeFlags.js.map +1 -1
- package/dist/esm/internal/tracer.js +0 -111
- package/dist/esm/internal/tracer.js.map +1 -1
- package/package.json +12 -1
- package/src/Config.ts +2 -2
- package/src/Effect.ts +8 -30
- package/src/FiberRef.ts +13 -0
- package/src/Layer.ts +0 -23
- package/src/RuntimeFlags.ts +0 -32
- package/src/SourceLocation.ts +108 -0
- package/src/Tracer.ts +0 -16
- package/src/index.ts +7 -0
- package/src/internal/config.ts +2 -2
- package/src/internal/core.ts +22 -106
- package/src/internal/effect/circular.ts +6 -16
- package/src/internal/fiberRuntime.ts +15 -88
- package/src/internal/layer/circular.ts +0 -14
- package/src/internal/layer.ts +0 -4
- package/src/internal/logger.ts +41 -4
- package/src/internal/runtimeFlags.ts +1 -11
- package/src/internal/tracer.ts +0 -143
package/src/Effect.ts
CHANGED
|
@@ -60,6 +60,7 @@ import type * as RuntimeFlagsPatch from "./RuntimeFlagsPatch.js"
|
|
|
60
60
|
import type * as Schedule from "./Schedule.js"
|
|
61
61
|
import * as Scheduler from "./Scheduler.js"
|
|
62
62
|
import type * as Scope from "./Scope.js"
|
|
63
|
+
import type * as SourceLocation from "./SourceLocation.js"
|
|
63
64
|
import type * as Supervisor from "./Supervisor.js"
|
|
64
65
|
import type * as Tracer from "./Tracer.js"
|
|
65
66
|
import type {
|
|
@@ -2781,6 +2782,13 @@ export const gen: {
|
|
|
2781
2782
|
*/
|
|
2782
2783
|
export interface Adapter {
|
|
2783
2784
|
<A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>
|
|
2785
|
+
/**
|
|
2786
|
+
* Overload for source trace injection.
|
|
2787
|
+
* Used by @effect/unplugin to inject source location metadata.
|
|
2788
|
+
*
|
|
2789
|
+
* @since 3.20.0
|
|
2790
|
+
*/
|
|
2791
|
+
<A, E, R>(self: Effect<A, E, R>, trace: SourceLocation.SourceLocation): Effect<A, E, R>
|
|
2784
2792
|
<A, _A, _E, _R>(a: A, ab: (a: A) => Effect<_A, _E, _R>): Effect<_A, _E, _R>
|
|
2785
2793
|
<A, B, _A, _E, _R>(a: A, ab: (a: A) => B, bc: (b: B) => Effect<_A, _E, _R>): Effect<_A, _E, _R>
|
|
2786
2794
|
<A, B, C, _A, _E, _R>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => Effect<_A, _E, _R>): Effect<_A, _E, _R>
|
|
@@ -12945,36 +12953,6 @@ export const withTracerTiming: {
|
|
|
12945
12953
|
<A, E, R>(effect: Effect<A, E, R>, enabled: boolean): Effect<A, E, R>
|
|
12946
12954
|
} = core.withTracerTiming
|
|
12947
12955
|
|
|
12948
|
-
/**
|
|
12949
|
-
* Controls whether source location capture is enabled for forked fibers.
|
|
12950
|
-
*
|
|
12951
|
-
* **Details**
|
|
12952
|
-
*
|
|
12953
|
-
* When enabled, `Effect.fork` and similar operations will capture the call
|
|
12954
|
-
* site (file, line, column) and store it in a FiberRef that can be read by
|
|
12955
|
-
* Supervisors. This enables automatic tracing with meaningful span names
|
|
12956
|
-
* like `"sendEmail (user-handlers.ts:42)"` instead of `"anonymous"`.
|
|
12957
|
-
*
|
|
12958
|
-
* Source capture is disabled by default for performance reasons. Use this
|
|
12959
|
-
* API or `Layer.enableSourceCapture` to enable it for specific scopes.
|
|
12960
|
-
*
|
|
12961
|
-
* @example
|
|
12962
|
-
* ```ts
|
|
12963
|
-
* import { Effect } from "effect"
|
|
12964
|
-
*
|
|
12965
|
-
* Effect.gen(function* () {
|
|
12966
|
-
* yield* Effect.fork(myTask) // Call site is captured
|
|
12967
|
-
* }).pipe(Effect.withCaptureStackTraces(true))
|
|
12968
|
-
* ```
|
|
12969
|
-
*
|
|
12970
|
-
* @since 3.15.0
|
|
12971
|
-
* @category Tracing
|
|
12972
|
-
*/
|
|
12973
|
-
export const withCaptureStackTraces: {
|
|
12974
|
-
(enabled: boolean): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>
|
|
12975
|
-
<A, E, R>(effect: Effect<A, E, R>, enabled: boolean): Effect<A, E, R>
|
|
12976
|
-
} = core.withCaptureStackTraces
|
|
12977
|
-
|
|
12978
12956
|
/**
|
|
12979
12957
|
* Adds annotations to each span in the effect for enhanced traceability.
|
|
12980
12958
|
*
|
package/src/FiberRef.ts
CHANGED
|
@@ -22,6 +22,7 @@ import type * as Request from "./Request.js"
|
|
|
22
22
|
import type * as RuntimeFlags from "./RuntimeFlags.js"
|
|
23
23
|
import * as Scheduler from "./Scheduler.js"
|
|
24
24
|
import type * as Scope from "./Scope.js"
|
|
25
|
+
import type * as SourceLocation from "./SourceLocation.js"
|
|
25
26
|
import type * as Supervisor from "./Supervisor.js"
|
|
26
27
|
import type * as Tracer from "./Tracer.js"
|
|
27
28
|
import type * as Types from "./Types.js"
|
|
@@ -387,6 +388,18 @@ export const currentRuntimeFlags: FiberRef<RuntimeFlags.RuntimeFlags> = fiberRun
|
|
|
387
388
|
*/
|
|
388
389
|
export const currentScheduler: FiberRef<Scheduler.Scheduler> = Scheduler.currentScheduler
|
|
389
390
|
|
|
391
|
+
/**
|
|
392
|
+
* The current source location trace, used for build-time instrumentation.
|
|
393
|
+
*
|
|
394
|
+
* This FiberRef contains the source location of the currently executing effect
|
|
395
|
+
* step within an `Effect.gen` block. It is automatically set by the
|
|
396
|
+
* `@effect/unplugin` build-time transformer.
|
|
397
|
+
*
|
|
398
|
+
* @since 3.20.0
|
|
399
|
+
* @category fiberRefs
|
|
400
|
+
*/
|
|
401
|
+
export const currentSourceTrace: FiberRef<SourceLocation.SourceLocation | undefined> = core.currentSourceTrace
|
|
402
|
+
|
|
390
403
|
/**
|
|
391
404
|
* @since 2.0.0
|
|
392
405
|
* @category fiberRefs
|
package/src/Layer.ts
CHANGED
|
@@ -1107,29 +1107,6 @@ export const setTracerTiming: (enabled: boolean) => Layer<never> = (enabled: boo
|
|
|
1107
1107
|
fiberRuntime.fiberRefLocallyScoped(core.currentTracerTimingEnabled, enabled)
|
|
1108
1108
|
)
|
|
1109
1109
|
|
|
1110
|
-
/**
|
|
1111
|
-
* A layer that enables source location capture for forked fibers.
|
|
1112
|
-
*
|
|
1113
|
-
* When enabled, `Effect.fork` and similar operations will capture the call
|
|
1114
|
-
* site (file, line, column) and store it in a FiberRef that can be read by
|
|
1115
|
-
* Supervisors. This enables automatic tracing with meaningful span names
|
|
1116
|
-
* like `"sendEmail (user-handlers.ts:42)"` instead of `"anonymous"`.
|
|
1117
|
-
*
|
|
1118
|
-
* @example
|
|
1119
|
-
* ```ts
|
|
1120
|
-
* import { Effect, Layer } from "effect"
|
|
1121
|
-
*
|
|
1122
|
-
* // Enable source capture for entire program
|
|
1123
|
-
* Effect.runPromise(
|
|
1124
|
-
* program.pipe(Effect.provide(Layer.enableSourceCapture))
|
|
1125
|
-
* )
|
|
1126
|
-
* ```
|
|
1127
|
-
*
|
|
1128
|
-
* @since 3.15.0
|
|
1129
|
-
* @category tracing
|
|
1130
|
-
*/
|
|
1131
|
-
export const enableSourceCapture: Layer<never> = internal.enableSourceCapture
|
|
1132
|
-
|
|
1133
1110
|
/**
|
|
1134
1111
|
* @since 2.0.0
|
|
1135
1112
|
* @category logging
|
package/src/RuntimeFlags.ts
CHANGED
|
@@ -59,17 +59,6 @@ export const Interruption: RuntimeFlag = internal.Interruption
|
|
|
59
59
|
*/
|
|
60
60
|
export const OpSupervision: RuntimeFlag = internal.OpSupervision
|
|
61
61
|
|
|
62
|
-
/**
|
|
63
|
-
* The operation tracing flag determines whether or not the Effect runtime system
|
|
64
|
-
* will capture metadata for high-level operations (such as Effect.all, Effect.forEach)
|
|
65
|
-
* in the trace field. This metadata can be consumed by supervisors via OpSupervision
|
|
66
|
-
* to enable automatic span creation without manual instrumentation.
|
|
67
|
-
*
|
|
68
|
-
* @since 3.10.0
|
|
69
|
-
* @category constructors
|
|
70
|
-
*/
|
|
71
|
-
export const OperationTracing: RuntimeFlag = internal.OperationTracing
|
|
72
|
-
|
|
73
62
|
/**
|
|
74
63
|
* The runtime metrics flag determines whether or not the Effect runtime system
|
|
75
64
|
* will collect metrics about the Effect runtime. Use of this flag will have a
|
|
@@ -171,12 +160,6 @@ export const disableInterruption: Layer.Layer<never> = circular.disableInterrupt
|
|
|
171
160
|
*/
|
|
172
161
|
export const disableOpSupervision: Layer.Layer<never> = circular.disableOpSupervision
|
|
173
162
|
|
|
174
|
-
/**
|
|
175
|
-
* @since 3.10.0
|
|
176
|
-
* @category context
|
|
177
|
-
*/
|
|
178
|
-
export const disableOperationTracing: Layer.Layer<never> = circular.disableOperationTracing
|
|
179
|
-
|
|
180
163
|
/**
|
|
181
164
|
* @since 2.0.0
|
|
182
165
|
* @category context
|
|
@@ -229,12 +212,6 @@ export const enableInterruption: Layer.Layer<never> = circular.enableInterruptio
|
|
|
229
212
|
*/
|
|
230
213
|
export const enableOpSupervision: Layer.Layer<never> = circular.enableOpSupervision
|
|
231
214
|
|
|
232
|
-
/**
|
|
233
|
-
* @since 3.10.0
|
|
234
|
-
* @category context
|
|
235
|
-
*/
|
|
236
|
-
export const enableOperationTracing: Layer.Layer<never> = circular.enableOperationTracing
|
|
237
|
-
|
|
238
215
|
/**
|
|
239
216
|
* @since 2.0.0
|
|
240
217
|
* @category context
|
|
@@ -312,15 +289,6 @@ export const none: RuntimeFlags = internal.none
|
|
|
312
289
|
*/
|
|
313
290
|
export const opSupervision: (self: RuntimeFlags) => boolean = internal.opSupervision
|
|
314
291
|
|
|
315
|
-
/**
|
|
316
|
-
* Returns `true` if the `OperationTracing` `RuntimeFlag` is enabled, `false`
|
|
317
|
-
* otherwise.
|
|
318
|
-
*
|
|
319
|
-
* @since 3.10.0
|
|
320
|
-
* @category getters
|
|
321
|
-
*/
|
|
322
|
-
export const operationTracing: (self: RuntimeFlags) => boolean = internal.operationTracing
|
|
323
|
-
|
|
324
292
|
/**
|
|
325
293
|
* Patches a set of `RuntimeFlag`s with a `RuntimeFlagsPatch`, returning the
|
|
326
294
|
* patched set of `RuntimeFlag`s.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source location metadata for build-time instrumentation.
|
|
3
|
+
*
|
|
4
|
+
* This module provides types and utilities for tracking source code locations
|
|
5
|
+
* through the Effect runtime. It enables automatic log prefixing, OpenTelemetry
|
|
6
|
+
* code attributes, and DevTools integration.
|
|
7
|
+
*
|
|
8
|
+
* @since 3.20.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @since 3.20.0
|
|
13
|
+
* @category symbols
|
|
14
|
+
*/
|
|
15
|
+
export const SourceLocationTypeId: unique symbol = Symbol.for("effect/SourceLocation")
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @since 3.20.0
|
|
19
|
+
* @category symbols
|
|
20
|
+
*/
|
|
21
|
+
export type SourceLocationTypeId = typeof SourceLocationTypeId
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Represents a source code location, typically injected at build time.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const trace: SourceLocation = {
|
|
29
|
+
* [SourceLocationTypeId]: SourceLocationTypeId,
|
|
30
|
+
* path: "src/services/UserRepo.ts",
|
|
31
|
+
* line: 42,
|
|
32
|
+
* column: 12,
|
|
33
|
+
* label: "fetchUser"
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @since 3.20.0
|
|
38
|
+
* @category models
|
|
39
|
+
*/
|
|
40
|
+
export interface SourceLocation {
|
|
41
|
+
readonly [SourceLocationTypeId]: SourceLocationTypeId
|
|
42
|
+
/**
|
|
43
|
+
* The relative file path from the project root.
|
|
44
|
+
* Example: "src/services/UserRepo.ts"
|
|
45
|
+
*/
|
|
46
|
+
readonly path: string
|
|
47
|
+
/**
|
|
48
|
+
* The 1-based line number in the source file.
|
|
49
|
+
*/
|
|
50
|
+
readonly line: number
|
|
51
|
+
/**
|
|
52
|
+
* The 0-based column number in the source file.
|
|
53
|
+
*/
|
|
54
|
+
readonly column: number
|
|
55
|
+
/**
|
|
56
|
+
* An optional label for this location, typically the variable name
|
|
57
|
+
* or function name associated with the effect.
|
|
58
|
+
*/
|
|
59
|
+
readonly label?: string | undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Constructs a SourceLocation object.
|
|
64
|
+
*
|
|
65
|
+
* @since 3.20.0
|
|
66
|
+
* @category constructors
|
|
67
|
+
*/
|
|
68
|
+
export const make = (
|
|
69
|
+
path: string,
|
|
70
|
+
line: number,
|
|
71
|
+
column: number,
|
|
72
|
+
label?: string | undefined
|
|
73
|
+
): SourceLocation => ({
|
|
74
|
+
[SourceLocationTypeId]: SourceLocationTypeId,
|
|
75
|
+
path,
|
|
76
|
+
line,
|
|
77
|
+
column,
|
|
78
|
+
label
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Formats a SourceLocation as a string for display.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { SourceLocation } from "effect"
|
|
87
|
+
*
|
|
88
|
+
* const trace = SourceLocation.make("src/UserRepo.ts", 42, 12, "fetchUser")
|
|
89
|
+
* console.log(SourceLocation.format(trace))
|
|
90
|
+
* // Output: "src/UserRepo.ts:42"
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @since 3.20.0
|
|
94
|
+
* @category formatting
|
|
95
|
+
*/
|
|
96
|
+
export const format = (location: SourceLocation): string =>
|
|
97
|
+
location.label
|
|
98
|
+
? `${location.path}:${location.line} (${location.label})`
|
|
99
|
+
: `${location.path}:${location.line}`
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Type guard to check if a value is a SourceLocation.
|
|
103
|
+
*
|
|
104
|
+
* @since 3.20.0
|
|
105
|
+
* @category guards
|
|
106
|
+
*/
|
|
107
|
+
export const isSourceLocation = (u: unknown): u is SourceLocation =>
|
|
108
|
+
typeof u === "object" && u !== null && SourceLocationTypeId in u
|
package/src/Tracer.ts
CHANGED
|
@@ -5,7 +5,6 @@ import type * as Context from "./Context.js"
|
|
|
5
5
|
import type * as Effect from "./Effect.js"
|
|
6
6
|
import type * as Exit from "./Exit.js"
|
|
7
7
|
import type * as Fiber from "./Fiber.js"
|
|
8
|
-
import type * as FiberRef from "./FiberRef.js"
|
|
9
8
|
import type { LazyArg } from "./Function.js"
|
|
10
9
|
import * as defaultServices from "./internal/defaultServices.js"
|
|
11
10
|
import * as internal from "./internal/tracer.js"
|
|
@@ -181,18 +180,3 @@ export interface DisablePropagation {
|
|
|
181
180
|
* @category annotations
|
|
182
181
|
*/
|
|
183
182
|
export const DisablePropagation: Context.Reference<DisablePropagation, boolean> = internal.DisablePropagation
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* FiberRef for propagating OpenTelemetry span context through Effect's fiber hierarchy.
|
|
187
|
-
*
|
|
188
|
-
* When fibers are forked, they inherit this FiberRef's value from their parent.
|
|
189
|
-
* This allows supervisors to maintain correct parent-child span relationships
|
|
190
|
-
* even when the OTel AsyncLocalStorage context is lost due to Effect's fiber scheduler.
|
|
191
|
-
*
|
|
192
|
-
* The value is typed as `unknown` to avoid a direct dependency on @opentelemetry/api.
|
|
193
|
-
* Consumers should cast to `OtelApi.Context` when using.
|
|
194
|
-
*
|
|
195
|
-
* @since 3.20.0
|
|
196
|
-
* @category otel
|
|
197
|
-
*/
|
|
198
|
-
export const currentOtelSpanContext: FiberRef.FiberRef<unknown> = internal.currentOtelSpanContext
|
package/src/index.ts
CHANGED
|
@@ -1302,6 +1302,13 @@ export * as ScopedCache from "./ScopedCache.js"
|
|
|
1302
1302
|
*/
|
|
1303
1303
|
export * as ScopedRef from "./ScopedRef.js"
|
|
1304
1304
|
|
|
1305
|
+
/**
|
|
1306
|
+
* Source location metadata for build-time instrumentation.
|
|
1307
|
+
*
|
|
1308
|
+
* @since 3.20.0
|
|
1309
|
+
*/
|
|
1310
|
+
export * as SourceLocation from "./SourceLocation.js"
|
|
1311
|
+
|
|
1305
1312
|
/**
|
|
1306
1313
|
* @since 2.0.0
|
|
1307
1314
|
* @deprecated
|
package/src/internal/config.ts
CHANGED
|
@@ -415,14 +415,14 @@ export const orElseIf = dual<
|
|
|
415
415
|
readonly if: Predicate<ConfigError.ConfigError>
|
|
416
416
|
readonly orElse: LazyArg<Config.Config<A2>>
|
|
417
417
|
}
|
|
418
|
-
) => <A>(self: Config.Config<A>) => Config.Config<A>,
|
|
418
|
+
) => <A>(self: Config.Config<A>) => Config.Config<A | A2>,
|
|
419
419
|
<A, A2>(
|
|
420
420
|
self: Config.Config<A>,
|
|
421
421
|
options: {
|
|
422
422
|
readonly if: Predicate<ConfigError.ConfigError>
|
|
423
423
|
readonly orElse: LazyArg<Config.Config<A2>>
|
|
424
424
|
}
|
|
425
|
-
) => Config.Config<A>
|
|
425
|
+
) => Config.Config<A | A2>
|
|
426
426
|
>(2, (self, options) => {
|
|
427
427
|
const fallback = Object.create(proto)
|
|
428
428
|
fallback._tag = OpCodes.OP_FALLBACK
|
package/src/internal/core.ts
CHANGED
|
@@ -35,6 +35,7 @@ import type * as RequestResolver from "../RequestResolver.js"
|
|
|
35
35
|
import type * as RuntimeFlags from "../RuntimeFlags.js"
|
|
36
36
|
import * as RuntimeFlagsPatch from "../RuntimeFlagsPatch.js"
|
|
37
37
|
import type * as Scope from "../Scope.js"
|
|
38
|
+
import type * as SourceLocation from "../SourceLocation.js"
|
|
38
39
|
import type * as Tracer from "../Tracer.js"
|
|
39
40
|
import type { NoInfer, NotFunction } from "../Types.js"
|
|
40
41
|
import { internalCall, YieldWrap } from "../Utils.js"
|
|
@@ -1415,10 +1416,26 @@ export const fromIterator = <Eff extends YieldWrap<Effect.Effect<any, any, any>>
|
|
|
1415
1416
|
return effect
|
|
1416
1417
|
})
|
|
1417
1418
|
|
|
1419
|
+
/**
|
|
1420
|
+
* The adapter function injected into Effect.gen generators.
|
|
1421
|
+
* Accepts an effect and an optional source location trace.
|
|
1422
|
+
* When a trace is provided, it wraps the effect with `fiberRefLocally`
|
|
1423
|
+
* to set the currentSourceTrace FiberRef during execution.
|
|
1424
|
+
*
|
|
1425
|
+
* @internal
|
|
1426
|
+
*/
|
|
1427
|
+
export const genAdapter = <A, E, R>(
|
|
1428
|
+
effect: Effect.Effect<A, E, R>,
|
|
1429
|
+
trace?: SourceLocation.SourceLocation
|
|
1430
|
+
): Effect.Effect<A, E, R> =>
|
|
1431
|
+
trace !== undefined
|
|
1432
|
+
? fiberRefLocally(effect, currentSourceTrace, trace)
|
|
1433
|
+
: effect
|
|
1434
|
+
|
|
1418
1435
|
/* @internal */
|
|
1419
1436
|
export const gen: typeof Effect.gen = function() {
|
|
1420
1437
|
const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0])
|
|
1421
|
-
return fromIterator(() => f(
|
|
1438
|
+
return fromIterator(() => f(genAdapter))
|
|
1422
1439
|
}
|
|
1423
1440
|
|
|
1424
1441
|
/** @internal */
|
|
@@ -1484,28 +1501,6 @@ export const withTracerTiming = dual<
|
|
|
1484
1501
|
enabled
|
|
1485
1502
|
))
|
|
1486
1503
|
|
|
1487
|
-
/** @internal */
|
|
1488
|
-
export const withCaptureStackTraces = dual<
|
|
1489
|
-
(enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1490
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>
|
|
1491
|
-
>(2, (effect, enabled) =>
|
|
1492
|
-
fiberRefLocally(
|
|
1493
|
-
effect,
|
|
1494
|
-
currentCaptureStackTraces,
|
|
1495
|
-
enabled
|
|
1496
|
-
))
|
|
1497
|
-
|
|
1498
|
-
/** @internal */
|
|
1499
|
-
export const withCaptureOperations = dual<
|
|
1500
|
-
(enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1501
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>
|
|
1502
|
-
>(2, (effect, enabled) =>
|
|
1503
|
-
fiberRefLocally(
|
|
1504
|
-
effect,
|
|
1505
|
-
currentCaptureOperations,
|
|
1506
|
-
enabled
|
|
1507
|
-
))
|
|
1508
|
-
|
|
1509
1504
|
/* @internal */
|
|
1510
1505
|
export const yieldNow = (options?: {
|
|
1511
1506
|
readonly priority?: number | undefined
|
|
@@ -2171,89 +2166,10 @@ export const currentTracerSpanLinks: FiberRef.FiberRef<Chunk.Chunk<Tracer.SpanLi
|
|
|
2171
2166
|
() => fiberRefUnsafeMake(Chunk.empty())
|
|
2172
2167
|
)
|
|
2173
2168
|
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
/**
|
|
2179
|
-
* Represents a source code location captured from a stack trace.
|
|
2180
|
-
* @internal
|
|
2181
|
-
*/
|
|
2182
|
-
export interface SourceLocation {
|
|
2183
|
-
readonly file: string
|
|
2184
|
-
readonly line: number
|
|
2185
|
-
readonly column: number
|
|
2186
|
-
readonly functionName?: string
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
/**
|
|
2190
|
-
* Represents metadata for a high-level Effect operation.
|
|
2191
|
-
* Stored in the `trace` field of Effect primitives when operation tracing is enabled.
|
|
2192
|
-
* The `_tag` field identifies this as operation metadata for use by supervisors.
|
|
2193
|
-
* @internal
|
|
2194
|
-
*/
|
|
2195
|
-
export interface OperationMeta {
|
|
2196
|
-
readonly _tag: "OperationMeta" // Tag to identify operation metadata
|
|
2197
|
-
readonly op: string // Operation name: 'all', 'forEach', 'retry', etc.
|
|
2198
|
-
readonly count?: number // Item count for all/forEach
|
|
2199
|
-
readonly capturedAt: string // Stack trace captured at creation time
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
/**
|
|
2203
|
-
* Creates operation metadata for tracing high-level Effect operations.
|
|
2204
|
-
* @internal
|
|
2205
|
-
*/
|
|
2206
|
-
export const makeOperationMeta = (
|
|
2207
|
-
op: string,
|
|
2208
|
-
capturedAt: string,
|
|
2209
|
-
count?: number
|
|
2210
|
-
): OperationMeta => {
|
|
2211
|
-
const meta: OperationMeta = {
|
|
2212
|
-
_tag: "OperationMeta",
|
|
2213
|
-
op,
|
|
2214
|
-
capturedAt
|
|
2215
|
-
}
|
|
2216
|
-
if (count !== undefined) {
|
|
2217
|
-
(meta as { count?: number }).count = count
|
|
2218
|
-
}
|
|
2219
|
-
return meta
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
/**
|
|
2223
|
-
* FiberRef that controls whether operation tracing is enabled.
|
|
2224
|
-
* When enabled, high-level operations like Effect.all, Effect.forEach
|
|
2225
|
-
* capture their call site and store metadata in the trace field.
|
|
2226
|
-
* @internal
|
|
2227
|
-
*/
|
|
2228
|
-
export const currentCaptureOperations: FiberRef.FiberRef<boolean> = globalValue(
|
|
2229
|
-
Symbol.for("effect/FiberRef/currentCaptureOperations"),
|
|
2230
|
-
() => fiberRefUnsafeMake(false)
|
|
2231
|
-
)
|
|
2232
|
-
|
|
2233
|
-
/**
|
|
2234
|
-
* FiberRef that controls whether source location capture is enabled.
|
|
2235
|
-
* When enabled, `Effect.fork` captures the call site and stores it
|
|
2236
|
-
* in `currentSourceLocation` for use by Supervisors.
|
|
2237
|
-
* @internal
|
|
2238
|
-
*/
|
|
2239
|
-
export const currentCaptureStackTraces: FiberRef.FiberRef<boolean> = globalValue(
|
|
2240
|
-
Symbol.for("effect/FiberRef/currentCaptureStackTraces"),
|
|
2241
|
-
() => fiberRefUnsafeMake(false)
|
|
2242
|
-
)
|
|
2243
|
-
|
|
2244
|
-
/**
|
|
2245
|
-
* FiberRef that holds the captured source location for a fiber.
|
|
2246
|
-
* This is set by `Effect.fork` when `currentCaptureStackTraces` is enabled.
|
|
2247
|
-
* Each fiber gets its own location (not propagated to children).
|
|
2248
|
-
* @internal
|
|
2249
|
-
*/
|
|
2250
|
-
export const currentSourceLocation: FiberRef.FiberRef<SourceLocation | undefined> = globalValue(
|
|
2251
|
-
Symbol.for("effect/FiberRef/currentSourceLocation"),
|
|
2252
|
-
() =>
|
|
2253
|
-
fiberRefUnsafeMake<SourceLocation | undefined>(undefined, {
|
|
2254
|
-
fork: () => undefined, // Don't propagate - each fiber gets its own
|
|
2255
|
-
join: (parent, _) => parent
|
|
2256
|
-
})
|
|
2169
|
+
/** @internal */
|
|
2170
|
+
export const currentSourceTrace: FiberRef.FiberRef<SourceLocation.SourceLocation | undefined> = globalValue(
|
|
2171
|
+
Symbol.for("effect/FiberRef/currentSourceTrace"),
|
|
2172
|
+
() => fiberRefUnsafeMake<SourceLocation.SourceLocation | undefined>(undefined)
|
|
2257
2173
|
)
|
|
2258
2174
|
|
|
2259
2175
|
// -----------------------------------------------------------------------------
|
|
@@ -366,16 +366,10 @@ export const forkAll: {
|
|
|
366
366
|
}): Effect.Effect<void, never, Effect.Effect.Context<Eff>>
|
|
367
367
|
} = dual((args) => Predicate.isIterable(args[0]), <A, E, R>(effects: Iterable<Effect.Effect<A, E, R>>, options: {
|
|
368
368
|
readonly discard: true
|
|
369
|
-
}): Effect.Effect<void, never, R> =>
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const result: Effect.Effect<void | Fiber.Fiber<Array<A>, E>, never, R> = options?.discard ?
|
|
374
|
-
core.forEachSequentialDiscard(effectsArray, fiberRuntime.fork) :
|
|
375
|
-
core.map(core.forEachSequential(effectsArray, fiberRuntime.fork), fiberRuntime.fiberAll)
|
|
376
|
-
;(result as any).trace = core.makeOperationMeta("forkAll", rawStack, count)
|
|
377
|
-
return result
|
|
378
|
-
})
|
|
369
|
+
}): Effect.Effect<void, never, R> =>
|
|
370
|
+
options?.discard ?
|
|
371
|
+
core.forEachSequentialDiscard(effects, fiberRuntime.fork) :
|
|
372
|
+
core.map(core.forEachSequential(effects, fiberRuntime.fork), fiberRuntime.fiberAll))
|
|
379
373
|
|
|
380
374
|
/** @internal */
|
|
381
375
|
export const forkIn = dual<
|
|
@@ -383,9 +377,8 @@ export const forkIn = dual<
|
|
|
383
377
|
<A, E, R>(self: Effect.Effect<A, E, R>, scope: Scope.Scope) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>
|
|
384
378
|
>(
|
|
385
379
|
2,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const result: Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R> = core.withFiberRuntime((parent, parentStatus) => {
|
|
380
|
+
(self, scope) =>
|
|
381
|
+
core.withFiberRuntime((parent, parentStatus) => {
|
|
389
382
|
const scopeImpl = scope as fiberRuntime.ScopeImpl
|
|
390
383
|
const fiber = fiberRuntime.unsafeFork(self, parent, parentStatus.runtimeFlags, globalScope)
|
|
391
384
|
if (scopeImpl.state._tag === "Open") {
|
|
@@ -406,9 +399,6 @@ export const forkIn = dual<
|
|
|
406
399
|
}
|
|
407
400
|
return core.succeed(fiber)
|
|
408
401
|
})
|
|
409
|
-
;(result as any).trace = core.makeOperationMeta("forkIn", rawStack, 1)
|
|
410
|
-
return result
|
|
411
|
-
}
|
|
412
402
|
)
|
|
413
403
|
|
|
414
404
|
/** @internal */
|