Skip to content
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

Allow scanning instrumented reactor publishers and only allow registe… #5755

Merged
merged 5 commits into from
Apr 7, 2022

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Apr 6, 2022

…ring once.

While working on some other test code, I noticed that we add a context propagating publisher to the chain that does not allow scanning it's parent, unlike all the standard reactor publishers. While not strictly necessary based on the publisher spec, it's good to not lose this functionality.

Also noticed it seems possible to register hooks twice so added a guard.

@anuraaga anuraaga requested a review from a team as a code owner April 6, 2022 06:39
@Test
void fluxParentsAccessible() {
UnicastProcessor<String> source = UnicastProcessor.create();
Flux<String> mono = ContextPropagationOperator.runWithContext(source, Context.root());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
Flux<String> mono = ContextPropagationOperator.runWithContext(source, Context.root());
Flux<String> flux = ContextPropagationOperator.runWithContext(source, Context.root());

@@ -98,17 +101,22 @@ public static Context getOpenTelemetryContext(
* reactive stream. This should generally be called in a static initializer block in your
* application.
*/
public void registerOnEachOperator() {
public synchronized void registerOnEachOperator() {
Copy link
Contributor Author

@anuraaga anuraaga Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying to use AtomicBoolean I got this bizzare exception in KotlinCoroutinesInstrumentationTest. Synchronizing for these should be fine anyways, but is it an agent bug?

[otel.javaagent 2022-04-06 07:40:51:716 +0000] [otel-javaagent-transform-safe-logger] DEBUG io.opentelemetry.javaagent.tooling.AgentInstaller$TransformLoggingListener - Failed to handle io.opentelemetry.instrumentation.reactor.ContextPropagationOperator for transformation on classloader jdk.internal.loader.ClassLoaders$AppClassLoader@7ad041f3
java.lang.IllegalStateException: Cannot assign private static final java.util.concurrent.atomic.AtomicBoolean io.opentelemetry.instrumentation.reactor.ContextPropagationOperator.enabled to boolean
	at net.bytebuddy.asm.Advice$OffsetMapping$ForField.resolve(Advice.java:2317)
	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$ForMethodEnter.doApply(Advice.java:8684)
	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$ForMethodEnter$WithDiscardedEnterType.doApply(Advice.java:8786)
	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$ForMethodEnter.apply(Advice.java:8642)
	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$AdviceMethodInliner.visitMethod(Advice.java:8332)
	at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1353)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:744)
	at org.objectweb.asm.ClassReader.accept(ClassReader.java:424)
	at net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$AdviceMethodInliner.apply(Advice.java:8325)
	at net.bytebuddy.asm.Advice$AdviceVisitor.onAfterExceptionTable(Advice.java:10579)
	at net.bytebuddy.utility.visitor.ExceptionTableSensitiveMethodVisitor.considerEndOfExceptionTable(ExceptionTableSensitiveMethodVisitor.java:49)
	at net.bytebuddy.utility.visitor.ExceptionTableSensitiveMethodVisitor.visitLabel(ExceptionTableSensitiveMethodVisitor.java:81)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's a public class, better to avoid synchronizing on this?

@anuraaga anuraaga merged commit 225971e into open-telemetry:main Apr 7, 2022
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
open-telemetry#5755)

* Allow scanning instrumented reactor publishers and only allow registering once.

* Avoid atomicboolean

* Clean

* Bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants