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,16 @@

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", ""));
new AtomicReference<>(
ConfigPropertiesUtil.getString("otel.experimental.javascript-snippet") == null
? ""
: ConfigPropertiesUtil.getString("otel.experimental.javascript-snippet"));
trask marked this conversation as resolved.
Show resolved Hide resolved

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,27 @@ 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>")

traces.countSpansByKind(Span.SpanKind.SPAN_KIND_SERVER) == 1

traces.countSpansByName('GET /app/jsp') == 1

where:
[appServer, jdk] << getTestParams()
}

protected String getSpanName(String path) {
switch (path) {
case "/app/greeting":
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