io.opentelemetry.instrumentation.rocketmqclient.v4_8.RocketMqConsumerInstrumenter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-rocketmq-client-4.8 Show documentation
Show all versions of opentelemetry-rocketmq-client-4.8 Show documentation
Instrumentation of Java libraries using OpenTelemetry.
The newest version!
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.rocketmqclient.v4_8;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import java.util.List;
import org.apache.rocketmq.common.message.MessageExt;
final class RocketMqConsumerInstrumenter {
private final Instrumenter singleProcessInstrumenter;
private final Instrumenter batchProcessInstrumenter;
private final Instrumenter batchReceiveInstrumenter;
RocketMqConsumerInstrumenter(
Instrumenter singleProcessInstrumenter,
Instrumenter batchProcessInstrumenter,
Instrumenter batchReceiveInstrumenter) {
this.singleProcessInstrumenter = singleProcessInstrumenter;
this.batchProcessInstrumenter = batchProcessInstrumenter;
this.batchReceiveInstrumenter = batchReceiveInstrumenter;
}
Context start(Context parentContext, List msgs) {
if (msgs.size() == 1) {
if (singleProcessInstrumenter.shouldStart(parentContext, msgs.get(0))) {
return singleProcessInstrumenter.start(parentContext, msgs.get(0));
}
} else {
if (batchReceiveInstrumenter.shouldStart(parentContext, null)) {
Context rootContext = batchReceiveInstrumenter.start(parentContext, null);
for (MessageExt message : msgs) {
createChildSpan(rootContext, message);
}
return rootContext;
}
}
return parentContext;
}
private void createChildSpan(Context parentContext, MessageExt msg) {
if (batchProcessInstrumenter.shouldStart(parentContext, msg)) {
Context context = batchProcessInstrumenter.start(parentContext, msg);
batchProcessInstrumenter.end(context, msg, null, null);
}
}
void end(Context context, List msgs) {
if (msgs.size() == 1) {
singleProcessInstrumenter.end(context, msgs.get(0), null, null);
} else {
batchReceiveInstrumenter.end(context, null, null, null);
}
}
}