嗨,我正在使用Java SpringBoot学习Opentelemtry,在生成span并将其导出到JaegerUI时遇到了一个问题。这是我的服务:
// 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;
}
字符串
这是我的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;
}
}
型
问题是,每次我使用Insomnia发出GET请求时,代码都会连续生成到JaegerUI中的跨度,直到我关闭我的服务。我尝试关闭我的SdkTracerProvider使用:
SdkTracerProvider.shutdown();
型
但它使我的服务不生成跨度,它会是什么问题呢?对不起我的英语。:)
1条答案
按热度按时间holgip5t1#
迟了但我解决了:我愚蠢地设置了出口作为接收器,所以它陷入了一个循环!:(