Configuring Multiple FetchHttpClient Instances with Different Settings

How do I get 2 disctincts configuration of the FetchHttpClient ?
It seems credentials: "include" is set for all requests, even for TracingLive, but it shouldn't have this setting to work

import { Otlp } from "@effect/opentelemetry"
import { FetchHttpClient, HttpApi, HttpApiClient } from "@effect/platform"
import { Effect, Layer } from "effect"

const CorsFetchHttpLive = FetchHttpClient.layer.pipe(
  Layer.provide(
    Layer.succeed(FetchHttpClient.RequestInit, {
      credentials: "include"
    })
  )
)

const TracingLive = Layer.unwrapEffect(
  Effect.gen(function*() {
    const serviceName = "app"
    return Otlp.layer({
      baseUrl: "https://api.honeycomb.io",
      resource: { serviceName },
      headers: {
        "x-honeycomb-team": "apiKey",
        "x-honeycomb-dataset": serviceName
      }
    })
  })
).pipe(Layer.provide(FetchHttpClient.layer))

const Api = HttpApi.make("MyApi")

export class ApiClient extends Effect.Service<ApiClient>()("ApiClient", {
  accessors: true,
  dependencies: [CorsFetchHttpLive],
  effect: HttpApiClient.make(Api, {
    baseUrl: "https://somewhere-with-cors"
  })
}) {}

const allLayers = Layer.mergeAll(ApiClient.Default, TracingLive)
Was this page helpful?