Snippet Injection Smoke Test (#8655)

Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
This commit is contained in:
siyuniu-ms 2023-06-07 14:33:19 -07:00 committed by GitHub
parent 1263e47ec2
commit 012657e596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 23 deletions

View File

@ -5,12 +5,17 @@
package io.opentelemetry.javaagent.bootstrap.servlet;
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil;
import java.util.concurrent.atomic.AtomicReference;
public class ExperimentalSnippetHolder {
private static final AtomicReference<String> snippet =
new AtomicReference<>(System.getProperty("otel.experimental.javascript-snippet", ""));
private static final AtomicReference<String> snippet = new AtomicReference<>(getSnippetSetting());
private static String getSnippetSetting() {
String result = ConfigPropertiesUtil.getString("otel.experimental.javascript-snippet");
return result == null ? "" : result;
}
public static void setSnippet(String newValue) {
snippet.compareAndSet("", newValue);

View File

@ -369,6 +369,31 @@ abstract class AppServerTest extends SmokeTest {
[appServer, jdk, isWindows] << getTestParams()
}
@Unroll
def "JSP smoke test for Snippet Injection"() {
when:
def response = client().get("/app/jsp").aggregate().join()
TraceInspector traces = new TraceInspector(waitForTraces())
String responseBody = response.contentUtf8()
then:
response.status().isSuccess()
responseBody.contains("Successful JSP test")
responseBody.contains("<script>console.log(hi)</script>")
if (expectServerSpan()){
traces.countSpansByKind(Span.SpanKind.SPAN_KIND_SERVER) == 1
traces.countSpansByName('GET /app/jsp') == 1
}
where:
[appServer, jdk] << getTestParams()
}
protected boolean expectServerSpan() {
true
}
protected String getSpanName(String path) {
switch (path) {
case "/app/greeting":

View File

@ -17,6 +17,11 @@ abstract class TomcatSmokeTest extends AppServerTest {
protected TargetWaitStrategy getWaitStrategy() {
return new TargetWaitStrategy.Log(Duration.ofMinutes(1), ".*Server startup in.*")
}
@Override
protected boolean expectServerSpan() {
return this.serverVersion != "7.0.109"
}
}
@AppServer(version = "7.0.109", jdk = "8")

View File

@ -5,9 +5,6 @@
package io.opentelemetry.smoketest
import io.opentelemetry.proto.trace.v1.Span
import spock.lang.Unroll
import java.time.Duration
abstract class WildflySmokeTest extends AppServerTest {
@ -21,24 +18,6 @@ abstract class WildflySmokeTest extends AppServerTest {
return new TargetWaitStrategy.Log(Duration.ofMinutes(1), ".*started in.*")
}
@Unroll
def "JSP smoke test on WildFly"() {
when:
def response = client().get("/app/jsp").aggregate().join()
TraceInspector traces = new TraceInspector(waitForTraces())
String responseBody = response.contentUtf8()
then:
response.status().isSuccess()
responseBody.contains("Successful JSP test")
traces.countSpansByKind(Span.SpanKind.SPAN_KIND_SERVER) == 1
traces.countSpansByName('GET /app/jsp') == 1
where:
[appServer, jdk] << getTestParams()
}
}
@AppServer(version = "13.0.0.Final", jdk = "8")

View File

@ -32,6 +32,7 @@ public abstract class AbstractTestContainerManager implements TestContainerManag
environment.put("OTEL_RESOURCE_ATTRIBUTES", "service.name=smoke-test");
}
environment.put("OTEL_JAVAAGENT_DEBUG", "true");
environment.put("OTEL_EXPERIMENTAL_JAVASCRIPT_SNIPPET", "<script>console.log(hi)</script>");
return environment;
}