Effect CommunityEC
Effect Community•3y ago•
16 replies
Graeme

Troubleshooting OTEL HttpInstrumentation and Effect Trace Spans

Here's a tweaked version of one of the samples, in an attempt to use the OTEL HttpInstrumentation in combination with the Effect trace spans. Only the a/b/c spans are captured, there's no sign of the HTTP request (either from platform or from the HTTP instrumentation) other than the log of the status code. I'm clearly doing something wrong, but I'd expect the trace to propagate to the HTTP instrumentation (and beyond, but one step at a time :P):
import { seconds } from '@effect/data/Duration';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import * as Layer from '@effect/io/Layer';
import * as NodeSdk from '@effect/opentelemetry/NodeSdk';
import * as Resource from '@effect/opentelemetry/Resource';
import * as Tracer from '@effect/opentelemetry/Tracer';
import * as Http from '@effect/platform/HttpClient';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import {
  ConsoleSpanExporter,
  SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';

const ResourceLive = Resource.layer({ serviceName: 'example' });

const NodeSdkLive = NodeSdk.layer(
  Effect.sync(() =>
    NodeSdk.config({
      spanProcessor: new SimpleSpanProcessor(new ConsoleSpanExporter()),
      instrumentations: [new HttpInstrumentation({})],
    }),
  ),
);

const TracingLive = Layer.provide(
  ResourceLive,
  Layer.merge(NodeSdkLive, Tracer.layer),
);

const program = pipe(
  Http.request.get('https://example.com'),
  Http.client.fetchOk(),
  Effect.tap((response) => Effect.log(response.status)),
  Effect.withSpan('c'),
  Effect.withSpan('b'),
  Effect.withSpan('a'),
  Effect.repeatN(2),
  Effect.annotateSpans('working', true),
);

pipe(
  Effect.delay(program, seconds(1)),
  Effect.provide(TracingLive),
  Effect.catchAllCause(Effect.logError),
  Effect.runFork,
);

Any pointers greatly appreciated 🙂
Was this page helpful?