6
6
package io .opentelemetry .instrumentation .spring .autoconfigure ;
7
7
8
8
import io .opentelemetry .api .OpenTelemetry ;
9
- import io .opentelemetry .api .incubator .config .GlobalConfigProvider ;
10
9
import io .opentelemetry .api .trace .TracerProvider ;
11
10
import io .opentelemetry .instrumentation .api .incubator .config .internal .InstrumentationConfig ;
12
11
import io .opentelemetry .instrumentation .api .internal .EmbeddedInstrumentationProperties ;
@@ -159,23 +158,12 @@ public OpenTelemetryConfigurationModel openTelemetryConfigurationModel(
159
158
@ Bean
160
159
public OpenTelemetry openTelemetry (
161
160
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 ));
164
164
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
-
176
165
logStart ();
177
-
178
- return null ;
166
+ return sdk ;
179
167
}
180
168
181
169
@ Bean
@@ -220,6 +208,26 @@ public OpenTelemetry openTelemetry() {
220
208
public ConfigProperties otelProperties () {
221
209
return DefaultConfigProperties .createFromMap (Collections .emptyMap ());
222
210
}
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
+ }
223
231
}
224
232
225
233
@ Configuration
@@ -232,6 +240,16 @@ public ConfigProperties otelProperties() {
232
240
}
233
241
}
234
242
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
+
235
253
/**
236
254
* The {@link ComponentLoader} is used by the SDK autoconfiguration to load all components, e.g.
237
255
* <a
0 commit comments