Skip to content

Commit 9950442

Browse files
authored
Grpc smoke test (#66)
1 parent 7da251b commit 9950442

File tree

42 files changed

+1209
-215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1209
-215
lines changed

.github/workflows/ci-build.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
concurrency:
1111
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
12-
cancel-in-progress: true
12+
cancel-in-progress: false
1313

1414
jobs:
1515

@@ -20,10 +20,10 @@ jobs:
2020
- name: GIT Checkout
2121
uses: actions/checkout@v3
2222

23-
- name: Set up JDK 11
23+
- name: Set up JDK 17
2424
uses: actions/setup-java@v3
2525
with:
26-
java-version: '11'
26+
java-version: '17'
2727
distribution: temurin
2828

2929
# using wrapper version (supposed to be 7.5.1)
@@ -43,3 +43,24 @@ jobs:
4343
name: digma-otel-agent-extension
4444
path: ./agent-extension/build/libs/digma-otel-agent-extension*.jar
4545
retention-days: 5
46+
47+
- name: Upload agent-extension tests report
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: agent-extension-tests-report
51+
path: ./agent-extension/build/reports/tests/
52+
retention-days: 5
53+
54+
- name: Upload methods instrumentation tests report
55+
uses: actions/upload-artifact@v3
56+
with:
57+
name: methods-instrumentation-tests-report
58+
path: ./testing/methods/build/reports/tests/
59+
retention-days: 5
60+
61+
- name: Upload java 7 instrumentation tests report
62+
uses: actions/upload-artifact@v3
63+
with:
64+
name: java7-instrumentation-tests-report
65+
path: ./testing/java7/build/reports/tests/
66+
retention-days: 5

.github/workflows/ci-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
- name: GIT Checkout
2020
uses: actions/checkout@v3
2121

22-
- name: Set up JDK 11
22+
- name: Set up JDK 17
2323
uses: actions/setup-java@v3
2424
with:
25-
java-version: '11'
25+
java-version: '17'
2626
distribution: temurin
2727

2828
# using wrapper version (supposed to be 7.5.1)

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ build/*
3535
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
3636
hs_err_pid*
3737

38-
38+
## Idea profiler
3939
.profileconfig.json

DEV_NOTES.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
3+
## Build
4+
./gradlew clean build<br>
5+
or<br>
6+
./gradlew clean build -x test
7+
8+
9+
## When running tests from Idea
10+
turn off your Digma plugin observability :)
11+
12+
## New instrumentation advices
13+
every new advice should be tested with java 7 bytecode.
14+
see Java7CompatibilityTests.
15+
read the comment there.
16+
17+
18+
19+
### Using podman with testcontainers
20+
https://github.com/eugene-khyst/podman-testcontainers?tab=readme-ov-file#5

agent-extension/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ext {
6262
// various instrumentations
6363
springFramework : "5.3.24",
6464
springKafka : "2.7.1",
65-
grpc : "1.6.0",
65+
grpc : "1.63.0",
6666
]
6767

6868
deps = [
@@ -132,6 +132,7 @@ dependencies {
132132
testImplementation("io.opentelemetry.proto:opentelemetry-proto:1.1.0-alpha")
133133

134134
testImplementation("org.junit.jupiter:junit-jupiter-api:${versions.junit}")
135+
testImplementation("org.junit.jupiter:junit-jupiter-params:${versions.junit}")
135136
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${versions.junit}")
136137
testRuntimeOnly("ch.qos.logback:logback-classic:1.5.3")
137138

@@ -142,6 +143,12 @@ dependencies {
142143
testImplementation("org.springframework:spring-context:${versions.springFramework}")
143144
testImplementation("org.springframework:spring-web:${versions.springFramework}")
144145
testImplementation("org.springframework.kafka:spring-kafka:${versions.springKafka}")
146+
testImplementation("io.grpc:grpc-core:${versions.grpc}")
147+
testImplementation("io.grpc:grpc-stub:${versions.grpc}")
148+
testImplementation("io.grpc:grpc-okhttp:${versions.grpc}")
149+
testImplementation("io.grpc:grpc-protobuf:${versions.grpc}")
150+
151+
145152

146153
//TODO remove when start using io.opentelemetry.instrumentation.javaagent-instrumentation plugin
147154
add("codegen", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")

agent-extension/src/main/java/com/digma/otel/javaagent/extension/instrumentation/common/DigmaCurrentSpanAdvice.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.digma.otel.javaagent.extension.instrumentation.common;
22

33
import io.opentelemetry.api.trace.Span;
4+
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
45
import net.bytebuddy.asm.Advice;
56

67
import java.lang.reflect.Method;
@@ -33,10 +34,10 @@ public static void methodEnter(
3334
targetClassName = method.getDeclaringClass().getName();
3435
}
3536

36-
Span currentSpan = Span.current();
37+
Span currentSpan = Java8BytecodeBridge.currentSpan();
3738

38-
currentSpan.setAttribute(stringKey("code.namespace"), targetClassName);
39-
currentSpan.setAttribute(stringKey("code.function"), method.getName());
39+
currentSpan.setAttribute("code.namespace", targetClassName);
40+
currentSpan.setAttribute("code.function", method.getName());
4041
}
4142

4243
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
package com.digma.otel.javaagent.extension.instrumentation.common;
22

33
import io.opentelemetry.api.trace.Span;
4-
import io.opentelemetry.context.Context;
54
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
65
import io.opentelemetry.instrumentation.api.internal.HttpRouteState;
6+
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
77
import net.bytebuddy.asm.Advice;
88

99
import java.lang.reflect.Method;
1010

11-
import static io.opentelemetry.api.common.AttributeKey.stringKey;
12-
1311
public class DigmaServerAdvice {
1412

15-
//Note when declaring static variables here like a logger the advice doesn't run, strange bytebuddy issue
16-
1713
@Advice.OnMethodEnter(suppress = Throwable.class)
1814
public static void methodEnter(
1915
@Advice.This Object target,
@@ -35,46 +31,34 @@ public static void methodEnter(
3531
// taking local root span (servlet of tomcat or jetty) and set the code attributes on it
3632

3733
//Find http route span and set it
38-
HttpRouteState routeStateNew = HttpRouteState.fromContextOrNull(Context.current());
34+
HttpRouteState routeStateNew = HttpRouteState.fromContextOrNull(Java8BytecodeBridge.currentContext());
3935
Span routeSpan = null;
4036

4137
if (routeStateNew != null) {
42-
4338
try {
4439
routeSpan = routeStateNew.getSpan();
4540
if (routeSpan != null) {
46-
47-
routeSpan.setAttribute(stringKey("code.namespace"), targetClassName);
48-
routeSpan.setAttribute(stringKey("code.function"), method.getName());
41+
routeSpan.setAttribute("code.namespace", targetClassName);
42+
routeSpan.setAttribute("code.function", method.getName());
4943
}
5044
} catch (Error e) {
51-
52-
//do nothing
45+
//ignore
5346
}
5447
}
5548

5649
//Fallback to previous behavior
5750
else {
58-
5951
Span rootSpan = LocalRootSpan.current();
6052
if (rootSpan != null) {
61-
// System.out.println("DBG: setting local root span ");
62-
63-
rootSpan.setAttribute(stringKey("code.namespace"), targetClassName);
64-
rootSpan.setAttribute(stringKey("code.function"), method.getName());
53+
rootSpan.setAttribute("code.namespace", targetClassName);
54+
rootSpan.setAttribute("code.function", method.getName());
6555
}
6656
}
6757

68-
Span span = Span.fromContextOrNull(Context.current());
58+
Span span = Java8BytecodeBridge.spanFromContext(Java8BytecodeBridge.currentContext());
6959
if (span != null) {
70-
71-
span.setAttribute(stringKey("code.namespace"), targetClassName);
72-
span.setAttribute(stringKey("code.function"), method.getName());
60+
span.setAttribute("code.namespace", targetClassName);
61+
span.setAttribute("code.function", method.getName());
7362
}
74-
75-
7663
}
77-
78-
79-
8064
}

agent-extension/src/main/java/com/digma/otel/javaagent/extension/instrumentation/common/DigmaTypeInstrumentation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public abstract class DigmaTypeInstrumentation implements TypeInstrumentation {
1111

1212
@Override
1313
public final ElementMatcher<TypeDescription> typeMatcher() {
14+
// return hasClassFileVersionAtLeast(ClassFileVersion.JAVA_V7).and(digmaTypeMatcher());
1415
return hasClassFileVersionAtLeast(ClassFileVersion.JAVA_V8).and(digmaTypeMatcher());
1516
}
1617

agent-extension/src/main/java/com/digma/otel/javaagent/extension/instrumentation/grpc/v1_6/DigmaGrpcInstrumentationModule.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
55
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
66

7+
import java.util.ArrayList;
78
import java.util.Collections;
89
import java.util.List;
910

@@ -34,4 +35,12 @@ public List<TypeInstrumentation> typeInstrumentations() {
3435
return Collections.singletonList(new DigmaGrpcServerBuilderInstrumentation());
3536
}
3637

38+
@Override
39+
public List<String> getAdditionalHelperClassNames() {
40+
List<String> classNames = new ArrayList<>();
41+
classNames.add("io.opentelemetry.instrumentation.api.instrumenter.util.ClassAndMethod");
42+
classNames.add("io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter");
43+
classNames.add("io.opentelemetry.instrumentation.api.instrumenter.util.AutoValue_ClassAndMethod");
44+
return classNames;
45+
}
3746
}

agent-extension/src/main/java/com/digma/otel/javaagent/extension/instrumentation/grpc/v1_6/DigmaGrpcServerBuilderInstrumentation.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ public ElementMatcher<TypeDescription> digmaTypeMatcher() {
3131
@Override
3232
public void transform(TypeTransformer transformer) {
3333
transformer.applyAdviceToMethod(
34-
isMethod().and(isPublic()).and(named("build")).and(takesArguments(0)),
35-
DigmaGrpcServerBuilderInstrumentation.class.getName() + "$DigmaBuildAdvice");
34+
isMethod().and(isPublic()).and(named("build")).and(takesArguments(0)),
35+
DigmaGrpcServerBuilderInstrumentation.class.getName() + "$DigmaBuildAdvice");
3636
}
3737

3838
@SuppressWarnings("unused")
3939
public static class DigmaBuildAdvice {
4040

4141
@Advice.OnMethodEnter(suppress = Throwable.class)
4242
public static void onEnter(
43-
@Advice.This ServerBuilder<?> serverBuilder) {
44-
43+
@Advice.This ServerBuilder<?> serverBuilder) {
4544
serverBuilder.intercept(DigmaTracingServerInterceptor.create());
4645
}
4746
}

0 commit comments

Comments
 (0)