-
Notifications
You must be signed in to change notification settings - Fork 872
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
351 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...elemetry/javaagent/instrumentation/rocketmqclient/v5_0/ConsumeServiceInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.rocketmqclient.v5_0; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.apache.rocketmq.client.apis.consumer.MessageListener; | ||
|
||
final class ConsumeServiceInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
// Instrument ConsumerService instead of MessageListener because lambda could not be enhanced. | ||
return named("org.apache.rocketmq.client.java.impl.consumer.ConsumeService"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isConstructor() | ||
.and( | ||
isPublic() | ||
.and(takesArguments(5)) | ||
.and( | ||
takesArgument( | ||
1, named("org.apache.rocketmq.client.apis.consumer.MessageListener")))), | ||
ConsumeServiceInstrumentation.class.getName() + "$ConstructorAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class ConstructorAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter( | ||
@Advice.Argument(value = 1, readOnly = false) MessageListener messageListener) { | ||
// Replace messageListener by wrapper. | ||
if (!(messageListener instanceof MessageListenerWrapper)) { | ||
messageListener = new MessageListenerWrapper(messageListener); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...o/opentelemetry/javaagent/instrumentation/rocketmqclient/v5_0/MessageListenerWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.rocketmqclient.v5_0; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import org.apache.rocketmq.client.apis.consumer.ConsumeResult; | ||
import org.apache.rocketmq.client.apis.consumer.MessageListener; | ||
import org.apache.rocketmq.client.apis.message.MessageView; | ||
|
||
public final class MessageListenerWrapper implements MessageListener { | ||
private final MessageListener delegator; | ||
|
||
public MessageListenerWrapper(MessageListener delegator) { | ||
this.delegator = delegator; | ||
} | ||
|
||
@Override | ||
public ConsumeResult consume(MessageView messageView) { | ||
Context parentContext = VirtualFieldStore.getContextByMessage(messageView); | ||
if (parentContext == null) { | ||
parentContext = Context.current(); | ||
} | ||
Instrumenter<MessageView, ConsumeResult> processInstrumenter = | ||
RocketMqSingletons.consumerProcessInstrumenter(); | ||
if (!processInstrumenter.shouldStart(parentContext, messageView)) { | ||
return delegator.consume(messageView); | ||
} | ||
Context context = processInstrumenter.start(parentContext, messageView); | ||
try (Scope ignored = context.makeCurrent()) { | ||
ConsumeResult consumeResult = delegator.consume(messageView); | ||
processInstrumenter.end(context, messageView, consumeResult, null); | ||
return consumeResult; | ||
} catch (Throwable t) { | ||
processInstrumenter.end(context, messageView, null, t); | ||
throw t; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 0 additions & 94 deletions
94
...javaagent/instrumentation/rocketmqclient/v5_0/RocketMqMessageListenerInstrumentation.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...ntelemetry/instrumentation/rocketmqclient/v5_0/RocketMqClientSuppressReceiveSpanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.rocketmqclient.v5_0; | ||
|
||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
public class RocketMqClientSuppressReceiveSpanTest | ||
extends AbstractRocketMqClientSuppressReceiveSpanTest { | ||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
@Override | ||
protected InstrumentationExtension testing() { | ||
return testing; | ||
} | ||
} |
Oops, something went wrong.