Skip to content

Commit

Permalink
Snippet Injection Smoke Test (#8655)
Browse files Browse the repository at this point in the history
Co-authored-by: Mateusz Rzeszutek <[email protected]>
  • Loading branch information
siyuniu-ms and Mateusz Rzeszutek committed Jun 7, 2023
1 parent 1263e47 commit 012657e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected Map<String, String> getAgentEnvironment(
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;
}

Expand Down

0 comments on commit 012657e

Please sign in to comment.