javaopen-telemetryopen-telemetry-collectoropen-telemetry-java

OpenTelemetry Only Emit traces when service restarted


Below is my Otel implementation to instantiate the OpenTelemetry SDKs for Metrics & Traces. I found that Metrics are getting emitted whenever application requests are getting served but Traces are only emitted when this application is restarted.

Any suggestions what I'm missing here?

SpanExporter exporter = OtlpGrpcSpanExporter.builder()
                    .setEndpoint(otlEndPoint)
                    .build();

            SdkTracerProviderBuilder tracerProviderBuilder = SdkTracerProvider.builder()
                    .addSpanProcessor(BatchSpanProcessor.builder(exporter).build())
                    .setSampler(Sampler.alwaysOn());

            SdkTracerProvider tracerProvider = tracerProviderBuilder
                    .setResource(resource)
                    .build();

            ContextPropagators propagators = ContextPropagators.create(TextMapPropagator.composite(
                    W3CTraceContextPropagator.getInstance(),
                    W3CBaggagePropagator.getInstance()
            ));

            openTelemetry = OpenTelemetrySdk.builder().setMeterProvider(SdkMeterProvider.builder().setResource(resource)
                            .registerMetricReader(PeriodicMetricReader.builder(otlpGrpcMetricsExporter)
                                    .setInterval(Duration.ofMillis(1000)).build()).build())
                    .setTracerProvider(tracerProvider)
                    .setPropagators(propagators)
                    .buildAndRegisterGlobal();

Solution

  • We have our home-grown instrumentation framework where I was registering tracer instance to static context. This framework works well with running spring-boot based services but in this case where we load classes on-demand the tracer instance were needed to be passed for each request.

    We have handled the situation and it is working fine now.

    GlobalTracer.register(tracer);
    

    https://github.com/open-telemetry/opentelemetry-java/discussions/6594