8
8
import io .opentelemetry .api .OpenTelemetry ;
9
9
import io .opentelemetry .api .trace .TracerProvider ;
10
10
import io .opentelemetry .instrumentation .api .internal .EmbeddedInstrumentationProperties ;
11
+ import io .opentelemetry .instrumentation .sdk .DeclarativeConfigPropertiesBridge ;
11
12
import io .opentelemetry .instrumentation .spring .autoconfigure .internal .OtelMapConverter ;
12
13
import io .opentelemetry .instrumentation .spring .autoconfigure .internal .SdkEnabled ;
13
14
import io .opentelemetry .instrumentation .spring .autoconfigure .internal .properties .OtelResourceProperties ;
23
24
import io .opentelemetry .sdk .autoconfigure .spi .ConfigProperties ;
24
25
import io .opentelemetry .sdk .autoconfigure .spi .ResourceProvider ;
25
26
import io .opentelemetry .sdk .autoconfigure .spi .internal .DefaultConfigProperties ;
27
+ import io .opentelemetry .sdk .extension .incubator .fileconfig .DeclarativeConfiguration ;
28
+ import io .opentelemetry .sdk .extension .incubator .fileconfig .internal .model .OpenTelemetryConfigurationModel ;
26
29
import java .util .Collections ;
27
30
import java .util .List ;
28
31
import java .util .Optional ;
29
32
import java .util .function .Function ;
30
33
import java .util .function .Supplier ;
31
34
import java .util .stream .Collectors ;
32
- import io .opentelemetry .sdk .extension .incubator .fileconfig .DeclarativeConfiguration ;
33
- import io .opentelemetry .sdk .extension .incubator .fileconfig .internal .model .OpenTelemetryConfigurationModel ;
34
35
import org .slf4j .Logger ;
35
36
import org .slf4j .LoggerFactory ;
36
37
import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
43
44
import org .springframework .context .annotation .Bean ;
44
45
import org .springframework .context .annotation .Conditional ;
45
46
import org .springframework .context .annotation .Configuration ;
46
- import org .springframework .context .annotation .DependsOn ;
47
47
import org .springframework .core .env .Environment ;
48
48
49
49
/**
@@ -65,23 +65,8 @@ public class OpenTelemetryAutoConfiguration {
65
65
66
66
public OpenTelemetryAutoConfiguration () {}
67
67
68
- @ Bean
69
- @ ConfigurationPropertiesBinding
70
- OtelMapConverter otelMapConverter () {
71
- // This is needed for otlp exporter headers and OtelResourceProperties.
72
-
73
- // We need this converter, even if the SDK is disabled,
74
- // because the properties are parsed before the SDK is disabled.
75
-
76
- // We also need this converter if the OpenTelemetry bean is user supplied,
77
- // because the environment variables may still contain a value that needs to be converted,
78
- // even if the SDK is disabled (and the value thus ignored).
79
- return new OtelMapConverter ();
80
- }
81
-
82
68
@ Configuration
83
69
@ Conditional (SdkEnabled .class )
84
- @ DependsOn ("otelMapConverter" )
85
70
@ ConditionalOnMissingBean (OpenTelemetry .class )
86
71
static class OpenTelemetrySdkConfig {
87
72
@@ -101,67 +86,109 @@ public ResourceProvider otelDistroVersionResourceProvider() {
101
86
return new DistroVersionResourceProvider ();
102
87
}
103
88
104
- @ Bean
105
- public AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk (
106
- Environment env ,
107
- OtlpExporterProperties otlpExporterProperties ,
108
- OtelResourceProperties resourceProperties ,
109
- OtelSpringProperties otelSpringProperties ,
110
- OpenTelemetrySdkComponentLoader componentLoader ) {
111
-
112
- return AutoConfigureUtil .setComponentLoader (
113
- AutoConfigureUtil .setConfigPropertiesCustomizer (
114
- AutoConfiguredOpenTelemetrySdk .builder (),
115
- c ->
116
- SpringConfigProperties .create (
117
- env ,
118
- otlpExporterProperties ,
119
- resourceProperties ,
120
- otelSpringProperties ,
121
- c )),
122
- componentLoader )
123
- .build ();
89
+ @ Configuration
90
+ @ ConditionalOnProperty (name = "otel.file_format" , matchIfMissing = true , havingValue = "never" )
91
+ static class PropertiesConfig {
92
+
93
+ @ Bean
94
+ @ ConfigurationPropertiesBinding
95
+ OtelMapConverter otelMapConverter () {
96
+ return new OtelMapConverter ();
97
+ }
98
+
99
+ @ Bean
100
+ public AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk (
101
+ Environment env ,
102
+ OtlpExporterProperties otlpExporterProperties ,
103
+ OtelResourceProperties resourceProperties ,
104
+ OtelSpringProperties otelSpringProperties ,
105
+ OpenTelemetrySdkComponentLoader componentLoader ) {
106
+
107
+ return AutoConfigureUtil .setComponentLoader (
108
+ AutoConfigureUtil .setConfigPropertiesCustomizer (
109
+ AutoConfiguredOpenTelemetrySdk .builder (),
110
+ c ->
111
+ SpringConfigProperties .create (
112
+ env ,
113
+ otlpExporterProperties ,
114
+ resourceProperties ,
115
+ otelSpringProperties ,
116
+ c )),
117
+ componentLoader )
118
+ .build ();
119
+ }
120
+
121
+ @ Bean
122
+ public OpenTelemetry openTelemetry (
123
+ AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk ) {
124
+ logStart ();
125
+ return autoConfiguredOpenTelemetrySdk .getOpenTelemetrySdk ();
126
+ }
127
+
128
+ /**
129
+ * Expose the {@link ConfigProperties} bean for use in other auto-configurations.
130
+ *
131
+ * <p>Not using spring boot properties directly in order to support {@link
132
+ * io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer#addPropertiesCustomizer(Function)}
133
+ * and {@link
134
+ * io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer#addPropertiesSupplier(Supplier)}.
135
+ */
136
+ @ Bean
137
+ public ConfigProperties otelProperties (
138
+ AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk ) {
139
+ return AutoConfigureUtil .getConfig (autoConfiguredOpenTelemetrySdk );
140
+ }
124
141
}
142
+ }
143
+
144
+ @ Configuration
145
+ @ ConditionalOnProperty (name = "otel.file_format" )
146
+ static class OpenTelemetrySdkEmbeddedConfigFileConfig {
125
147
126
- // todo is not available with declarative config - unless via file property
127
148
@ Bean
128
- public OpenTelemetry openTelemetry (
129
- AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk ) {
130
- logger .info (
131
- "OpenTelemetry Spring Boot starter ({}) has been started" ,
132
- EmbeddedInstrumentationProperties .findVersion (
133
- "io.opentelemetry.spring-boot-autoconfigure" ));
134
-
135
- return autoConfiguredOpenTelemetrySdk .getOpenTelemetrySdk ();
149
+ public OpenTelemetry openTelemetry () {
150
+
151
+ // todo declarative configuration
152
+ // todo map converter not needed here, because the declarative configuration is not using
153
+ // environment variables
154
+
155
+ logStart ();
156
+
157
+ return null ;
136
158
}
137
159
138
160
/**
139
161
* Expose the {@link ConfigProperties} bean for use in other auto-configurations.
140
162
*
141
- * <p>Not using spring boot properties directly in order to support {@link
142
- * io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer#addPropertiesCustomizer(Function)}
143
- * and {@link
144
- * io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer#addPropertiesSupplier(Supplier)}.
163
+ * <p>Not using spring boot properties directly, because declarative configuration does not
164
+ * integrate with spring boot properties.
145
165
*/
146
166
@ Bean
147
- public ConfigProperties otelProperties (
148
- AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk ) {
149
- return AutoConfigureUtil .getConfig (autoConfiguredOpenTelemetrySdk );
167
+ public ConfigProperties otelProperties (OpenTelemetryConfigurationModel model ) {
168
+ // todo component loader
169
+ return DeclarativeConfigPropertiesBridge .create (
170
+ DeclarativeConfiguration .toConfigProperties (model ));
150
171
}
172
+ }
151
173
152
- @ Bean (name = "otelProperties" )
153
- public ConfigProperties otelBridgeProperties (OpenTelemetryConfigurationModel model ) {
154
- // todo componet loader
155
- // todo bridge properties
156
- return DeclarativeConfiguration .toConfigProperties (model );
157
- }
174
+ private static void logStart () {
175
+ logger .info (
176
+ "OpenTelemetry Spring Boot starter ({}) has been started" ,
177
+ EmbeddedInstrumentationProperties .findVersion (
178
+ "io.opentelemetry.spring-boot-autoconfigure" ));
158
179
}
159
180
160
181
@ Configuration
161
- @ DependsOn ("otelMapConverter" )
162
182
@ ConditionalOnMissingBean (OpenTelemetry .class )
163
183
@ ConditionalOnProperty (name = "otel.sdk.disabled" , havingValue = "true" )
164
184
static class DisabledOpenTelemetrySdkConfig {
185
+
186
+ @ Bean
187
+ @ ConfigurationPropertiesBinding
188
+ OtelMapConverter otelMapConverter () {
189
+ return new OtelMapConverter ();
190
+ }
191
+
165
192
@ Bean
166
193
public OpenTelemetry openTelemetry () {
167
194
logger .info ("OpenTelemetry Spring Boot starter has been disabled" );
0 commit comments