Skip to content

Commit

Permalink
Merge pull request #16 from appoptics/NH-2669-update-otel-dependency
Browse files Browse the repository at this point in the history
NH2669: Dependencies: Upgrade Otel agent to 1.7.2
  • Loading branch information
jiwen624 authored Nov 17, 2021
2 parents 9635833 + 39b0e17 commit bff3149
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
//implementation project(path: ":custom", configuration: "shadow")
customShadow project(path: ":instrumentation", configuration: "shadow")
implementation project(path: ":core-bootstrap")
implementation "io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}:all"
implementation "io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}"
implementation "com.appoptics.agent.java:core:${versions.appopticsCore}"
implementation "com.appoptics.agent.java:metrics:${versions.appopticsMetrics}"
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ subprojects {

ext {
versions = [
opentelemetry : "1.3.0",
opentelemetryJavaagent: "1.3.0",
opentelemetry : "1.7.1",
opentelemetryJavaagent: "1.7.2",
// opentelemetry : "1.1.0",
// opentelemetryJavaagent: "1.1.0",
bytebuddy : "1.10.18",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public boolean matches(TypeDescription typeDefinitions) {
private static Plugin pluginFromClassPath(
Iterable<File> classPath, File sourceDirectory, String className) {
try {
ClassLoader classLoader = classLoaderFromClassPath(classPath, sourceDirectory);
URLClassLoader classLoader = classLoaderFromClassPath(classPath, sourceDirectory);
Class<?> clazz = Class.forName(className, false, classLoader);
return (Plugin) clazz.getDeclaredConstructor().newInstance();
return (Plugin) clazz.getDeclaredConstructor(URLClassLoader.class).newInstance(classLoader);
} catch (Exception e) {
throw new IllegalStateException("Failed to create ByteBuddy plugin instance", e);
}
}

private static ClassLoader classLoaderFromClassPath(
private static URLClassLoader classLoaderFromClassPath(
Iterable<File> classPath, File sourceDirectory) {
List<URL> urls = new ArrayList<>();
urls.add(fileAsUrl(sourceDirectory));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.appoptics.opentelemetry.extensions;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.spi.BootstrapPackagesProvider;

import java.util.Arrays;
import java.util.List;

@AutoService(BootstrapPackagesProvider.class)
public class AppOpticsBootstrapPackagesProvider implements BootstrapPackagesProvider {
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.extension.bootstrap.BootstrapPackagesBuilder;
import io.opentelemetry.javaagent.extension.bootstrap.BootstrapPackagesConfigurer;

/**
* This adds the Joboe core classes to the list which would always be loaded by the bootstrap classloader,
* no matter what classloader is used initially.
* The Otel agent instruments all classloaders and checks the class named to be loaded. It will load the class
* with the bootstrap classloader if the class mateches any of the prefix in the list above.
*/
@AutoService(BootstrapPackagesConfigurer.class)
public class AppOpticsBootstrapPackagesProvider implements BootstrapPackagesConfigurer {
@Override
public List<String> getPackagePrefixes() {
return Arrays.asList("com.tracelytics");
public void configure(Config config, BootstrapPackagesBuilder builder) {
builder.add("com.tracelytics");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import com.google.auto.service.AutoService;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;

@AutoService(ConfigurablePropagatorProvider.class)
public class AppOpticsContextPropagatorProvider implements ConfigurablePropagatorProvider {

@Override
public TextMapPropagator getPropagator() {
public TextMapPropagator getPropagator(ConfigProperties config) {
return new AppOpticsContextPropagator();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.appoptics.opentelemetry.extensions;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.spi.config.PropertySource;
import io.opentelemetry.javaagent.extension.config.ConfigPropertySource;

import java.util.HashMap;
import java.util.Map;

/**
* Provide various default properties when running OT agent with AO SPI implementations
*/
@AutoService(PropertySource.class)
public class AppOpticsPropertySource implements PropertySource {
@AutoService(ConfigPropertySource.class)
public class AppOpticsPropertySource implements ConfigPropertySource {
private static final Map<String, String> PROPERTIES = new HashMap<>();

static {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.appoptics.opentelemetry.extensions;

import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableSamplerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;

@AutoService(ConfigurableSamplerProvider.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurableSpanExporterProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
import io.opentelemetry.sdk.trace.export.SpanExporter;

@AutoService(ConfigurableSpanExporterProvider.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import com.google.auto.service.AutoService;
import com.tracelytics.joboe.config.InvalidConfigException;
import com.tracelytics.util.ServiceKeyUtils;
import io.opentelemetry.sdk.autoconfigure.spi.SdkTracerProviderConfigurer;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.SdkTracerProviderConfigurer;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@AutoService(SdkTracerProviderConfigurer.class)
public class AppOpticsTracerProviderConfigurer implements SdkTracerProviderConfigurer {
private Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
public AppOpticsTracerProviderConfigurer() {
try {
Initializer.initialize();
Expand All @@ -22,7 +23,7 @@ public AppOpticsTracerProviderConfigurer() {
}

@Override
public void configure(SdkTracerProviderBuilder tracerProvider) {
public void configure(SdkTracerProviderBuilder tracerProvider, ConfigProperties config) {
tracerProvider.addSpanProcessor(new AppOpticsRootSpanProcessor());
tracerProvider.addSpanProcessor(new AppOpticsProfilingSpanProcessor());
tracerProvider.addSpanProcessor(new AppOpticsInboundMetricsSpanProcessor());
Expand Down
6 changes: 3 additions & 3 deletions gradle/instrumentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ configurations {

dependencies {
compileOnly("io.opentelemetry:opentelemetry-sdk:${versions.opentelemetry}")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-api:${versions.opentelemetryJavaagentAlpha}")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}")
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
//compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-spi:${versions.opentelemetryJavaagentAlpha}")
implementation "org.slf4j:slf4j-api:1.6.2"
Expand All @@ -45,7 +45,7 @@ dependencies {

afterEvaluate {
dependencies {
compileOnly "io.opentelemetry.javaagent:opentelemetry-javaagent-api:${versions.opentelemetryJavaagentAlpha}"
compileOnly "io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}"
compileOnly "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}"
compileOnly "net.bytebuddy:byte-buddy:${versions.bytebuddy}"
compileOnly "io.opentelemetry:opentelemetry-api:${versions.opentelemetry}"
Expand All @@ -55,7 +55,7 @@ afterEvaluate {


}
def pluginName = 'io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin'
def pluginName = 'io.opentelemetry.javaagent.tooling.muzzle.generation.MuzzleCodeGenerationPlugin'
new ByteBuddyPluginConfigurator(project, sourceSets.main, pluginName,
configurations.toolingRuntime + configurations.runtimeClasspath
).configure()
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/appoptics-annotation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apply from: "$rootDir/gradle/instrumentation.gradle"
//}

dependencies {
compileOnly "io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:${versions.opentelemetryJavaagentAlpha}"
compileOnly "io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}"
compileOnly "com.appoptics.agent.java:core:${versions.appopticsCore}"
compileOnly project(":appoptics-opentelemetry-sdk")
compileOnly project(":custom")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@
package com.appoptics.opentelemetry.instrumentation;

import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.api.CallDepthThreadLocalMap;
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

import java.sql.Statement;
import java.util.Map;

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed;
import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext;
import static java.util.Collections.singletonMap;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static net.bytebuddy.matcher.ElementMatchers.*;

/**
Expand Down Expand Up @@ -52,7 +47,7 @@ public static class StatementAdvice {
//@Advice.OnMethodEnter(suppress = Throwable.class)
@Advice.OnMethodEnter
public static void onEnter() {
if (CallDepthThreadLocalMap.getCallDepth(Statement.class).get() != 1) { //only report back when depth is one to avoid duplications
if (CallDepth.forClass(Statement.class).get() != 1) { //only report back when depth is one to avoid duplications
return;
}
AoStatementTracer.writeStackTrace(Context.current());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import javax.servlet.http.HttpServletRequest;

import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed;
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
import static net.bytebuddy.matcher.ElementMatchers.*;

/**
Expand Down

0 comments on commit bff3149

Please sign in to comment.