1+ /*
2+ * Copyright The OpenTelemetry Authors
3+ * SPDX-License-Identifier: Apache-2.0
4+ */
5+
16package io .opentelemetry .javaagent .instrumentation .sling ;
27
38import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
813import io .opentelemetry .instrumentation .testing .junit .http .HttpServerInstrumentationExtension ;
914import io .opentelemetry .javaagent .testing .common .TestAgentListenerAccess ;
1015import io .opentelemetry .sdk .common .InstrumentationScopeInfo ;
16+ import io .opentelemetry .sdk .trace .data .SpanData ;
1117import io .opentelemetry .testing .internal .armeria .common .AggregatedHttpResponse ;
1218import io .opentelemetry .testing .internal .armeria .common .HttpResponse ;
19+ import java .net .Socket ;
20+ import java .nio .file .Files ;
21+ import java .nio .file .Path ;
22+ import java .time .Duration ;
23+ import java .util .List ;
24+ import java .util .concurrent .CompletableFuture ;
1325import org .apache .sling .feature .launcher .impl .Bootstrap ;
1426import org .apache .sling .feature .launcher .impl .LauncherConfig ;
1527import org .awaitility .Awaitility ;
1931import org .junit .jupiter .api .extension .RegisterExtension ;
2032import org .slf4j .Logger ;
2133import org .slf4j .LoggerFactory ;
22- import java .net .Socket ;
23- import java .util .List ;
24- import java .nio .file .Files ;
25- import java .nio .file .Path ;
26- import java .time .Duration ;
27- import java .util .concurrent .CompletableFuture ;
28- import io .opentelemetry .sdk .trace .data .SpanData ;
29- import io .opentelemetry .api .trace .SpanKind ;
3034
3135public class SlingTest extends AbstractHttpServerUsingTest <Void > {
3236
@@ -48,8 +52,8 @@ void cleanup() {
4852
4953 @ Test
5054 void basic () throws Exception {
51- AggregatedHttpResponse response = client . get ( address . resolve ( "starter.html" ). toString ())
52- .aggregate ().join ();
55+ AggregatedHttpResponse response =
56+ client . get ( address . resolve ( "starter.html" ). toString ()) .aggregate ().join ();
5357
5458 assertThat (response .status ().code ()).isEqualTo (200 );
5559
@@ -58,22 +62,43 @@ void basic() throws Exception {
5862 TestAgentListenerAccess .getAndResetAdviceFailureCount ();
5963
6064 // FIXME - Muzzle checks we need to clarify
61- // [otel.javaagent 2025-07-02 13:00:07:012 +0200] [FelixStartLevel] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - Instrumentation skipped, mismatched references were found: sling [class io.opentelemetry.javaagent.instrumentation.sling.SlingInstrumentationModule] on org.apache.sling.installer.console [217]
62- // [otel.javaagent 2025-07-02 13:00:07:012 +0200] [FelixStartLevel] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - -- io.opentelemetry.javaagent.instrumentation.sling.ServletResolverInstrumentation$ResolveServletAdvice:65 Missing class javax.servlet.http.HttpServletRequest
63- // [otel.javaagent 2025-07-02 13:00:07:015 +0200] [FelixStartLevel] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - Instrumentation skipped, mismatched references were found: servlet [class io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3InstrumentationModule] on org.apache.sling.installer.console [217]
64- // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - -- io.opentelemetry.javaagent.instrumentation.servlet.v3_0.snippet.Servlet3SnippetInjectingResponseWrapper:56 Missing class javax.servlet.http.HttpServletResponse
65- // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - -- io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Accessor:28 Missing class javax.servlet.http.HttpServletRequest
66- // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - -- io.opentelemetry.javaagent.instrumentation.servlet.v3_0.snippet.ServletOutputStreamInjectionState:20 Missing method io.opentelemetry.javaagent.bootstrap.servlet.SnippetInjectingResponseWrapper#getCharacterEncoding()Ljava/lang/String;
67- // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - -- io.opentelemetry.javaagent.instrumentation.servlet.v3_0.snippet.Servlet3SnippetInjectingResponseWrapper:0 Missing class javax.servlet.http.HttpServletResponseWrapper
65+ // [otel.javaagent 2025-07-02 13:00:07:012 +0200] [FelixStartLevel] WARN
66+ // io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - Instrumentation skipped,
67+ // mismatched references were found: sling [class
68+ // io.opentelemetry.javaagent.instrumentation.sling.SlingInstrumentationModule] on
69+ // org.apache.sling.installer.console [217]
70+ // [otel.javaagent 2025-07-02 13:00:07:012 +0200] [FelixStartLevel] WARN
71+ // io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - --
72+ // io.opentelemetry.javaagent.instrumentation.sling.ServletResolverInstrumentation$ResolveServletAdvice:65 Missing class javax.servlet.http.HttpServletRequest
73+ // [otel.javaagent 2025-07-02 13:00:07:015 +0200] [FelixStartLevel] WARN
74+ // io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - Instrumentation skipped,
75+ // mismatched references were found: servlet [class
76+ // io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3InstrumentationModule] on
77+ // org.apache.sling.installer.console [217]
78+ // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN
79+ // io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - --
80+ // io.opentelemetry.javaagent.instrumentation.servlet.v3_0.snippet.Servlet3SnippetInjectingResponseWrapper:56 Missing class javax.servlet.http.HttpServletResponse
81+ // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN
82+ // io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - --
83+ // io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Accessor:28 Missing class
84+ // javax.servlet.http.HttpServletRequest
85+ // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN
86+ // io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - --
87+ // io.opentelemetry.javaagent.instrumentation.servlet.v3_0.snippet.ServletOutputStreamInjectionState:20 Missing method io.opentelemetry.javaagent.bootstrap.servlet.SnippetInjectingResponseWrapper#getCharacterEncoding()Ljava/lang/String;
88+ // [otel.javaagent 2025-07-02 13:00:07:017 +0200] [FelixStartLevel] WARN
89+ // io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - --
90+ // io.opentelemetry.javaagent.instrumentation.servlet.v3_0.snippet.Servlet3SnippetInjectingResponseWrapper:0 Missing class javax.servlet.http.HttpServletResponseWrapper
6891 //
69- // Potentially because of optional imports - Import-Package: javax.servlet;resolution:=optional;version="[3.1,4)"
92+ // Potentially because of optional imports - Import-Package:
93+ // javax.servlet;resolution:=optional;version="[3.1,4)"
7094 TestAgentListenerAccess .getAndResetMuzzleFailureCount ();
7195
7296 List <List <SpanData >> traces = testing .waitForTraces (1 );
7397
74- traces .forEach (trace -> {
75- System .out .println ("!!!Trace: " + trace );
76- });
98+ traces .forEach (
99+ trace -> {
100+ System .out .println ("!!!Trace: " + trace );
101+ });
77102
78103 List <SpanData > mainTrace = traces .get (0 );
79104 assertThat (mainTrace ).hasSize (3 );
@@ -83,7 +108,8 @@ void basic() throws Exception {
83108 .hasAttributesSatisfying (
84109 attributes -> {
85110 assertThat (attributes ).containsEntry ("http.request.method" , "GET" );
86- assertThat (attributes ).containsEntry ("http.route" , "/apps/sling/starter/home/home.html.esp" );
111+ assertThat (attributes )
112+ .containsEntry ("http.route" , "/apps/sling/starter/home/home.html.esp" );
87113 });
88114
89115 assertThat (mainTrace .get (1 ))
@@ -103,48 +129,52 @@ protected Void setupServer() throws Exception {
103129 Path homeDir = Files .createTempDirectory ("javaagent_sling-test" );
104130
105131 LauncherConfig cfg = new LauncherConfig ();
106- cfg .getInstallation ().addFrameworkProperty ("org.osgi.service.http.port" , String .valueOf (this .port ));
132+ cfg .getInstallation ()
133+ .addFrameworkProperty ("org.osgi.service.http.port" , String .valueOf (this .port ));
107134 cfg .setHomeDirectory (homeDir .toFile ());
108- cfg .addFeatureFiles ("mvn:org.apache.sling/org.apache.sling.starter/13/slingosgifeature/oak_tar" );
109-
110- CompletableFuture .runAsync (() -> {
111- try {
112- Bootstrap b = new Bootstrap (cfg , log );
113- b .runWithException ();
114- } catch (Exception e ) {
115- e .printStackTrace (System .err );
116- // throw new RuntimeException(e);
117- }
118- });
135+ cfg .addFeatureFiles (
136+ "mvn:org.apache.sling/org.apache.sling.starter/13/slingosgifeature/oak_tar" );
137+
138+ CompletableFuture .runAsync (
139+ () -> {
140+ try {
141+ Bootstrap b = new Bootstrap (cfg , log );
142+ b .runWithException ();
143+ } catch (Exception e ) {
144+ e .printStackTrace (System .err );
145+ // throw new RuntimeException(e);
146+ }
147+ });
119148
120149 Awaitility .await ()
121150 .atMost (Duration .ofMinutes (1 ))
122151 .pollInterval (Duration .ofMillis (500 ))
123152 .ignoreExceptions ()
124- .until (() -> {
125- try ( Socket s = new Socket ( address . getHost (), address . getPort ())) {
126- return s . isConnected ();
127- } catch ( Exception e ) {
128- return false ;
129- }
130-
131- });
153+ .until (
154+ () -> {
155+ try ( Socket s = new Socket ( address . getHost (), address . getPort ())) {
156+ return s . isConnected ();
157+ } catch ( Exception e ) {
158+ return false ;
159+ }
160+ });
132161
133162 System .err .println ("Sling server bound to " + address );
134163
135164 Awaitility .await ()
136- .atMost ( Duration .ofMinutes (4 ))
137- .pollInterval ( Duration .ofMillis (500 ))
165+ .atMost (Duration .ofMinutes (4 ))
166+ .pollInterval (Duration .ofMillis (500 ))
138167 .ignoreExceptions ()
139- .until (() -> {
140- try {
141- HttpResponse response = client .get (address .resolve ("/" ).toString ());
142- return response .aggregate ().join ().status ().code () >= 200
143- && response .aggregate ().join ().status ().code () < 400 ;
144- } catch (RuntimeException e ) {
145- return false ;
146- }
147- });
168+ .until (
169+ () -> {
170+ try {
171+ HttpResponse response = client .get (address .resolve ("/" ).toString ());
172+ return response .aggregate ().join ().status ().code () >= 200
173+ && response .aggregate ().join ().status ().code () < 400 ;
174+ } catch (RuntimeException e ) {
175+ return false ;
176+ }
177+ });
148178
149179 System .err .println ("Sling server serving requests at " + address );
150180
0 commit comments