-
Notifications
You must be signed in to change notification settings - Fork 870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pulsar: use span links when receive telemetry is enabled #10650
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
69ca4c5
Pulsar: use span links when receive telemetry is enabled
laurit ff37b2b
suppress receive spans
laurit 98956e4
fix tests
laurit 16d1e89
rename methods, rework comment
laurit fb8abda
Merge branch 'main' into pulsar-span-links
laurit 7f16962
Merge branch 'main' into pulsar-span-links
laurit 18bec4b
address review comments
laurit ab9647d
merge
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 additions & 0 deletions
48
...a/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/ConsumerBaseInstrumentation.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,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.pulsar.v2_8; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.opentelemetry.javaagent.instrumentation.pulsar.v2_8.telemetry.MessageListenerContext; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class ConsumerBaseInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.apache.pulsar.client.impl.ConsumerBase") | ||
.or(named("org.apache.pulsar.client.impl.MultiTopicsConsumerImpl")); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
// these methods receive a message and pass it on to a message listener | ||
// we instrument them so that the span for the receive operation could be suppressed | ||
transformer.applyAdviceToMethod( | ||
named("triggerListener").and(takesArguments(0)).or(named("receiveMessageFromConsumer")), | ||
this.getClass().getName() + "$TriggerListenerAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class TriggerListenerAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter() { | ||
MessageListenerContext.startProcessing(); | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void onExit() { | ||
MessageListenerContext.endProcessing(); | ||
} | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...opentelemetry/javaagent/instrumentation/pulsar/v2_8/telemetry/MessageListenerContext.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,31 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.pulsar.v2_8.telemetry; | ||
|
||
/** | ||
* Helper class used to determine whether message is going to be processed by a listener. If we know | ||
* that message is going to be passed to a message listener, that would produce a span for the | ||
* "process" operation, we are going to suppress the span from the message "receive" operation. | ||
*/ | ||
public final class MessageListenerContext { | ||
private static final ThreadLocal<Boolean> processing = new ThreadLocal<>(); | ||
|
||
private MessageListenerContext() {} | ||
|
||
/** Call on entry to a method that will pass the received message to a message listener. */ | ||
public static void startProcessing() { | ||
processing.set(Boolean.TRUE); | ||
} | ||
|
||
public static void endProcessing() { | ||
processing.remove(); | ||
} | ||
|
||
/** Returns true if we expect a received message to be passed to a listener. */ | ||
public static boolean isProcessing() { | ||
return processing.get() != null; | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spring kafka instrumentation also produces telemetry with span links for the batch receive scenario that can't be modeled with just parent child relationships