always need map converter (#13224)

Co-authored-by: Jean Bisutti <jean.bisutti@gmail.com>
This commit is contained in:
Gregor Zeitlinger 2025-02-05 16:22:29 +01:00 committed by GitHub
parent 36e1e14ee7
commit 081415e6b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 5 deletions

View File

@ -7,7 +7,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure;
import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.MapConverter; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.OtelMapConverter;
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.SdkEnabled; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.SdkEnabled;
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.OtelResourceProperties; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.OtelResourceProperties;
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.OtelSpringProperties; import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.OtelSpringProperties;
@ -64,9 +64,9 @@ public class OpenTelemetryAutoConfiguration {
@Bean @Bean
@ConfigurationPropertiesBinding @ConfigurationPropertiesBinding
public MapConverter mapConverter() { public OtelMapConverter otelMapConverter() {
// needed for otlp exporter headers and OtelResourceProperties // needed for otlp exporter headers and OtelResourceProperties
return new MapConverter(); return new OtelMapConverter();
} }
@Bean @Bean
@ -133,6 +133,17 @@ public class OpenTelemetryAutoConfiguration {
@ConditionalOnProperty(name = "otel.sdk.disabled", havingValue = "true") @ConditionalOnProperty(name = "otel.sdk.disabled", havingValue = "true")
static class DisabledOpenTelemetrySdkConfig { static class DisabledOpenTelemetrySdkConfig {
@Bean
@ConfigurationPropertiesBinding
// Duplicated in OpenTelemetrySdkConfig and DisabledOpenTelemetrySdkConfig to not expose the
// converter in the public API
public OtelMapConverter otelMapConverter() {
// needed for otlp exporter headers and OtelResourceProperties
// we need this converter, even if the SDK is disabled,
// because the properties are parsed before the SDK is disabled
return new OtelMapConverter();
}
@Bean @Bean
public OpenTelemetry openTelemetry() { public OpenTelemetry openTelemetry() {
return OpenTelemetry.noop(); return OpenTelemetry.noop();

View File

@ -20,7 +20,7 @@ import org.springframework.core.convert.converter.Converter;
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change * <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time. * at any time.
*/ */
public class MapConverter implements Converter<String, Map<String, String>> { public class OtelMapConverter implements Converter<String, Map<String, String>> {
public static final String KEY = "key"; public static final String KEY = "key";

View File

@ -156,7 +156,9 @@ class OpenTelemetryAutoConfigurationTest {
void shouldInitializeNoopOpenTelemetryWhenSdkIsDisabled() { void shouldInitializeNoopOpenTelemetryWhenSdkIsDisabled() {
this.contextRunner this.contextRunner
.withConfiguration(AutoConfigurations.of(OpenTelemetryAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(OpenTelemetryAutoConfiguration.class))
.withPropertyValues("otel.sdk.disabled=true") .withPropertyValues(
"otel.sdk.disabled=true",
"otel.resource.attributes=service.name=workflow-backend-dev,service.version=3c8f9ce9")
.run( .run(
context -> context ->
assertThat(context).getBean("openTelemetry").isEqualTo(OpenTelemetry.noop())); assertThat(context).getBean("openTelemetry").isEqualTo(OpenTelemetry.noop()));