55
66package io .opentelemetry .contrib .gcp .auth ;
77
8+ import static io .opentelemetry .api .common .AttributeKey .stringKey ;
9+ import static java .util .Arrays .stream ;
10+ import static java .util .Objects .nonNull ;
11+ import static java .util .stream .Collectors .joining ;
12+ import static java .util .stream .Collectors .toMap ;
13+
814import com .google .auth .oauth2 .GoogleCredentials ;
915import com .google .auto .service .AutoService ;
10- import io .opentelemetry .api .common .AttributeKey ;
1116import io .opentelemetry .api .common .Attributes ;
1217import io .opentelemetry .contrib .gcp .auth .GoogleAuthException .Reason ;
1318import io .opentelemetry .exporter .otlp .http .metrics .OtlpHttpMetricExporter ;
2530import io .opentelemetry .sdk .resources .Resource ;
2631import io .opentelemetry .sdk .trace .export .SpanExporter ;
2732import java .io .IOException ;
28- import java .util .Arrays ;
2933import java .util .List ;
3034import java .util .Map ;
31- import java .util .Objects ;
3235import java .util .Optional ;
3336import java .util .logging .Level ;
3437import java .util .logging .Logger ;
35- import java .util .stream .Collectors ;
3638import javax .annotation .Nonnull ;
3739
3840/**
@@ -150,7 +152,7 @@ private static boolean isSignalTargeted(String checkSignal, ConfigProperties con
150152 String userSpecifiedTargetedSignals =
151153 ConfigurableOption .GOOGLE_OTEL_AUTH_TARGET_SIGNALS .getConfiguredValueWithFallback (
152154 configProperties , () -> SIGNAL_TYPE_ALL );
153- return Arrays . stream (userSpecifiedTargetedSignals .split ("," ))
155+ return stream (userSpecifiedTargetedSignals .split ("," ))
154156 .map (String ::trim )
155157 .anyMatch (
156158 targetedSignal ->
@@ -202,17 +204,16 @@ private static Map<String, String> getRequiredHeaderMap(
202204 } catch (IOException e ) {
203205 throw new GoogleAuthException (Reason .FAILED_ADC_REFRESH , e );
204206 }
205- // flatten list
206207 Map <String , String > flattenedHeaders =
207208 gcpHeaders .entrySet ().stream ()
208209 .collect (
209- Collectors . toMap (
210+ toMap (
210211 Map .Entry ::getKey ,
211212 entry ->
212213 entry .getValue ().stream ()
213- .filter (Objects :: nonNull ) // Filter nulls
214+ .filter (nonNull ) // Filter nulls
214215 .filter (s -> !s .isEmpty ()) // Filter empty strings
215- .collect (Collectors . joining ("," ))));
216+ .collect (joining ("," ))));
216217 // Add quota user project header if not detected by the auth library and user provided it via
217218 // system properties.
218219 if (!flattenedHeaders .containsKey (QUOTA_USER_PROJECT_HEADER )) {
@@ -232,7 +233,7 @@ private static Resource customizeResource(Resource resource, ConfigProperties co
232233 ConfigurableOption .GOOGLE_CLOUD_PROJECT .getConfiguredValue (configProperties );
233234 Resource res =
234235 Resource .create (
235- Attributes .of (AttributeKey . stringKey (GCP_USER_PROJECT_ID_KEY ), gcpProjectId ));
236+ Attributes .of (stringKey (GCP_USER_PROJECT_ID_KEY ), gcpProjectId ));
236237 return resource .merge (res );
237238 }
238239}
0 commit comments