5
5
6
6
package io .opentelemetry .contrib .gcp .auth ;
7
7
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
+
8
14
import com .google .auth .oauth2 .GoogleCredentials ;
9
15
import com .google .auto .service .AutoService ;
10
- import io .opentelemetry .api .common .AttributeKey ;
11
16
import io .opentelemetry .api .common .Attributes ;
12
17
import io .opentelemetry .contrib .gcp .auth .GoogleAuthException .Reason ;
13
18
import io .opentelemetry .exporter .otlp .http .metrics .OtlpHttpMetricExporter ;
25
30
import io .opentelemetry .sdk .resources .Resource ;
26
31
import io .opentelemetry .sdk .trace .export .SpanExporter ;
27
32
import java .io .IOException ;
28
- import java .util .Arrays ;
29
33
import java .util .List ;
30
34
import java .util .Map ;
31
- import java .util .Objects ;
32
35
import java .util .Optional ;
33
36
import java .util .logging .Level ;
34
37
import java .util .logging .Logger ;
35
- import java .util .stream .Collectors ;
36
38
import javax .annotation .Nonnull ;
37
39
38
40
/**
@@ -150,7 +152,7 @@ private static boolean isSignalTargeted(String checkSignal, ConfigProperties con
150
152
String userSpecifiedTargetedSignals =
151
153
ConfigurableOption .GOOGLE_OTEL_AUTH_TARGET_SIGNALS .getConfiguredValueWithFallback (
152
154
configProperties , () -> SIGNAL_TYPE_ALL );
153
- return Arrays . stream (userSpecifiedTargetedSignals .split ("," ))
155
+ return stream (userSpecifiedTargetedSignals .split ("," ))
154
156
.map (String ::trim )
155
157
.anyMatch (
156
158
targetedSignal ->
@@ -202,17 +204,16 @@ private static Map<String, String> getRequiredHeaderMap(
202
204
} catch (IOException e ) {
203
205
throw new GoogleAuthException (Reason .FAILED_ADC_REFRESH , e );
204
206
}
205
- // flatten list
206
207
Map <String , String > flattenedHeaders =
207
208
gcpHeaders .entrySet ().stream ()
208
209
.collect (
209
- Collectors . toMap (
210
+ toMap (
210
211
Map .Entry ::getKey ,
211
212
entry ->
212
213
entry .getValue ().stream ()
213
- .filter (Objects :: nonNull ) // Filter nulls
214
+ .filter (nonNull ) // Filter nulls
214
215
.filter (s -> !s .isEmpty ()) // Filter empty strings
215
- .collect (Collectors . joining ("," ))));
216
+ .collect (joining ("," ))));
216
217
// Add quota user project header if not detected by the auth library and user provided it via
217
218
// system properties.
218
219
if (!flattenedHeaders .containsKey (QUOTA_USER_PROJECT_HEADER )) {
@@ -232,7 +233,7 @@ private static Resource customizeResource(Resource resource, ConfigProperties co
232
233
ConfigurableOption .GOOGLE_CLOUD_PROJECT .getConfiguredValue (configProperties );
233
234
Resource res =
234
235
Resource .create (
235
- Attributes .of (AttributeKey . stringKey (GCP_USER_PROJECT_ID_KEY ), gcpProjectId ));
236
+ Attributes .of (stringKey (GCP_USER_PROJECT_ID_KEY ), gcpProjectId ));
236
237
return resource .merge (res );
237
238
}
238
239
}
0 commit comments