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

Snippet Injection Smoke Test #8655

Merged
merged 9 commits into from
Jun 7, 2023
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
Loading