Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

package io.opentelemetry.contrib.gcp.auth;

import static java.util.Arrays.stream;
import static java.util.Objects.requireNonNull;
import static java.util.logging.Level.WARNING;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.auto.service.AutoService;
import io.opentelemetry.api.common.AttributeKey;
Expand All @@ -25,14 +31,11 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

/**
Expand All @@ -49,7 +52,7 @@
* @see GoogleCredentials
*/
@AutoService(AutoConfigurationCustomizerProvider.class)
public class GcpAuthAutoConfigurationCustomizerProvider
public final class GcpAuthAutoConfigurationCustomizerProvider
implements AutoConfigurationCustomizerProvider {

private static final Logger logger =
Expand Down Expand Up @@ -96,6 +99,7 @@ public class GcpAuthAutoConfigurationCustomizerProvider
*/
@Override
public void customize(@Nonnull AutoConfigurationCustomizer autoConfiguration) {
requireNonNull(autoConfiguration, "autoConfiguration");
GoogleCredentials credentials;
try {
credentials = GoogleCredentials.getApplicationDefault();
Expand Down Expand Up @@ -124,7 +128,7 @@ private static SpanExporter customizeSpanExporter(
} else {
String[] params = {SIGNAL_TYPE_TRACES, SIGNAL_TARGET_WARNING_FIX_SUGGESTION};
logger.log(
Level.WARNING,
WARNING,
"GCP Authentication Extension is not configured for signal type: {0}. {1}",
params);
}
Expand All @@ -138,7 +142,7 @@ private static MetricExporter customizeMetricExporter(
} else {
String[] params = {SIGNAL_TYPE_METRICS, SIGNAL_TARGET_WARNING_FIX_SUGGESTION};
logger.log(
Level.WARNING,
WARNING,
"GCP Authentication Extension is not configured for signal type: {0}. {1}",
params);
}
Expand All @@ -150,7 +154,7 @@ private static boolean isSignalTargeted(String checkSignal, ConfigProperties con
String userSpecifiedTargetedSignals =
ConfigurableOption.GOOGLE_OTEL_AUTH_TARGET_SIGNALS.getConfiguredValueWithFallback(
configProperties, () -> SIGNAL_TYPE_ALL);
return Arrays.stream(userSpecifiedTargetedSignals.split(","))
return stream(userSpecifiedTargetedSignals.split(","))
.map(String::trim)
.anyMatch(
targetedSignal ->
Expand Down Expand Up @@ -206,13 +210,13 @@ private static Map<String, String> getRequiredHeaderMap(
Map<String, String> flattenedHeaders =
gcpHeaders.entrySet().stream()
.collect(
Collectors.toMap(
toMap(
Map.Entry::getKey,
entry ->
entry.getValue().stream()
.filter(Objects::nonNull) // Filter nulls
.filter(s -> !s.isEmpty()) // Filter empty strings
.collect(Collectors.joining(","))));
.collect(joining(","))));
// Add quota user project header if not detected by the auth library and user provided it via
// system properties.
if (!flattenedHeaders.containsKey(QUOTA_USER_PROJECT_HEADER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* thrown when there are issues with retrieving or refreshing Google Application Default Credentials
* (ADC).
*/
public class GoogleAuthException extends RuntimeException {
public final class GoogleAuthException extends RuntimeException {

private static final long serialVersionUID = 149908685226796448L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
@SpringBootTest(
classes = {Application.class},
webEnvironment = WebEnvironment.RANDOM_PORT)
public class GcpAuthExtensionEndToEndTest {
class GcpAuthExtensionEndToEndTest {

@LocalServerPort private int testApplicationPort; // port at which the spring app is running

Expand Down