effect 3.4.5 → 3.4.6

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.
@@ -8,6 +8,7 @@ import * as Either from "../Either.js"
8
8
  import * as Equal from "../Equal.js"
9
9
  import * as Exit from "../Exit.js"
10
10
  import * as Fiber from "../Fiber.js"
11
+ import * as FiberRef from "../FiberRef.js"
11
12
  import { constVoid, dual, identity, pipe } from "../Function.js"
12
13
  import type { LazyArg } from "../Function.js"
13
14
  import * as Layer from "../Layer.js"
@@ -28,6 +29,7 @@ import * as mergeDecision from "./channel/mergeDecision.js"
28
29
  import * as mergeState from "./channel/mergeState.js"
29
30
  import * as _mergeStrategy from "./channel/mergeStrategy.js"
30
31
  import * as singleProducerAsyncInput from "./channel/singleProducerAsyncInput.js"
32
+ import * as coreEffect from "./core-effect.js"
31
33
  import * as core from "./core-stream.js"
32
34
  import * as MergeDecisionOpCodes from "./opCodes/channelMergeDecision.js"
33
35
  import * as MergeStateOpCodes from "./opCodes/channelMergeState.js"
@@ -2326,29 +2328,25 @@ export const withSpan: {
2326
2328
  const dataFirst = typeof arguments[0] !== "string"
2327
2329
  const name = dataFirst ? arguments[1] : arguments[0]
2328
2330
  const options = tracer.addSpanStackTrace(dataFirst ? arguments[2] : arguments[1])
2331
+ const acquire = Effect.all([
2332
+ Effect.makeSpan(name, options),
2333
+ Effect.context(),
2334
+ Effect.clock,
2335
+ FiberRef.get(FiberRef.currentTracerTimingEnabled)
2336
+ ])
2329
2337
  if (dataFirst) {
2330
2338
  const self = arguments[0]
2331
- return unwrapScoped(
2332
- Effect.flatMap(
2333
- Effect.context(),
2334
- (context) =>
2335
- Effect.map(
2336
- Effect.makeSpanScoped(name, options),
2337
- (span) => core.provideContext(self, Context.add(context, tracer.spanTag, span))
2338
- )
2339
- )
2339
+ return acquireUseRelease(
2340
+ acquire,
2341
+ ([span, context]) => core.provideContext(self, Context.add(context, tracer.spanTag, span)),
2342
+ ([span, , clock, timingEnabled], exit) => coreEffect.endSpan(span, exit, clock, timingEnabled)
2340
2343
  )
2341
2344
  }
2342
- return (self: Effect.Effect<any, any, any>) =>
2343
- unwrapScoped(
2344
- Effect.flatMap(
2345
- Effect.context(),
2346
- (context) =>
2347
- Effect.map(
2348
- Effect.makeSpanScoped(name, options),
2349
- (span) => core.provideContext(self, Context.add(context, tracer.spanTag, span))
2350
- )
2351
- )
2345
+ return (self: Channel.Channel<any>) =>
2346
+ acquireUseRelease(
2347
+ acquire,
2348
+ ([span, context]) => core.provideContext(self, Context.add(context, tracer.spanTag, span)),
2349
+ ([span, , clock, timingEnabled], exit) => coreEffect.endSpan(span, exit, clock, timingEnabled)
2352
2350
  )
2353
2351
  } as any
2354
2352
 
@@ -1,3 +1,4 @@
1
+ import type { Exit } from "effect/Exit"
1
2
  import { internalCall } from "effect/Utils"
2
3
  import * as Arr from "../Array.js"
3
4
  import type * as Cause from "../Cause.js"
@@ -2122,6 +2123,18 @@ export const spanAnnotations: Effect.Effect<HashMap.HashMap<string, unknown>> =
2122
2123
  export const spanLinks: Effect.Effect<Chunk.Chunk<Tracer.SpanLink>> = core
2123
2124
  .fiberRefGet(core.currentTracerSpanLinks)
2124
2125
 
2126
+ /** @internal */
2127
+ export const endSpan = <A, E>(span: Tracer.Span, exit: Exit<A, E>, clock: Clock.Clock, timingEnabled: boolean) =>
2128
+ core.sync(() => {
2129
+ if (span.status._tag === "Ended") {
2130
+ return
2131
+ }
2132
+ if (core.exitIsFailure(exit) && internalCause.spanToTrace.has(span)) {
2133
+ span.attribute("code.stacktrace", internalCause.spanToTrace.get(span)!())
2134
+ }
2135
+ span.end(timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0, exit)
2136
+ })
2137
+
2125
2138
  /** @internal */
2126
2139
  export const useSpan: {
2127
2140
  <A, E, R>(name: string, evaluate: (span: Tracer.Span) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
@@ -2144,16 +2157,7 @@ export const useSpan: {
2144
2157
  const span = unsafeMakeSpan(fiber, name, options)
2145
2158
  const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
2146
2159
  const clock = Context.get(fiber.getFiberRef(defaultServices.currentServices), clockTag)
2147
- return core.onExit(evaluate(span), (exit) =>
2148
- core.sync(() => {
2149
- if (span.status._tag === "Ended") {
2150
- return
2151
- }
2152
- if (core.exitIsFailure(exit) && internalCause.spanToTrace.has(span)) {
2153
- span.attribute("code.stacktrace", internalCause.spanToTrace.get(span)!())
2154
- }
2155
- span.end(timingEnabled ? clock.unsafeCurrentTimeNanos() : bigint0, exit)
2156
- }))
2160
+ return core.onExit(evaluate(span), (exit) => endSpan(span, exit, clock, timingEnabled))
2157
2161
  })
2158
2162
  }
2159
2163
 
@@ -1085,13 +1085,13 @@ export class FiberRuntime<in out A, in out E = never> implements Fiber.RuntimeFi
1085
1085
  return resume(core.exitSucceed(result.right))
1086
1086
  }
1087
1087
  switch (result.left._tag) {
1088
- case "Aborted": {
1088
+ case "Interrupt": {
1089
1089
  return resume(core.exitFailCause(internalCause.interrupt(FiberId.none)))
1090
1090
  }
1091
- case "Expected": {
1091
+ case "Fail": {
1092
1092
  return resume(core.fail(result.left.error))
1093
1093
  }
1094
- case "Unexpected": {
1094
+ case "Die": {
1095
1095
  return resume(core.die(result.left.defect))
1096
1096
  }
1097
1097
  }
@@ -3666,13 +3666,7 @@ export const makeSpanScoped = (
3666
3666
  const timingEnabled = fiber.getFiberRef(core.currentTracerTimingEnabled)
3667
3667
  const clock_ = Context.get(fiber.getFiberRef(defaultServices.currentServices), clock.clockTag)
3668
3668
  return core.as(
3669
- core.scopeAddFinalizerExit(scope, (exit) =>
3670
- core.sync(() => {
3671
- if (span.status._tag === "Ended") {
3672
- return
3673
- }
3674
- span.end(timingEnabled ? clock_.unsafeCurrentTimeNanos() : BigInt(0), exit)
3675
- })),
3669
+ core.scopeAddFinalizerExit(scope, (exit) => internalEffect.endSpan(span, exit, clock_, timingEnabled)),
3676
3670
  span
3677
3671
  )
3678
3672
  })
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.4.5"
1
+ let moduleVersion = "3.4.6"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4