Effect CommunityEC
Effect Community•14mo ago
.

Implementing a correlation ID in a way that feels idiomatic to the Effect library involves levera...

CorrelationId idiomatic implementation

Howdy 👋

I'm struggling to conjour up a good way to implement a correlationId that from request will be available to subsequent effects

I've explored Middlewares for this but feel like I'm lacking some Effect-style approach that is more idiomatic for this

export class Correlator extends HttpApiMiddleware.Tag<Correlator>()(
  "Correlator",
  {
    provides: CorrelationId
  }
) {
}

export const CorrelatorLive = Layer.effect(
  Correlator,
  Effect.gen(function*() {
    const uuid = yield* UUID
    const id = yield* uuid.generate
    return Correlator.of(Effect.succeed(Schema.decodeSync(CorrelationIdBranded)(id)))
  })
).pipe(Layer.provide(UUID.Default))


Approach so far^

Any guidance would be massively appreciated !
Was this page helpful?