Skip to content

@fastify/otel and openobserve? #1097

Open

Description

@YChebotaev

@fastify/otel and openobserve?

Hello!

I'm trying to use openobserve in conjunction with fastify

I'm using @fastify/otel package and follow instructions

But I can't see any example of how to export logs

And also, when I'm using ConsoleTraceExporter, I don't see nothing

May You please provide a complete example of how to export metrics and traces of fastify app into openobserve?

Your Environment

  • node version: 21.7.3
  • fastify version: >= 5.2.1
  • os: Mac

Activity

  1. changed the title [-]fastify/otel and openobserve?[/-] [+]@fastify/otel and openobserve?[/+] on May 20, 2025
  2. metcoder95 commented on May 28, 2025

    @metcoder95
    Member

    Can you provide the way you are setting OTEL in your app?

  3. YChebotaev commented on May 29, 2025

    @YChebotaev
    Author

    @metcoder95 Something like this:

    class Service {
      constructor() {
        this.ready = this.initialize();
      }
    
      private async initialize() {
        const { sdk, plugin } = await this.createOtelSdk();
    
        sdk.start();
    
        this.service = fastify({ loggerInstance: this.logger, trustProxy: true });
    
        this.service.register(plugin);
      }
    
      private async createOtelSdk() {
        const { FastifyOtelInstrumentation } = await import("@fastify/otel");
        const { NodeSDK } = await import("@opentelemetry/sdk-node");
        const { OTLPTraceExporter } = await import(
          "@opentelemetry/exporter-trace-otlp-http"
        );
        const { NodeTracerProvider } = await import(
          "@opentelemetry/sdk-trace-node"
        );
        const { resourceFromAttributes } = await import("@opentelemetry/resources");
        const { SemanticResourceAttributes } = await import(
          "@opentelemetry/semantic-conventions"
        );
        const { getNodeAutoInstrumentations } = await import(
          "@opentelemetry/auto-instrumentations-node"
        );
        const { ConsoleSpanExporter } = await import(
          "@opentelemetry/sdk-trace-base"
        );
        const { SimpleSpanProcessor } = await import(
          "@opentelemetry/sdk-trace-base"
        );
    
        const otelInstrumentation = new FastifyOtelInstrumentation({
          servername: "api-service",
        });
    
        const sdk = new NodeSDK({
          traceExporter: new OTLPTraceExporter({
            url: `${env.OO_BASE_URL}/v1/traces`,
            headers: { Authorization: `Basic ${env.OO_AUTH_CRED}` },
          }),
          spanProcessors: [new SimpleSpanProcessor(new ConsoleSpanExporter())],
          instrumentations: [getNodeAutoInstrumentations(), otelInstrumentation],
        });
    
        otelInstrumentation.init();
    
        return {
          sdk,
          plugin: otelInstrumentation.plugin(),
        };
      }
    }
  4. metcoder95 commented on Jun 2, 2025

    @metcoder95
    Member

    This is the setup we use for testing the otel implementation:

    const httpInstrumentation = new HttpInstrumentation()
    const instrumentation = new FastifyInstrumentation()
    const contextManager = new AsyncHooksContextManager()
    const memoryExporter = new InMemorySpanExporter()
    const spanProcessor = new SimpleSpanProcessor(memoryExporter)
    const provider = new NodeTracerProvider({
      sampler: new AlwaysOnSampler(),
      spanProcessors: [spanProcessor]
    })
    
    provider.register()
    propagation.setGlobalPropagator(new JaegerPropagator())
    context.setGlobalContextManager(contextManager)
    httpInstrumentation.setTracerProvider(provider)
    instrumentation.setTracerProvider(provider)

    It seems your implementation is missing the tracer provider register part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions