3838import io .opentelemetry .sdk .trace .export .BatchSpanProcessor ;
3939import io .opentelemetry .sdk .trace .export .SpanExporter ;
4040import io .opentelemetry .sdk .trace .samplers .Sampler ;
41+ import java .util .Collection ;
42+ import java .util .Collections ;
4143import java .util .Objects ;
4244import java .util .Random ;
4345import java .util .concurrent .ExecutionException ;
@@ -79,10 +81,22 @@ public class IntegrationTestEnv extends ExternalResource {
7981 private final boolean alwaysCreateNewInstance ;
8082 private RemoteSpannerHelper testHelper ;
8183
84+ private Collection <TestEnvOptions > testEnvOptions = Collections .emptyList ();
85+
86+ public enum TestEnvOptions {
87+ USE_END_TO_END_TRACING ;
88+ // TODO : Move alwaysCreateNewInstance to TestEnvOptions
89+ }
90+
8291 public IntegrationTestEnv () {
8392 this (false );
8493 }
8594
95+ public IntegrationTestEnv (Collection <TestEnvOptions > testEnvOptions ) {
96+ this (false );
97+ this .testEnvOptions = testEnvOptions ;
98+ }
99+
86100 public IntegrationTestEnv (final boolean alwaysCreateNewInstance ) {
87101 this .alwaysCreateNewInstance = alwaysCreateNewInstance ;
88102 }
@@ -119,10 +133,15 @@ protected void before() throws Throwable {
119133 assumeFalse (alwaysCreateNewInstance && isCloudDevel ());
120134
121135 this .config .setUp ();
122- // OpenTelemetry set up for enabling End to End tracing for all integration test env.
123- // The gRPC stub and connections are created during test env set up using SpannerOptions and are
124- // reused for executing statements.
125- SpannerOptions options = spannerOptionsWithEndToEndTracing ();
136+ SpannerOptions options = config .spannerOptions ();
137+ if (testEnvOptions .stream ()
138+ .anyMatch (testEnvOption -> TestEnvOptions .USE_END_TO_END_TRACING .equals (testEnvOption ))) {
139+ // OpenTelemetry set up for enabling End to End tracing for all integration test env.
140+ // The gRPC stub and connections are created during test env set up using SpannerOptions and
141+ // are
142+ // reused for executing statements.
143+ options = spannerOptionsWithEndToEndTracing (options );
144+ }
126145 String instanceProperty = System .getProperty (TEST_INSTANCE_PROPERTY , "" );
127146 InstanceId instanceId ;
128147 if (!instanceProperty .isEmpty () && !alwaysCreateNewInstance ) {
@@ -147,11 +166,10 @@ protected void before() throws Throwable {
147166 }
148167 }
149168
150- public SpannerOptions spannerOptionsWithEndToEndTracing () {
169+ public SpannerOptions spannerOptionsWithEndToEndTracing (SpannerOptions options ) {
151170 GlobalOpenTelemetry .resetForTest (); // reset global context for test
152171 assumeFalse ("This test requires credentials" , EmulatorSpannerHelper .isUsingEmulator ());
153172
154- SpannerOptions options = config .spannerOptions ();
155173 TraceConfiguration .Builder traceConfigurationBuilder = TraceConfiguration .builder ();
156174 if (options .getCredentials () != null ) {
157175 traceConfigurationBuilder .setCredentials (options .getCredentials ());
0 commit comments