3131import io .opentelemetry .sdk .autoconfigure .internal .SpiHelper ;
3232import io .opentelemetry .sdk .autoconfigure .spi .ConfigProperties ;
3333import io .opentelemetry .sdk .autoconfigure .spi .ConfigurationException ;
34+ import io .opentelemetry .sdk .autoconfigure .spi .metrics .ConfigurableMetricExporterProvider ;
3435import io .opentelemetry .sdk .autoconfigure .spi .traces .ConfigurableSpanExporterProvider ;
3536import io .opentelemetry .sdk .common .CompletableResultCode ;
37+ import io .opentelemetry .sdk .metrics .export .MetricExporter ;
3638import io .opentelemetry .sdk .trace .data .SpanData ;
3739import io .opentelemetry .sdk .trace .export .SpanExporter ;
3840import 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