Skip to content

Commit cc8d663

Browse files
committed
Add warning logs to indicate possible misconfiguration
1 parent b41abc8 commit cc8d663

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

gcp-auth-extension/src/main/java/io/opentelemetry/contrib/gcp/auth/ConfigurableOption.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ enum ConfigurableOption {
5151
* configured using the environment variable `GOOGLE_OTEL_AUTH_TARGET_SIGNALS` or the system
5252
* property `google.otel.auth.target.signals`.
5353
*/
54-
GOOGLE_OTEL_AUTH_TARGET_SIGNALS("Target Signals for Google Auth Extension");
54+
GOOGLE_OTEL_AUTH_TARGET_SIGNALS("Target Signals for Google Authentication Extension");
5555

5656
private final String userReadableName;
5757
private final String environmentVariableName;
@@ -82,6 +82,15 @@ String getSystemProperty() {
8282
return this.systemPropertyName;
8383
}
8484

85+
/**
86+
* Returns the user readable name associated with this option.
87+
*
88+
* @return the user readable name (e.g., "Google Cloud Quota Project ID")
89+
*/
90+
String getUserReadableName() {
91+
return this.userReadableName;
92+
}
93+
8594
/**
8695
* Retrieves the configured value for this option. This method checks the environment variable
8796
* first and then the system property.

gcp-auth-extension/src/main/java/io/opentelemetry/contrib/gcp/auth/GcpAuthAutoConfigurationCustomizerProvider.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.Map;
3131
import java.util.Objects;
3232
import java.util.Optional;
33+
import java.util.logging.Level;
34+
import java.util.logging.Logger;
3335
import java.util.stream.Collectors;
3436
import javax.annotation.Nonnull;
3537

@@ -50,6 +52,18 @@
5052
public class GcpAuthAutoConfigurationCustomizerProvider
5153
implements AutoConfigurationCustomizerProvider {
5254

55+
private static final Logger logger =
56+
Logger.getLogger(GcpAuthAutoConfigurationCustomizerProvider.class.getName());
57+
private static final String SIGNAL_TARGET_WARNING_FIX_SUGGESTION =
58+
String.format(
59+
"You may safely ignore this warning if it is intentional, otherwise please configure the '%s' by exporting valid values to environment variable: %s or by setting valid values in system property: %s.",
60+
ConfigurableOption.GOOGLE_OTEL_AUTH_TARGET_SIGNALS.getUserReadableName(),
61+
ConfigurableOption.GOOGLE_OTEL_AUTH_TARGET_SIGNALS.getEnvironmentVariable(),
62+
ConfigurableOption.GOOGLE_OTEL_AUTH_TARGET_SIGNALS.getSystemProperty());
63+
private static final String SIGNAL_TARGET_WARNING_MSG =
64+
"GCP Authentication Extension is not configured for signal type: %s. "
65+
+ SIGNAL_TARGET_WARNING_FIX_SUGGESTION;
66+
5367
static final String QUOTA_USER_PROJECT_HEADER = "x-goog-user-project";
5468
static final String GCP_USER_PROJECT_ID_KEY = "gcp.project_id";
5569

@@ -110,6 +124,8 @@ private static SpanExporter customizeSpanExporter(
110124
SpanExporter exporter, GoogleCredentials credentials, ConfigProperties configProperties) {
111125
if (isSignalTargeted(SIGNAL_TYPE_TRACES, configProperties)) {
112126
return addAuthorizationHeaders(exporter, credentials, configProperties);
127+
} else {
128+
logger.log(Level.WARNING, String.format(SIGNAL_TARGET_WARNING_MSG, SIGNAL_TYPE_TRACES));
113129
}
114130
return exporter;
115131
}
@@ -118,6 +134,8 @@ private static MetricExporter customizeMetricExporter(
118134
MetricExporter exporter, GoogleCredentials credentials, ConfigProperties configProperties) {
119135
if (isSignalTargeted(SIGNAL_TYPE_METRICS, configProperties)) {
120136
return addAuthorizationHeaders(exporter, credentials, configProperties);
137+
} else {
138+
logger.log(Level.WARNING, String.format(SIGNAL_TARGET_WARNING_MSG, SIGNAL_TYPE_METRICS));
121139
}
122140
return exporter;
123141
}

0 commit comments

Comments
 (0)