Slide 50
Slide 50 text
Copyright © 2024, Oracle and/or its affiliates
50
参考: TracingConsumerInterceptorの実装
public class TracingConsumerInterceptor implements ConsumerInterceptor {
private static final KafkaTelemetry telemetry = KafkaTelemetry.builder(GlobalOpenTelemetry.get())
.setMessagingReceiveInstrumentationEnabled(ConfigPropertiesUtil.getBoolean(
"otel.instrumentation.messaging.experimental.receive-telemetry.enabled", false)).build();
@Override
@CanIgnoreReturnValue
public ConsumerRecords onConsume(ConsumerRecords records) {
Context receiveContext = telemetry.buildAndFinishSpan(records, consumerGroup, clientId, timer);
# ... 省略 ...
return telemetry.addTracing(records, consumerContext);
}
}
Context buildAndFinishSpan(
ConsumerRecords records, String consumerGroup, String clientId, Timer timer) {
Context parentContext = Context.current();
KafkaReceiveRequest request = KafkaReceiveRequest.create(records, consumerGroup, clientId);
Context context = null;
if (consumerReceiveInstrumenter.shouldStart(parentContext, request)) {
context = InstrumenterUtil.startAndEnd( # Context情報のExtractと新しいスパンの⽣成
consumerReceiveInstrumenter,
parentContext,
request,
null,
null,
timer.startTime(),
timer.now());
}
}