-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load InstrumentationModules using InstrumentationLoader (#2971)
* Load InstrumentationModules using InstrumentationLoader * writing-instrumentation-module doc improvement * spotless
- Loading branch information
Mateusz Rzeszutek
committed
May 13, 2021
1 parent
a3be8e3
commit a72a783
Showing
9 changed files
with
126 additions
and
94 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
30 changes: 0 additions & 30 deletions
30
...telemetry/javaagent/extension/instrumentation/InstrumentationExtensionImplementation.java
This file was deleted.
Oops, something went wrong.
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
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
61 changes: 61 additions & 0 deletions
61
...c/main/java/io/opentelemetry/javaagent/tooling/instrumentation/InstrumentationLoader.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,61 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.instrumentation; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
import io.opentelemetry.javaagent.extension.spi.AgentExtension; | ||
import io.opentelemetry.javaagent.instrumentation.api.SafeServiceLoader; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import net.bytebuddy.agent.builder.AgentBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@AutoService(AgentExtension.class) | ||
public class InstrumentationLoader implements AgentExtension { | ||
private static final Logger log = LoggerFactory.getLogger(InstrumentationLoader.class); | ||
|
||
private final InstrumentationModuleInstaller instrumentationModuleInstaller = | ||
new InstrumentationModuleInstaller(); | ||
|
||
@Override | ||
public AgentBuilder extend(AgentBuilder agentBuilder) { | ||
List<InstrumentationModule> instrumentationModules = | ||
SafeServiceLoader.load( | ||
InstrumentationModule.class, InstrumentationLoader.class.getClassLoader()) | ||
.stream() | ||
.sorted(Comparator.comparingInt(InstrumentationModule::order)) | ||
.collect(Collectors.toList()); | ||
|
||
int numberOfLoadedModules = 0; | ||
for (InstrumentationModule instrumentationModule : instrumentationModules) { | ||
log.debug( | ||
"Loading instrumentation {} [class {}]", | ||
instrumentationModule.instrumentationName(), | ||
instrumentationModule.getClass().getName()); | ||
try { | ||
agentBuilder = instrumentationModuleInstaller.install(instrumentationModule, agentBuilder); | ||
numberOfLoadedModules++; | ||
} catch (Exception | LinkageError e) { | ||
log.error( | ||
"Unable to load instrumentation {} [class {}]", | ||
instrumentationModule.instrumentationName(), | ||
instrumentationModule.getClass().getName(), | ||
e); | ||
} | ||
} | ||
log.debug("Installed {} instrumenter(s)", numberOfLoadedModules); | ||
|
||
return agentBuilder; | ||
} | ||
|
||
@Override | ||
public String extensionName() { | ||
return "instrumentation-loader"; | ||
} | ||
} |
Oops, something went wrong.