Skip to content

Commit

Permalink
Make the gcp exporter use ConfigMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Nov 5, 2024
1 parent 0fdedcf commit 35013e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static class GcpExporterEnabled implements BooleanSupplier {
GcpExporterConfig.GcpExporterBuildConfig gcpExporterConfig;

public boolean getAsBoolean() {
return gcpExporterConfig.enabled;
return gcpExporterConfig.enabled();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.ConvertWith;
import io.quarkus.runtime.configuration.TrimmedStringConverter;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithConverter;
import io.smallrye.config.WithDefault;

public class GcpExporterConfig {
@ConfigRoot(name = "opentelemetry.tracer.exporter.gcp", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public static class GcpExporterBuildConfig {
@ConfigMapping(prefix = "quarkus.opentelemetry.tracer.exporter.gcp")
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public interface GcpExporterBuildConfig {
/**
* GCP's Tracing exporter support. Enabled by default.
*/
@ConfigItem(defaultValue = "true")
public Boolean enabled;
@WithDefault(value = "true")
public Boolean enabled();
}

@ConfigRoot(name = "opentelemetry.tracer.exporter.gcp", phase = ConfigPhase.RUN_TIME)
public static class GcpExporterRuntimeConfig {
@ConfigMapping(prefix = "quarkus.opentelemetry.tracer.exporter.gcp")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface GcpExporterRuntimeConfig {
/**
* Override to set GCP's projectid.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
public Optional<String> projectid;
@WithConverter(TrimmedStringConverter.class)
public Optional<String> projectid();

/**
* Override for GCP TraceEndpoint setting.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
public Optional<String> endpoint;
@WithConverter(TrimmedStringConverter.class)
public Optional<String> endpoint();

/**
* Support for Cloud Run environments. Set to `true` for Cloud Run deployments.
* <p>
* Cloud Run <a href="https://cloud.google.com/trace/docs/setup/java-ot#export">doesn't support background processes</a>
* and `SimpleSpanProcessor` must be used.
*/
@ConfigItem(defaultValue = "false")
public Boolean cloudrun;
@WithDefault(value = "false")
public Boolean cloudrun();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Function<SyntheticCreationalContext<LateBoundSpanProcessor>, LateBoundSpa
public LateBoundSpanProcessor apply(
SyntheticCreationalContext<LateBoundSpanProcessor> lateBoundSpanProcessorSyntheticCreationalContext) {

if (launchMode != LaunchMode.TEST && runtimeConfig.endpoint.isEmpty()) {
if (launchMode != LaunchMode.TEST && runtimeConfig.endpoint().isEmpty()) {
try {
return configureTraceExporter(runtimeConfig);
} catch (IOException e) {
Expand All @@ -35,13 +35,13 @@ public LateBoundSpanProcessor apply(
} else {
TraceConfiguration.Builder builder = TestTraceConfigurationBuilder.buildTestTraceConfiguration();

if (runtimeConfig.endpoint.isPresent() && runtimeConfig.endpoint.get().trim().length() > 0) {
builder.setTraceServiceEndpoint(runtimeConfig.endpoint.get());
if (runtimeConfig.endpoint().isPresent() && runtimeConfig.endpoint().get().trim().length() > 0) {
builder.setTraceServiceEndpoint(runtimeConfig.endpoint().get());
}

TraceConfiguration config = builder.build();
try {
if (runtimeConfig.cloudrun) {
if (runtimeConfig.cloudrun()) {
return configureSimpleSpanExporter(config);
} else {
return configureBatchSpanExporter(config);
Expand All @@ -58,13 +58,13 @@ private LateBoundSpanProcessor configureTraceExporter(GcpExporterConfig.GcpExpor
throws IOException {
TraceConfiguration.Builder builder = TraceConfiguration.builder();

if (runtimeConfig.projectid.isPresent() && runtimeConfig.projectid.get().trim().length() > 0) {
builder.setProjectId(runtimeConfig.projectid.get());
if (runtimeConfig.projectid().isPresent() && runtimeConfig.projectid().get().trim().length() > 0) {
builder.setProjectId(runtimeConfig.projectid().get());
}

TraceConfiguration traceConfig = builder.build();
// Initialize GCP TraceExporter default configuration
if (runtimeConfig.cloudrun) {
if (runtimeConfig.cloudrun()) {
return configureSimpleSpanExporter(traceConfig);
} else {
return configureBatchSpanExporter(traceConfig);
Expand Down

0 comments on commit 35013e7

Please sign in to comment.