Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/contributing/writing-instrumentation-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,13 @@ to `true` and make it non-experimental.

### Shared classes and common classloader

By default, all the advices of an instrumentation module will be loaded into isolated classloaders,
one per instrumentation module. Some instrumentations require to use a common classloader in order
to preserve the semantics of `static` fields and to share classes.
All the advices are loaded into a shared classloader:

In order to load multiple `InstrumentationModule` implementations in the same classloader, you need to
override the `ExperimentalInstrumentationModule#getModuleGroup` to return an identical value.
- one common classloader for internal instrumentation modules
- one common classloader per extension

This allows to share classes between internal instrumentation modules, however each extension is isolated from others and from the internal instrumentation modules.
This means that extensions should not depend on internal instrumentation modules or rely on classes to be shared between them.

### Classes injected in application classloader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class AkkaHttpServerInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class AkkaHttpServerInstrumentationModule extends InstrumentationModule {
public AkkaHttpServerInstrumentationModule() {
super("akka-http", "akka-http-10.0", "akka-http-server");
}

@Override
public String getModuleGroup() {
return "akka-http";
}

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
// in GraphInterpreterInstrumentation we instrument a class that belongs to akka-streams, make
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,18 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;

/**
* This instrumentation applies to classes in akka-http.jar while
* AkkaHttpServerInstrumentationModule applies to classes in akka-http-core.jar
*/
@AutoService(InstrumentationModule.class)
public class AkkaHttpServerRouteInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class AkkaHttpServerRouteInstrumentationModule extends InstrumentationModule {
public AkkaHttpServerRouteInstrumentationModule() {
super("akka-http", "akka-http-10.0", "akka-http-server", "akka-http-server-route");
}

@Override
public String getModuleGroup() {
return "akka-http";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

// TODO: Copy & paste with only trivial adaptions from v2
abstract class AbstractAwsSdkInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
abstract class AbstractAwsSdkInstrumentationModule extends InstrumentationModule {

protected AbstractAwsSdkInstrumentationModule(String additionalInstrumentationName) {
super("aws-sdk", "aws-sdk-1.11", additionalInstrumentationName);
Expand All @@ -30,11 +28,6 @@ public boolean isHelperClass(String className) {
return className.startsWith("io.opentelemetry.contrib.awsxray.");
}

@Override
public String getModuleGroup() {
return "aws-sdk";
}

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
// added in 1.10.33
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class AwsSdkInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class AwsSdkInstrumentationModule extends InstrumentationModule {
public AwsSdkInstrumentationModule() {
super("aws-sdk", "aws-sdk-1.11", "aws-sdk-1.11-core");
}
Expand All @@ -25,11 +23,6 @@ public boolean isHelperClass(String className) {
return className.startsWith("io.opentelemetry.contrib.awsxray.");
}

@Override
public String getModuleGroup() {
return "aws-sdk";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,16 @@
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

abstract class AbstractAwsSdkInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
abstract class AbstractAwsSdkInstrumentationModule extends InstrumentationModule {

protected AbstractAwsSdkInstrumentationModule(String additionalInstrumentationName) {
super("aws-sdk", "aws-sdk-2.2", additionalInstrumentationName);
}

@Override
public String getModuleGroup() {
return "aws-sdk-v2";
}

@Override
public boolean isHelperClass(String className) {
return className.startsWith("io.opentelemetry.contrib.awsxray.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class AwsSdkInstrumentationModule extends AbstractAwsSdkInstrumentationModule {
public class AwsSdkInstrumentationModule extends AbstractAwsSdkInstrumentationModule
implements ExperimentalInstrumentationModule {
public AwsSdkInstrumentationModule() {
super("aws-sdk-2.2-core");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public List<TypeInstrumentation> typeInstrumentations() {
return asList(new CouchbaseBucketInstrumentation(), new CouchbaseClusterInstrumentation());
}

@Override
public String getModuleGroup() {
return "couchbase";
}

@Override
public List<String> injectedClassNames() {
return singletonList("rx.OpenTelemetryTracingUtil");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class CouchbaseInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class CouchbaseInstrumentationModule extends InstrumentationModule {

public CouchbaseInstrumentationModule() {
super("couchbase", "couchbase-2.6");
Expand All @@ -33,9 +31,4 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
public List<TypeInstrumentation> typeInstrumentations() {
return asList(new CouchbaseCoreInstrumentation(), new CouchbaseNetworkInstrumentation());
}

@Override
public String getModuleGroup() {
return "couchbase";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class ElasticsearchApiClientInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class ElasticsearchApiClientInstrumentationModule extends InstrumentationModule {
public ElasticsearchApiClientInstrumentationModule() {
super("elasticsearch-api-client", "elasticsearch-api-client-7.16", "elasticsearch");
}
Expand All @@ -32,11 +30,6 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
.and(not(hasClassesNamed("co.elastic.clients.transport.instrumentation.Instrumentation")));
}

@Override
public String getModuleGroup() {
return "elasticsearch";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class ElasticsearchRest7InstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class ElasticsearchRest7InstrumentationModule extends InstrumentationModule {
public ElasticsearchRest7InstrumentationModule() {
super("elasticsearch-rest", "elasticsearch-rest-7.0", "elasticsearch");
}
Expand All @@ -32,11 +30,6 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
.and(not(hasClassesNamed("co.elastic.clients.transport.instrumentation.Instrumentation")));
}

@Override
public String getModuleGroup() {
return "elasticsearch";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new RestClientInstrumentation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ public List<TypeInstrumentation> typeInstrumentations() {
new H2StreamChannelInitInstrumentation());
}

@Override
public String getModuleGroup() {
// relies on netty and needs access to common netty instrumentation classes
return "netty";
}

@Override
public List<String> injectedClassNames() {
// these are injected so that they can access package-private members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class HibernateInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class HibernateInstrumentationModule extends InstrumentationModule {

public HibernateInstrumentationModule() {
super("hibernate", "hibernate-3.3");
Expand All @@ -32,11 +30,6 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
"org.hibernate.transaction.JBossTransactionManagerLookup");
}

@Override
public String getModuleGroup() {
return "hibernate";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class HibernateInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class HibernateInstrumentationModule extends InstrumentationModule {

public HibernateInstrumentationModule() {
super("hibernate", "hibernate-4.0");
Expand All @@ -32,11 +30,6 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
"org.hibernate.Criteria");
}

@Override
public String getModuleGroup() {
return "hibernate";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class HibernateInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class HibernateInstrumentationModule extends InstrumentationModule {

public HibernateInstrumentationModule() {
super("hibernate", "hibernate-6.0");
Expand All @@ -29,11 +27,6 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return hasClassesNamed("org.hibernate.query.spi.SqmQuery");
}

@Override
public String getModuleGroup() {
return "hibernate";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class HibernateInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public class HibernateInstrumentationModule extends InstrumentationModule {
public HibernateInstrumentationModule() {
super("hibernate-procedure-call", "hibernate-procedure-call-4.3", "hibernate");
}
Expand All @@ -28,11 +26,6 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return hasClassesNamed("org.hibernate.procedure.ProcedureCall");
}

@Override
public String getModuleGroup() {
return "hibernate";
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(new ProcedureCallInstrumentation(), new SessionInstrumentation());
Expand Down
Loading
Loading