Skip to content

Commit 3e1cf29

Browse files
committed
Add test methods to support metrics export testing
1 parent be8e25d commit 3e1cf29

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

gcp-auth-extension/src/test/java/io/opentelemetry/contrib/gcp/auth/GcpAuthAutoConfigurationCustomizerProviderTest.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
3232
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
3333
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
34+
import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider;
3435
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider;
3536
import io.opentelemetry.sdk.common.CompletableResultCode;
37+
import io.opentelemetry.sdk.metrics.export.MetricExporter;
3638
import io.opentelemetry.sdk.trace.data.SpanData;
3739
import io.opentelemetry.sdk.trace.export.SpanExporter;
3840
import java.io.IOException;
@@ -428,10 +430,29 @@ private void prepareMockBehaviorForGoogleCredentials() {
428430
}
429431

430432
private OpenTelemetrySdk buildOpenTelemetrySdkWithExporter(SpanExporter spanExporter) {
433+
return buildOpenTelemetrySdkWithExporter(spanExporter, null, otelProperties);
434+
}
435+
436+
@SuppressWarnings("UnusedMethod")
437+
private OpenTelemetrySdk buildOpenTelemetrySdkWithExporter(SpanExporter spanExporter, ImmutableMap<String, String> customOTelProperties) {
438+
return buildOpenTelemetrySdkWithExporter(spanExporter, null, customOTelProperties);
439+
}
440+
441+
@SuppressWarnings("UnusedMethod")
442+
private OpenTelemetrySdk buildOpenTelemetrySdkWithExporter(MetricExporter metricExporter) {
443+
return buildOpenTelemetrySdkWithExporter(null, metricExporter, otelProperties);
444+
}
445+
446+
@SuppressWarnings("UnusedMethod")
447+
private OpenTelemetrySdk buildOpenTelemetrySdkWithExporter(MetricExporter metricExporter, ImmutableMap<String, String> customOtelProperties) {
448+
return buildOpenTelemetrySdkWithExporter(null, metricExporter, customOtelProperties);
449+
}
450+
451+
private OpenTelemetrySdk buildOpenTelemetrySdkWithExporter(SpanExporter spanExporter, MetricExporter metricExporter, ImmutableMap<String, String> customOtelProperties) {
431452
SpiHelper spiHelper =
432453
SpiHelper.create(GcpAuthAutoConfigurationCustomizerProviderTest.class.getClassLoader());
433454
AutoConfiguredOpenTelemetrySdkBuilder builder =
434-
AutoConfiguredOpenTelemetrySdk.builder().addPropertiesSupplier(() -> otelProperties);
455+
AutoConfiguredOpenTelemetrySdk.builder().addPropertiesSupplier(() -> customOtelProperties);
435456
AutoConfigureUtil.setComponentLoader(
436457
builder,
437458
new ComponentLoader() {
@@ -453,6 +474,21 @@ public String getName() {
453474
}
454475
});
455476
}
477+
if (spiClass == ConfigurableMetricExporterProvider.class) {
478+
return Collections.singletonList(
479+
(T)
480+
new ConfigurableMetricExporterProvider() {
481+
@Override
482+
public MetricExporter createExporter(ConfigProperties configProperties) {
483+
return metricExporter;
484+
}
485+
486+
@Override
487+
public String getName() {
488+
return "otlp";
489+
}
490+
});
491+
}
456492
return spiHelper.load(spiClass);
457493
}
458494
});

0 commit comments

Comments
 (0)