Skip to content

Commit

Permalink
fix MapConverter bean condition (open-telemetry#10346)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger authored and steverao committed Feb 16, 2024
1 parent 7b719d4 commit 82b6ae3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.expression.spel.standard.SpelExpressionParser;
Expand All @@ -65,17 +67,30 @@ public static class OpenTelemetrySdkConfig {

@Bean
@ConfigurationPropertiesBinding
@ConditionalOnBean({
OtelResourceAutoConfiguration.class,
OtlpLoggerExporterAutoConfiguration.class,
OtlpSpanExporterAutoConfiguration.class,
OtlpMetricExporterAutoConfiguration.class
})
@Conditional(MapConverterCondition.class)
public MapConverter mapConverter() {
// needed for otlp exporter headers and OtelResourceProperties
return new MapConverter();
}

static final class MapConverterCondition extends AnyNestedCondition {
public MapConverterCondition() {
super(ConfigurationPhase.REGISTER_BEAN);
}

@ConditionalOnBean(OtelResourceAutoConfiguration.class)
static class Resource {}

@ConditionalOnBean(OtlpLoggerExporterAutoConfiguration.class)
static class Logger {}

@ConditionalOnBean(OtlpSpanExporterAutoConfiguration.class)
static class Span {}

@ConditionalOnBean(OtlpMetricExporterAutoConfiguration.class)
static class Metric {}
}

@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
@ConditionalOnMissingBean
public SdkTracerProvider sdkTracerProvider(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.instrumentation.spring.autoconfigure.MapConverterTestAutoConfiguration;
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.util.stream.Collectors;
Expand All @@ -30,9 +29,7 @@ class OtlpSpanExporterAutoConfigurationTest {
new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(
OpenTelemetryAutoConfiguration.class,
OtlpSpanExporterAutoConfiguration.class,
MapConverterTestAutoConfiguration.class));
OpenTelemetryAutoConfiguration.class, OtlpSpanExporterAutoConfiguration.class));

@Test
@DisplayName("when exporters are ENABLED should initialize OtlpHttpSpanExporter bean")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.google.common.collect.ImmutableMap;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.spring.autoconfigure.MapConverterTestAutoConfiguration;
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration;
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -24,7 +24,7 @@ public class OtelResourcePropertiesTest {
.withPropertyValues("otel.springboot.resource.enabled=true")
.withConfiguration(
AutoConfigurations.of(
OtelResourceAutoConfiguration.class, MapConverterTestAutoConfiguration.class));
OtelResourceAutoConfiguration.class, OpenTelemetryAutoConfiguration.class));

@Test
@DisplayName("when attributes are SET should set OtelResourceProperties with given attributes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@
OtelSpringStarterSmokeTest.TestConfiguration.class
},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"otel.exporter.otlp.enabled=false", "otel.metric.export.interval=100"
properties = {
"otel.exporter.otlp.enabled=false",
"otel.metric.export.interval=100",
"otel.exporter.otlp.headers=a=1,b=2",
// We set the export interval of the metrics to 100 ms. The default value is 1 minute.
// the headers are simply set here to make sure that headers can be parsed, even with
// otel.exporter.otlp.enabled=false
})
class OtelSpringStarterSmokeTest {

Expand Down

0 comments on commit 82b6ae3

Please sign in to comment.