Understanding Scope and Spans in Effect TypeScript Library

random question, i think my mental picture of scope with respect to spans is incorrect...should the withLogSpan be in a separate pipe? i see a lot of examples with a separate pipe for span declarations, not entirely sure on the why

export const makeLiveProviderService = Effect.gen(function* () {
  const ecn = yield* EcnClient; // custom http client

  function getByDomain(domain: string) {
    const message = "Some fallback error for client";

    return pipe(
      safeEncodeURI(`/public/sps/${domain}`),
      Effect.tap((url) => Effect.logInfo(`Making GET request`, { url })),
      Effect.map(HttpClientRequest.make("GET")),
      Effect.flatMap(ecn.client.execute),
      Effect.tap(Effect.logInfo("Decoding response", { to: "GetByDomainResponseDTO" })),
      Effect.flatMap(HttpClientResponse.schemaBodyJson(GetByDomainResponseDTO)),
      Effect.tap(Effect.logInfo("Decoding DTO", { to: "ServiceProvider" })),
      Effect.flatMap(Schema.decodeUnknown(ServiceProvider)),
      Effect.tap(Effect.logInfo("Request successful.")),
      Effect.tapErrorCause((cause) => Effect.logError(Cause.pretty(cause))),
      Effect.catchAll(() => UnexpectedError.make({ message })),
      Effect.withLogSpan("ServiceProvider.getByDomain"),
      Effect.scoped,
    );
  }

  return { getByDomain };
});
Was this page helpful?