@@ -48,16 +48,19 @@ public abstract class ContractTestBase {
4848
4949 private final Logger collectorLogger =
5050 LoggerFactory .getLogger ("collector " + getApplicationOtelServiceName ());
51- private final Logger applicationLogger =
51+ protected final Logger applicationLogger =
5252 LoggerFactory .getLogger ("application " + getApplicationOtelServiceName ());
5353
54- private static final String AGENT_PATH =
54+ protected static final String AGENT_PATH =
5555 System .getProperty ("io.awsobservability.instrumentation.contracttests.agentPath" );
56+ protected static final String MOUNT_PATH = "/opentelemetry-javaagent-all.jar" ;
5657
5758 protected final Network network = Network .newNetwork ();
5859
5960 private static final String COLLECTOR_HOSTNAME = "collector" ;
6061 private static final int COLLECTOR_PORT = 4317 ;
62+ protected static final String COLLECTOR_HTTP_ENDPOINT =
63+ "http://" + COLLECTOR_HOSTNAME + ":" + COLLECTOR_PORT ;
6164
6265 protected final GenericContainer <?> mockCollector =
6366 new GenericContainer <>("aws-appsignals-mock-collector" )
@@ -67,29 +70,7 @@ public abstract class ContractTestBase {
6770 .withNetwork (network )
6871 .withNetworkAliases (COLLECTOR_HOSTNAME );
6972
70- protected final GenericContainer <?> application =
71- new GenericContainer <>(getApplicationImageName ())
72- .dependsOn (getDependsOn ())
73- .withExposedPorts (getApplicationPort ())
74- .withNetwork (network )
75- .withLogConsumer (new Slf4jLogConsumer (applicationLogger ))
76- .withCopyFileToContainer (
77- MountableFile .forHostPath (AGENT_PATH ), "/opentelemetry-javaagent-all.jar" )
78- .waitingFor (getApplicationWaitCondition ())
79- .withEnv ("JAVA_TOOL_OPTIONS" , "-javaagent:/opentelemetry-javaagent-all.jar" )
80- .withEnv ("OTEL_METRIC_EXPORT_INTERVAL" , "100" ) // 100 ms
81- .withEnv ("OTEL_AWS_APPLICATION_SIGNALS_ENABLED" , "true" )
82- .withEnv ("OTEL_METRICS_EXPORTER" , "none" )
83- .withEnv ("OTEL_BSP_SCHEDULE_DELAY" , "0" ) // Don't wait to export spans to the collector
84- .withEnv (
85- "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" ,
86- "http://" + COLLECTOR_HOSTNAME + ":" + COLLECTOR_PORT )
87- .withEnv (
88- "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" ,
89- "http://" + COLLECTOR_HOSTNAME + ":" + COLLECTOR_PORT )
90- .withEnv ("OTEL_RESOURCE_ATTRIBUTES" , getApplicationOtelResourceAttributes ())
91- .withEnv (getApplicationExtraEnvironmentVariables ())
92- .withNetworkAliases (getApplicationNetworkAliases ().toArray (new String [0 ]));
73+ protected final GenericContainer <?> application = getApplicationContainer ();
9374
9475 protected MockCollectorClient mockCollectorClient ;
9576 protected WebClient appClient ;
@@ -108,10 +89,8 @@ private void stopCollector() {
10889 protected void setupClients () {
10990 application .start ();
11091
111- appClient = WebClient .of ("http://localhost:" + application .getMappedPort (8080 ));
112- mockCollectorClient =
113- new MockCollectorClient (
114- WebClient .of ("http://localhost:" + mockCollector .getMappedPort (4317 )));
92+ appClient = getApplicationClient ();
93+ mockCollectorClient = getMockCollectorClient ();
11594 }
11695
11796 @ AfterEach
@@ -127,11 +106,55 @@ private List<Startable> getDependsOn() {
127106 return dependencies ;
128107 }
129108
109+ protected WebClient getApplicationClient () {
110+ return WebClient .of ("http://localhost:" + application .getMappedPort (8080 ));
111+ }
112+
113+ protected MockCollectorClient getMockCollectorClient () {
114+ return new MockCollectorClient (
115+ WebClient .of ("http://localhost:" + mockCollector .getMappedPort (4317 )));
116+ }
117+
118+ protected GenericContainer <?> getApplicationContainer () {
119+ return new GenericContainer <>(getApplicationImageName ())
120+ .dependsOn (getDependsOn ())
121+ .withExposedPorts (getApplicationPort ())
122+ .withNetwork (network )
123+ .withLogConsumer (new Slf4jLogConsumer (applicationLogger ))
124+ .withCopyFileToContainer (MountableFile .forHostPath (AGENT_PATH ), MOUNT_PATH )
125+ .waitingFor (getApplicationWaitCondition ())
126+ .withEnv (getApplicationEnvironmentVariables ())
127+ .withEnv (getApplicationExtraEnvironmentVariables ())
128+ .withNetworkAliases (getApplicationNetworkAliases ().toArray (new String [0 ]));
129+ }
130+
130131 /** Methods that should be overridden in sub classes * */
131132 protected int getApplicationPort () {
132133 return 8080 ;
133134 }
134135
136+ protected Map <String , String > getApplicationEnvironmentVariables () {
137+ return Map .of (
138+ "JAVA_TOOL_OPTIONS" ,
139+ "-javaagent:" + MOUNT_PATH ,
140+ "OTEL_METRIC_EXPORT_INTERVAL" ,
141+ "100" , // 100 ms
142+ "OTEL_AWS_APPLICATION_SIGNALS_ENABLED" ,
143+ "true" ,
144+ "OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED" ,
145+ isRuntimeEnabled (),
146+ "OTEL_METRICS_EXPORTER" ,
147+ "none" ,
148+ "OTEL_BSP_SCHEDULE_DELAY" ,
149+ "0" , // Don't wait to export spans to the collector
150+ "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT" ,
151+ COLLECTOR_HTTP_ENDPOINT ,
152+ "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" ,
153+ COLLECTOR_HTTP_ENDPOINT ,
154+ "OTEL_RESOURCE_ATTRIBUTES" ,
155+ getApplicationOtelResourceAttributes ());
156+ }
157+
135158 protected Map <String , String > getApplicationExtraEnvironmentVariables () {
136159 return Map .of ();
137160 }
@@ -159,4 +182,8 @@ protected String getApplicationOtelServiceName() {
159182 protected String getApplicationOtelResourceAttributes () {
160183 return "service.name=" + getApplicationOtelServiceName ();
161184 }
185+
186+ protected String isRuntimeEnabled () {
187+ return "false" ;
188+ }
162189}
0 commit comments