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

NH-10600: Upgrade otel agent dependencies #36

Merged
merged 8 commits into from
Apr 20, 2022
Merged
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
4 changes: 4 additions & 0 deletions agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ CopySpec isolateSpec() {
}
}

shadowJar {
classifier = null
}

tasks {
shadowJar {
dependsOn ':custom:shadowJar'
Expand Down
13 changes: 6 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ subprojects {

ext {
versions = [
opentelemetry : "1.7.1",
opentelemetryJavaagent: "1.7.2",
bytebuddy : "1.10.18",
opentelemetry : "1.12.0",
opentelemetryJavaagent: "1.12.1",
bytebuddy : "1.12.6",
guava : "30.1-jre",
appopticsCore : "7.2.0",
agent : "0.7.0" // the custom distro agent version
appopticsCore : "7.3.0",
agent : "0.8.0" // the custom distro agent version
]
versions.appopticsMetrics = "${versions.appopticsCore}" // they share the same version now
versions.opentelemetryAlpha = "${versions.opentelemetry}-alpha"
versions.opentelemetryJavaagentAlpha = "${versions.opentelemetryJavaagent}-alpha"

deps = [
bytebuddy : "net.bytebuddy:byte-buddy:${versions.bytebuddy}",
bytebuddyagent : "net.bytebuddy:byte-buddy-agent:${versions.bytebuddy}",
bytebuddy : "net.bytebuddy:byte-buddy-dep:${versions.bytebuddy}",
autoservice : [
"com.google.auto.service:auto-service:1.0-rc7",
"com.google.auto:auto-common:0.8",
Expand Down
7 changes: 5 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ dependencies {
implementation "org.ow2.asm:asm:7.0-beta"
implementation "org.ow2.asm:asm-tree:7.0-beta"
implementation "org.apache.httpcomponents:httpclient:4.5.10"
implementation "net.bytebuddy:byte-buddy-gradle-plugin:1.10.18"
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.12.6") {
exclude(group: "net.bytebuddy", module: "byte-buddy")
}
implementation("net.bytebuddy:byte-buddy-dep:1.12.6")

testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.1"
testImplementation "org.assertj:assertj-core:3.19.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void apply(Project project) {
Method assertionMethod =
instrumentationCL
.loadClass(
"io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil")
"io.opentelemetry.javaagent.muzzle.matcher.MuzzleGradlePluginUtil")
.getMethod("printMuzzleReferences", ClassLoader.class);
assertionMethod.invoke(null, instrumentationCL);
} catch (Exception e) {
Expand Down Expand Up @@ -298,7 +298,7 @@ public String toString() {
Method assertionMethod =
instrumentationCL
.loadClass(
"io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil")
"io.opentelemetry.javaagent.muzzle.matcher.MuzzleGradlePluginUtil")
.getMethod(
"assertInstrumentationMuzzled",
ClassLoader.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.extension.AgentListener;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;

/**
* Executes startup task after it's safe to do so. See https://github.com/appoptics/opentelemetry-custom-distro/pull/7
*/
@AutoService(AgentListener.class)
public class AppOpticsAgentListener implements AgentListener {
@Override
public void afterAgent(Config config) {
public void afterAgent(Config config, AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
Initializer.executeStartupTasks();
}
}
4 changes: 2 additions & 2 deletions gradle/instrumentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
implementation "org.slf4j:slf4j-api:1.6.2"

compileOnly deps.bytebuddy
compileOnly deps.bytebuddyagent
// compileOnly deps.bytebuddyagent
annotationProcessor deps.autoservice
compileOnly deps.autoservice

Expand All @@ -47,7 +47,7 @@ afterEvaluate {
dependencies {
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 "net.bytebuddy:byte-buddy-dep:${versions.bytebuddy}"
compileOnly "io.opentelemetry:opentelemetry-api:${versions.opentelemetry}"
// toolingRuntime(project(path: ":javaagent-tooling", configuration: 'instrumentationMuzzle'))
// toolingRuntime(project(path: ":javaagent-extension-api", configuration: 'instrumentationMuzzle'))
Expand Down
4 changes: 2 additions & 2 deletions instrumentation/jdbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply from: "$rootDir/gradle/instrumentation.gradle"

dependencies {
compileOnly project(":core-bootstrap")
implementation "com.appoptics.agent.java:core:${versions.appopticsCore}"
compileOnly "com.appoptics.agent.java:core:${versions.appopticsCore}"
implementation "io.opentelemetry:opentelemetry-semconv:${versions.opentelemetryAlpha}"
implementation "io.opentelemetry:opentelemetry-sdk-trace:${versions.opentelemetry}"

Expand All @@ -36,7 +36,7 @@ dependencies {
compileOnly "com.appoptics.agent.java:core:${versions.appopticsCore}"

// mandatory dependencies for using Spock
implementation "org.codehaus.groovy:groovy:3.0.9"
testImplementation "org.apache.groovy:groovy:4.0.1"
testImplementation platform("org.spockframework:spock-bom:2.1-groovy-3.0")
testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public static void onEnter(
// using CallDepth prevents this, because this check happens before Connection#getMetadata()
// is called - the first recursive Statement call is just skipped and we do not create a span
// for it
if (CallDepth.forClass(Statement.class).get() != 0) { //only report back when depth is one to avoid duplications
if (CallDepth.forClass(Statement.class).getAndIncrement() != 0) { //only report back when depth is one to avoid duplications
return;
}
QueryArgsCollector.collect(currentContext(), index, value);
CallDepth.forClass(Statement.class).decrementAndGet(); // do not want to interfere with the Otel's instrumentation
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand Down Expand Up @@ -90,11 +91,12 @@ public static void onEnter(
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
@Advice.Thrown Throwable throwable) {
if (CallDepth.forClass(Statement.class).get() != 1) { //only report back when depth is one to avoid duplications
if (CallDepth.forClass(Statement.class).getAndIncrement() != 1) { //only report back when depth is one to avoid duplications
return;
}
QueryArgsCollector.maybeAttach(currentContext());
StatementTruncator.maybeTruncateStatement(currentContext());
CallDepth.forClass(Statement.class).decrementAndGet(); // do not want to interfere with the Otel's instrumentation
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public void transform(TypeTransformer transformer) {
public static class StatementAdvice {
@Advice.OnMethodEnter
public static void onEnter(@Advice.Argument(value = 0, readOnly = false) String sql) {
if (CallDepth.forClass(Statement.class).get() != 1) { //only report back when depth is one to avoid duplications
if (CallDepth.forClass(Statement.class).getAndIncrement() != 1) { //only report back when depth is one to avoid duplications
return;
}
sql = TraceContextInjector.inject(currentContext(), sql);
AoStatementTracer.writeStackTraceSpec(currentContext());
StatementTruncator.maybeTruncateStatement(currentContext());
CallDepth.forClass(Statement.class).decrementAndGet(); // do not want to interfere with the Otel's instrumentation
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import com.tracelytics.util.BackTraceUtil;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
//import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AoStatementTracer extends BaseTracer {
public class AoStatementTracer {
private static final Logger log = LoggerFactory.getLogger(AoStatementTracer.class);

public static void writeStackTraceSpec(Context context) {
Expand All @@ -25,11 +25,11 @@ public static void writeStackTraceSpec(Context context) {
span.setAttribute(Constants.SW_KEY_PREFIX + "Spec", "query");
}
}

@Override
protected String getInstrumentationName() {
return "com.appoptics.opentelemetry.jdbc";
}
//
// @Override
// protected String getInstrumentationName() {
// return "com.appoptics.opentelemetry.jdbc";
// }

}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies {

compileOnly("javax.servlet:javax.servlet-api:3.0.1")
compileOnly "com.appoptics.agent.java:core:${versions.appopticsCore}"
compileOnly project(":appoptics-opentelemetry-sdk")
compileOnly project(":custom")
compileOnly project(":core-bootstrap")
toolingRuntime project(":custom")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

package com.appoptics.opentelemetry.instrumentation.servlet.v3_0;

import com.appoptics.opentelemetry.instrumentation.servlet.common.service.CallDepthKeyHolder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.servlet.AppServerBridge;
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
Expand All @@ -35,8 +35,8 @@ public static void onEnter(
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
return;
}
CallDepth callDepth = CallDepth.forClass(AppServerBridge.getCallDepthKey());
if (callDepth.get() > 1) {
CallDepth callDepth = CallDepth.forClass(CallDepthKeyHolder.getCallDepthKey());
if (callDepth.getAndIncrement() > 0) {
return;
}
injectXTraceHeader(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ archivesBaseName = "servlet5"

dependencies {
compileOnly "io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}"
implementation project(":instrumentation:servlet:servlet-common:javaagent")

compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")
implementation project(":instrumentation:servlet:servlet-common:javaagent")
compileOnly "com.appoptics.agent.java:core:${versions.appopticsCore}"
compileOnly project(":appoptics-opentelemetry-sdk")
compileOnly project(":custom")
compileOnly project(":core-bootstrap")
toolingRuntime project(":custom")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

package com.appoptics.opentelemetry.instrumentation.servlet.v5_0.service;

import com.appoptics.opentelemetry.instrumentation.servlet.common.service.CallDepthKeyHolder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.servlet.AppServerBridge;
import io.opentelemetry.javaagent.instrumentation.api.CallDepth;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
Expand All @@ -31,8 +31,8 @@ public static void onEnter(
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
return;
}
CallDepth callDepth = CallDepth.forClass(AppServerBridge.getCallDepthKey());
if (callDepth.get() > 1) {
CallDepth callDepth = CallDepth.forClass(CallDepthKeyHolder.getCallDepthKey());
if (callDepth.getAndIncrement() > 0) {
return;
}
injectXTraceHeader(response);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.appoptics.opentelemetry.instrumentation.servlet.common.service;

public class CallDepthKeyHolder {
public static Class<?> getCallDepthKey() {
class Key {}
return Key.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.ServerSpan;
import io.opentelemetry.instrumentation.api.server.ServerSpan;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

package com.appoptics.opentelemetry.instrumentation;

import io.opentelemetry.instrumentation.api.tracer.BaseTracer;
import io.opentelemetry.instrumentation.api.tracer.SpanNames;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNames;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.Servlet;
import java.lang.reflect.Method;

public class AoSpringWebMvcTracer extends BaseTracer {
public class AoSpringWebMvcTracer {


public static String spanNameOnHandle(Object handler) {
Expand Down Expand Up @@ -49,12 +48,9 @@ public static String spanNameOnHandle(Object handler) {

return SpanNames.fromMethod(clazz, methodName);
}




@Override
protected String getInstrumentationName() {
return "io.opentelemetry.javaagent.spring-webmvc-3.1";
}
//
// @Override
// protected String getInstrumentationName() {
// return "io.opentelemetry.javaagent.spring-webmvc-3.1";
// }
}
10 changes: 5 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
rootProject.name = 'otel-custom-distro'

include "agent"
include "appoptics-opentelemetry-sdk"
include "appoptics-opentelemetry-sdk-shaded"
//include "appoptics-opentelemetry-sdk"
//include "appoptics-opentelemetry-sdk-shaded"
include "core-bootstrap"
include "custom"
include "instrumentation"
include "instrumentation:jdbc"
include "instrumentation:appoptics-annotation"
//include "instrumentation:appoptics-annotation"
include "instrumentation:spring:spring-webmvc-3.1"
include "instrumentation:servlet:servlet-5.0:javaagent"
include "instrumentation:servlet:servlet-3.0:javaagent"
include "instrumentation:servlet:servlet-common:javaagent"
include "sdk-extensions"
include "sdk-extensions-bootstrap"
//include "sdk-extensions"
//include "sdk-extensions-bootstrap"