io.opentelemetry.instrumentation.rocketmqclient.v4_8.TracingSendMessageHookImpl 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 io.opentelemetry.instrumentation.api.util.VirtualField;
import org.apache.rocketmq.client.hook.SendMessageContext;
import org.apache.rocketmq.client.hook.SendMessageHook;
final class TracingSendMessageHookImpl implements SendMessageHook {
private static final VirtualField contextField =
VirtualField.find(SendMessageContext.class, Context.class);
private final Instrumenter instrumenter;
TracingSendMessageHookImpl(Instrumenter instrumenter) {
this.instrumenter = instrumenter;
}
@Override
public String hookName() {
return "OpenTelemetrySendMessageTraceHook";
}
@Override
public void sendMessageBefore(SendMessageContext context) {
if (context == null) {
return;
}
Context parentContext = Context.current();
if (!instrumenter.shouldStart(parentContext, context)) {
return;
}
contextField.set(context, instrumenter.start(parentContext, context));
}
@Override
public void sendMessageAfter(SendMessageContext context) {
if (context == null) {
return;
}
Context otelContext = contextField.get(context);
if (otelContext != null
&& (context.getSendResult() != null || context.getException() != null)) {
instrumenter.end(otelContext, context, null, context.getException());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy