Skip to content

Guidance on interop between Effect OTLP tracer and @opentelemetry/api Tracer? #5933

@schickling

Description

@schickling

Hi! We're using Effect's OTLP tracer (@effect/opentelemetry/Otlp) but also need an @opentelemetry/api Tracer for libraries expecting the OTel API. We're currently bridging the Effect tracer to an OTel API tracer with a custom adapter and using it as a workaround.

Question: Is there an official/idiomatic way to get interop between Effect's tracer (Otlp/OtelTracer) and the @opentelemetry/api tracer? Any recommended patterns or utilities to avoid maintaining a custom adapter?

Workaround (abridged):

const makeOtelEffectBridgeLayer = ({ baseUrl, serviceName, tracerExportInterval = 500 }) => {
  const otlpLayer = baseUrl
    ? Otlp.layer({ baseUrl, resource: { serviceName }, tracerExportInterval })
    : Layer.empty

  const otelAdapterLayer = Layer.effect(
    OtelTracer.OtelTracer,
    Effect.gen(function* () {
      const otlpTracer = yield* Effect.tracer
      return makeOtelTracerAdapter(otlpTracer)
    }),
  ).pipe(Layer.provide(otlpLayer))

  const otelEffectTracerLayer = Layer.unwrapEffect(Effect.map(OtelTracer.make, Layer.setTracer)).pipe(
    Layer.provide(otelAdapterLayer),
  )

  return otelEffectTracerLayer.pipe(Layer.provideMerge(otelAdapterLayer))
}

makeOtelTracerAdapter maps OTel API spans to Effect spans (parent context, links, attributes, timestamps). We're happy to share full code if useful.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions