Skip to content

Commit 11ed14e

Browse files
committed
fix disabled config
1 parent 1d29b05 commit 11ed14e

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.opentelemetry.instrumentation.spring.autoconfigure;
77

88
import io.opentelemetry.api.OpenTelemetry;
9-
import io.opentelemetry.api.incubator.config.GlobalConfigProvider;
109
import io.opentelemetry.api.trace.TracerProvider;
1110
import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig;
1211
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties;
@@ -159,23 +158,12 @@ public OpenTelemetryConfigurationModel openTelemetryConfigurationModel(
159158
@Bean
160159
public OpenTelemetry openTelemetry(
161160
OpenTelemetryConfigurationModel model, ApplicationContext applicationContext) {
162-
OpenTelemetrySdk sdk = DeclarativeConfiguration.create(model, new OpenTelemetrySdkComponentLoader(applicationContext));
163-
161+
OpenTelemetrySdk sdk =
162+
DeclarativeConfiguration.create(
163+
model, new OpenTelemetrySdkComponentLoader(applicationContext));
164164
Runtime.getRuntime().addShutdownHook(new Thread(sdk::close));
165-
166-
SdkConfigProvider configProvider = SdkConfigProvider.create(model);
167-
GlobalConfigProvider.set(configProvider);
168-
169-
System.out.println(
170-
"OpenTelemetry SDK initialized with configuration from: " + sdk); // todo remove
171-
172-
// todo declarative configuration
173-
// todo map converter not needed here, because the declarative configuration is not using
174-
// environment variables
175-
176165
logStart();
177-
178-
return null;
166+
return sdk;
179167
}
180168

181169
@Bean
@@ -220,6 +208,26 @@ public OpenTelemetry openTelemetry() {
220208
public ConfigProperties otelProperties() {
221209
return DefaultConfigProperties.createFromMap(Collections.emptyMap());
222210
}
211+
212+
@Bean
213+
public InstrumentationConfig instrumentationConfig(ConfigProperties properties) {
214+
return new ConfigPropertiesBridge(properties, null);
215+
}
216+
217+
@Configuration
218+
@ConditionalOnProperty(name = "otel.file_format", matchIfMissing = true, havingValue = "never")
219+
static class PropertiesConfig {
220+
/**
221+
* Is only added so that we have the same converters as with active OpenTelemetry SDK
222+
*
223+
* <p>In other words, don't break applications that (accidentally) use the {@link
224+
* OtelMapConverter}.
225+
*/
226+
@Bean
227+
OtelMapConverter otelMapConverter() {
228+
return new OtelMapConverter();
229+
}
230+
}
223231
}
224232

225233
@Configuration
@@ -232,6 +240,16 @@ public ConfigProperties otelProperties() {
232240
}
233241
}
234242

243+
@Configuration
244+
@ConditionalOnBean(OpenTelemetry.class)
245+
@ConditionalOnMissingBean({InstrumentationConfig.class})
246+
static class FallbackInstrumentationConfig {
247+
@Bean
248+
public InstrumentationConfig instrumentationConfig(ConfigProperties properties) {
249+
return new ConfigPropertiesBridge(properties, null);
250+
}
251+
}
252+
235253
/**
236254
* The {@link ComponentLoader} is used by the SDK autoconfiguration to load all components, e.g.
237255
* <a

0 commit comments

Comments
 (0)