javaspring-bootsdkopen-telemetryjaeger

Continuosly making spans until shutdown


Hi I'm learning Opentelemtry using Java SpringBoot, I faced an issue when generating spans and exporting them to JaegerUI. This is my service:

    // Iterates with a cursor a list of documents and returns them in json
    // then produces a message with kafka and exports telemetry datas.
    @Override
    public List<InsaccatiModel> findAll() {

        List<InsaccatiModel> insaccatiModels = new ArrayList<>();
        MongoCursor<Document> cursor = null;

        try {
            cursor = mongoCollection.find().iterator();

            while (cursor.hasNext()) {
                Document document = cursor.next();
                insaccatiModels.add(mapper.readValue(document.toJson(), InsaccatiModel.class));
            }
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        } finally {
            cursor.close();
        }

        // kafka producer
        Producer producer = new Producer();
        producer.producerMethod(kafkaServer, message);

        // instrumentation: spans
        Span span = tracer.spanBuilder("GET span").setSpanKind(SpanKind.PRODUCER).startSpan()
        .setAttribute("http.method", "GET")
        .setAttribute("http.url", "http://localhost:8080/app/all");
        span.end();

        // instrumentation: metrics
        LongCounter counter = meter
                .counterBuilder("processed")
                .setDescription("Description")
                .setUnit("1")
                .build();

        Attributes attributes = Attributes.of(AttributeKey.stringKey("Key"), "qualcosa");
        counter.add(123, attributes);

        return insaccatiModels;
    }

And this is my OpenTelemetryConfig:

    @Bean
    public OpenTelemetry openTelemetry() {
        Resource resource = Resource.getDefault()
                .merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "insaccati")));

        SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
                .addSpanProcessor(BatchSpanProcessor.builder(OtlpGrpcSpanExporter.builder().build()).build())
                .setResource(resource)
                .build();

        SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder()
                .registerMetricReader(PeriodicMetricReader.builder(OtlpGrpcMetricExporter.builder().build()).build())
                .setResource(resource)
                .build();

        OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
                .setTracerProvider(sdkTracerProvider)
                .setMeterProvider(sdkMeterProvider)
                .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
                .buildAndRegisterGlobal();

        return openTelemetry;
    }
}

The issue is that every time I make a GET request using Insomnia the code generates continuosly spans into JaegerUI until i shutdown my service. I tried to shutdown my SdkTracerProvider using:

SdkTracerProvider.shutdown();

But it makes my service not generating spans, where can it be the problem? Sorry for my English. :)


Solution

  • Late but i solved: I stupidly setted the exporter as receiver so it stucks itself into a loop! :(