Skip to content

Commit f715a18

Browse files
zeitlingertrask
andauthored
re-use sdk logic for configuring otlp exporters (#10292)
Co-authored-by: Trask Stalnaker <[email protected]>
1 parent d4435c9 commit f715a18

22 files changed

+599
-623
lines changed

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

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import io.opentelemetry.api.OpenTelemetry;
99
import io.opentelemetry.api.trace.TracerProvider;
1010
import io.opentelemetry.context.propagation.ContextPropagators;
11-
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpLoggerExporterAutoConfiguration;
11+
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpExporterProperties;
12+
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpLogRecordExporterAutoConfiguration;
1213
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpMetricExporterAutoConfiguration;
1314
import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpSpanExporterAutoConfiguration;
1415
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.MapConverter;
1516
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration;
16-
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringResourceConfigProperties;
17+
import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringConfigProperties;
1718
import io.opentelemetry.sdk.OpenTelemetrySdk;
1819
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
1920
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
@@ -55,7 +56,11 @@
5556
* <p>Updates the sampler probability for the configured {@link TracerProvider}.
5657
*/
5758
@Configuration
58-
@EnableConfigurationProperties({MetricExportProperties.class, SamplerProperties.class})
59+
@EnableConfigurationProperties({
60+
MetricExportProperties.class,
61+
SamplerProperties.class,
62+
OtlpExporterProperties.class
63+
})
5964
public class OpenTelemetryAutoConfiguration {
6065

6166
public OpenTelemetryAutoConfiguration() {}
@@ -81,7 +86,7 @@ public MapConverterCondition() {
8186
@ConditionalOnBean(OtelResourceAutoConfiguration.class)
8287
static class Resource {}
8388

84-
@ConditionalOnBean(OtlpLoggerExporterAutoConfiguration.class)
89+
@ConditionalOnBean(OtlpLogRecordExporterAutoConfiguration.class)
8590
static class Logger {}
8691

8792
@ConditionalOnBean(OtlpSpanExporterAutoConfiguration.class)
@@ -91,6 +96,13 @@ static class Span {}
9196
static class Metric {}
9297
}
9398

99+
@Bean
100+
@ConditionalOnMissingBean
101+
ConfigProperties configProperties(
102+
Environment env, OtlpExporterProperties otlpExporterProperties) {
103+
return new SpringConfigProperties(env, new SpelExpressionParser(), otlpExporterProperties);
104+
}
105+
94106
@Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance
95107
@ConditionalOnMissingBean
96108
public SdkTracerProvider sdkTracerProvider(
@@ -156,8 +168,7 @@ private static PeriodicMetricReader createPeriodicMetricReader(
156168
@Bean
157169
@ConditionalOnMissingBean
158170
public Resource otelResource(
159-
Environment env, ObjectProvider<List<ResourceProvider>> resourceProviders) {
160-
ConfigProperties config = new SpringResourceConfigProperties(env, new SpelExpressionParser());
171+
ConfigProperties config, ObjectProvider<List<ResourceProvider>> resourceProviders) {
161172
Resource resource = Resource.getDefault();
162173
for (ResourceProvider resourceProvider :
163174
resourceProviders.getIfAvailable(Collections::emptyList)) {

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingExporterProperties.java

-49
This file was deleted.

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfiguration.java

-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
1212
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1313
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
14-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1514
import org.springframework.context.annotation.Bean;
1615
import org.springframework.context.annotation.Condition;
1716
import org.springframework.context.annotation.Conditional;
1817
import org.springframework.context.annotation.Configuration;
1918

2019
/** Configures {@link LoggingMetricExporter} bean for tracing. */
2120
@Configuration
22-
@EnableConfigurationProperties(LoggingExporterProperties.class)
2321
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class)
2422
@Conditional(LoggingMetricExporterAutoConfiguration.CustomCondition.class)
2523
@ConditionalOnClass(LoggingMetricExporter.class)

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfiguration.java

-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
1212
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1313
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
14-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1514
import org.springframework.context.annotation.Bean;
1615
import org.springframework.context.annotation.Condition;
1716
import org.springframework.context.annotation.Conditional;
1817
import org.springframework.context.annotation.Configuration;
1918

2019
/** Configures {@link LoggingSpanExporter} bean for tracing. */
2120
@Configuration
22-
@EnableConfigurationProperties(LoggingExporterProperties.class)
2321
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class)
2422
@Conditional(LoggingSpanExporterAutoConfiguration.CustomCondition.class)
2523
@ConditionalOnClass(LoggingSpanExporter.class)

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterProperties.java

+1-96
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,24 @@
55

66
package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp;
77

8-
import java.time.Duration;
98
import java.util.HashMap;
109
import java.util.Map;
11-
import javax.annotation.Nullable;
1210
import org.springframework.boot.context.properties.ConfigurationProperties;
1311

14-
/**
15-
* Configuration for {@link io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter} and {@link
16-
* io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter}.
17-
*
18-
* <p>Get Exporter Service Name
19-
*
20-
* <p>Get Exporter Endpoint
21-
*
22-
* <p>Get max wait time for Collector to process Span Batches
23-
*/
12+
/** Configuration for OLTP exporters. */
2413
@ConfigurationProperties(prefix = "otel.exporter.otlp")
2514
public final class OtlpExporterProperties {
2615

27-
private boolean enabled = true;
28-
@Nullable private String endpoint;
29-
30-
@Nullable private String protocol;
31-
3216
private final Map<String, String> headers = new HashMap<>();
3317

34-
@Nullable private Duration timeout;
3518
private final SignalProperties traces = new SignalProperties();
3619
private final SignalProperties metrics = new SignalProperties();
3720
private final SignalProperties logs = new SignalProperties();
3821

39-
public boolean isEnabled() {
40-
return enabled;
41-
}
42-
43-
public void setEnabled(boolean enabled) {
44-
this.enabled = enabled;
45-
}
46-
47-
@Nullable
48-
public String getEndpoint() {
49-
return endpoint;
50-
}
51-
52-
public void setEndpoint(String endpoint) {
53-
this.endpoint = endpoint;
54-
}
55-
56-
@Nullable
57-
public String getProtocol() {
58-
return protocol;
59-
}
60-
61-
public void setProtocol(@Nullable String protocol) {
62-
this.protocol = protocol;
63-
}
64-
6522
public Map<String, String> getHeaders() {
6623
return headers;
6724
}
6825

69-
@Nullable
70-
public Duration getTimeout() {
71-
return timeout;
72-
}
73-
74-
public void setTimeout(Duration timeout) {
75-
this.timeout = timeout;
76-
}
77-
7826
public SignalProperties getTraces() {
7927
return traces;
8028
}
@@ -88,53 +36,10 @@ public SignalProperties getLogs() {
8836
}
8937

9038
public static class SignalProperties {
91-
92-
private boolean enabled = true;
93-
@Nullable private String endpoint;
94-
95-
@Nullable private String protocol;
96-
9739
private final Map<String, String> headers = new HashMap<>();
9840

99-
@Nullable private Duration timeout;
100-
101-
public boolean isEnabled() {
102-
return enabled;
103-
}
104-
105-
public void setEnabled(boolean enabled) {
106-
this.enabled = enabled;
107-
}
108-
109-
@Nullable
110-
public String getEndpoint() {
111-
return endpoint;
112-
}
113-
114-
public void setEndpoint(@Nullable String endpoint) {
115-
this.endpoint = endpoint;
116-
}
117-
118-
@Nullable
119-
public String getProtocol() {
120-
return protocol;
121-
}
122-
123-
public void setProtocol(@Nullable String protocol) {
124-
this.protocol = protocol;
125-
}
126-
12741
public Map<String, String> getHeaders() {
12842
return headers;
12943
}
130-
131-
@Nullable
132-
public Duration getTimeout() {
133-
return timeout;
134-
}
135-
136-
public void setTimeout(@Nullable Duration timeout) {
137-
this.timeout = timeout;
138-
}
13944
}
14045
}

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterUtil.java

-119
This file was deleted.

0 commit comments

Comments
 (0)