Skip to content

Commit

Permalink
Merge pull request #487 from geoand/quarkus-#35500
Browse files Browse the repository at this point in the history
Prevent the usage of OpenTelemetry in GcpDefaultsConfigSourceFactory
  • Loading branch information
loicmathieu authored Aug 24, 2023
2 parents 5ec2584 + 2f5cda7 commit 8197daf
Showing 1 changed file with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,39 @@
import io.smallrye.config.PropertiesConfigSource;

public class GcpDefaultsConfigSourceFactory implements ConfigSourceFactory {

private static final String OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP = "io.opentelemetry.context.contextStorageProvider";

@Override
public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context) {
ConfigValue enableMetadataServer = context.getValue("quarkus.google.cloud.enable-metadata-server");
if (enableMetadataServer.getValue() != null) {
if (Converters.getImplicitConverter(Boolean.class).convert(enableMetadataServer.getValue())) {
String defaultProjectId = ServiceOptions.getDefaultProjectId();
if (defaultProjectId != null) {
return singletonList(
new PropertiesConfigSource(Map.of("quarkus.google.cloud.project-id", defaultProjectId),
"GcpDefaultsConfigSource",
-Integer.MAX_VALUE));
String previousContextStorageSysProp = null;
try {
// Google HTTP Client under the hood which attempts to record traces via OpenCensus which is wired
// to delegate to OpenTelemetry.
// This can lead to problems with the Quarkus OpenTelemetry extension which expects Vert.x to be running,
// something that is not the case at build time, see https://github.com/quarkusio/quarkus/issues/35500
previousContextStorageSysProp = System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP,
"default");

String defaultProjectId = ServiceOptions.getDefaultProjectId();
if (defaultProjectId != null) {
return singletonList(
new PropertiesConfigSource(Map.of("quarkus.google.cloud.project-id", defaultProjectId),
"GcpDefaultsConfigSource",
-Integer.MAX_VALUE));
}
} finally {
if (previousContextStorageSysProp == null) {
System.clearProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP);
} else {
System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP,
previousContextStorageSysProp);
}
}

}
}
return emptyList();
Expand Down

0 comments on commit 8197daf

Please sign in to comment.