Skip to content

Commit

Permalink
Add instrumentation for RxJava 3
Browse files Browse the repository at this point in the history
  • Loading branch information
HaloFour committed Apr 13, 2021
1 parent 3faf693 commit 484109a
Show file tree
Hide file tree
Showing 24 changed files with 3,186 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apply from: "$rootDir/gradle/instrumentation.gradle"

muzzle {
pass {
group = "io.reactivex.rxjava3"
module = "rxjava"
versions = "[3.0.0,)"
assertInverse true
}
}

dependencies {
library group: 'io.reactivex.rxjava3', name: 'rxjava', version: "3.0.0"

implementation project(":instrumentation:rxjava:rxjava-3.0:library")

testImplementation deps.opentelemetryExtAnnotations
testImplementation project(':instrumentation:rxjava:rxjava-3.0:testing')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.rxjava3;

import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class RxJava3InstrumentationModule extends InstrumentationModule {

public RxJava3InstrumentationModule() {
super("rxjava3");
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return Collections.singletonList(new PluginInstrumentation());
}

public static class PluginInstrumentation implements TypeInstrumentation {

@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return named("io.reactivex.rxjava3.plugins.RxJavaPlugins");
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return Collections.singletonMap(
isMethod(), RxJava3InstrumentationModule.class.getName() + "$RxJavaPluginsAdvice");
}
}

public static class RxJavaPluginsAdvice {

// TODO(anuraaga): Replace with adding a type initializer to RxJavaPlugins
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/2685
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void activateOncePerClassloader() {
TracingAssemblyActivation.activate(RxJavaPlugins.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.rxjava3;

import java.util.concurrent.atomic.AtomicBoolean;

public final class TracingAssemblyActivation {

private static final ClassValue<AtomicBoolean> activated =
new ClassValue<AtomicBoolean>() {
@Override
protected AtomicBoolean computeValue(Class<?> type) {
return new AtomicBoolean();
}
};

public static void activate(Class<?> clz) {
if (activated.get(clz).compareAndSet(false, true)) {
TracingAssembly.enable();
}
}

private TracingAssemblyActivation() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import io.opentelemetry.instrumentation.rxjava3.AbstractRxJava3SubscriptionTest
import io.opentelemetry.instrumentation.test.AgentTestTrait

class RxJava3SubscriptionTest extends AbstractRxJava3SubscriptionTest implements AgentTestTrait {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import io.opentelemetry.instrumentation.rxjava3.AbstractRxJava3Test
import io.opentelemetry.instrumentation.test.AgentTestTrait

class RxJava3Test extends AbstractRxJava3Test implements AgentTestTrait {
}
Loading

0 comments on commit 484109a

Please sign in to comment.