Effect CommunityEC
Effect Community12mo ago
2 replies
Niklas

Add computed value as log annotations (in a generator)

Hello everyone. I am starting to add some observability to my effect app. I want to add some advanced logging by enhancing the log outputs with a requestID or the requested path. Now the problem is I can only add log anotations like this
await pipe(
    myEffect,
    Effect.annotateLogs("requestId", "..."),
    Effect.runPromise
  )
);


But what if I want to add log annotations from within a service layer? Or a generator? Something like this:

Effect.gen(function* (_) {
  const headerService = yield* HeaderService;
  const path = headerService.get("x-requested-path");
  
  // TODO: Annotate all downstream logs with the path
  // This will not work
  yield* Effect.annotateLogs("requestId", requestId);
});


I could not figure it out. I appreciate any help
Was this page helpful?