Add connect timeout properties for OTLP tracing
- Rename OtlpProperties to OtlpTracingProperties See gh-41460 See gh-42528
This commit is contained in:
@@ -16,14 +16,11 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.tracing.otlp;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
|
||||
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder;
|
||||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
|
||||
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.opentelemetry.otlp.Transport;
|
||||
import org.springframework.boot.actuate.autoconfigure.tracing.ConditionalOnEnabledTracing;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
@@ -33,7 +30,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Configurations imported by {@link OtlpAutoConfiguration}.
|
||||
* Configurations imported by {@link OtlpTracingAutoConfiguration}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Eddú Meléndez
|
||||
@@ -46,18 +43,18 @@ class OtlpTracingConfigurations {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(prefix = "management.otlp.tracing", name = "endpoint")
|
||||
OtlpTracingConnectionDetails otlpTracingConnectionDetails(OtlpProperties properties) {
|
||||
OtlpTracingConnectionDetails otlpTracingConnectionDetails(OtlpTracingProperties properties) {
|
||||
return new PropertiesOtlpTracingConnectionDetails(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts {@link OtlpProperties} to {@link OtlpTracingConnectionDetails}.
|
||||
* Adapts {@link OtlpTracingProperties} to {@link OtlpTracingConnectionDetails}.
|
||||
*/
|
||||
static class PropertiesOtlpTracingConnectionDetails implements OtlpTracingConnectionDetails {
|
||||
|
||||
private final OtlpProperties properties;
|
||||
private final OtlpTracingProperties properties;
|
||||
|
||||
PropertiesOtlpTracingConnectionDetails(OtlpProperties properties) {
|
||||
PropertiesOtlpTracingConnectionDetails(OtlpTracingProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@@ -82,29 +79,27 @@ class OtlpTracingConfigurations {
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "management.otlp.tracing", name = "transport", havingValue = "http",
|
||||
matchIfMissing = true)
|
||||
OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpProperties properties,
|
||||
OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpTracingProperties properties,
|
||||
OtlpTracingConnectionDetails connectionDetails) {
|
||||
OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder()
|
||||
.setEndpoint(connectionDetails.getUrl(Transport.HTTP))
|
||||
.setTimeout(properties.getTimeout())
|
||||
.setConnectTimeout(properties.getConnectTimeout())
|
||||
.setCompression(properties.getCompression().name().toLowerCase());
|
||||
for (Entry<String, String> header : properties.getHeaders().entrySet()) {
|
||||
builder.addHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
properties.getHeaders().forEach(builder::addHeader);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "management.otlp.tracing", name = "transport", havingValue = "grpc")
|
||||
OtlpGrpcSpanExporter otlpGrpcSpanExporter(OtlpProperties properties,
|
||||
OtlpGrpcSpanExporter otlpGrpcSpanExporter(OtlpTracingProperties properties,
|
||||
OtlpTracingConnectionDetails connectionDetails) {
|
||||
OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder()
|
||||
.setEndpoint(connectionDetails.getUrl(Transport.GRPC))
|
||||
.setTimeout(properties.getTimeout())
|
||||
.setConnectTimeout(properties.getConnectTimeout())
|
||||
.setCompression(properties.getCompression().name().toLowerCase());
|
||||
for (Entry<String, String> header : properties.getHeaders().entrySet()) {
|
||||
builder.addHeader(header.getKey(), header.getValue());
|
||||
}
|
||||
properties.getHeaders().forEach(builder::addHeader);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.tracing.otlp;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.opentelemetry.otlp.Transport;
|
||||
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,8 +20,6 @@ import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.opentelemetry.otlp.Compression;
|
||||
import org.springframework.boot.actuate.autoconfigure.opentelemetry.otlp.Transport;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
@@ -31,7 +29,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
* @since 3.1.0
|
||||
*/
|
||||
@ConfigurationProperties("management.otlp.tracing")
|
||||
public class OtlpProperties {
|
||||
public class OtlpTracingProperties {
|
||||
|
||||
/**
|
||||
* URL to the OTel collector's HTTP API.
|
||||
@@ -46,6 +44,11 @@ public class OtlpProperties {
|
||||
*/
|
||||
private Duration timeout = Duration.ofSeconds(10);
|
||||
|
||||
/**
|
||||
* Connect timeout for the OTel collector connection.
|
||||
*/
|
||||
private Duration connectTimeout = Duration.ofSeconds(10);
|
||||
|
||||
/**
|
||||
* Transport used to send the spans.
|
||||
*/
|
||||
@@ -77,6 +80,14 @@ public class OtlpProperties {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public Duration getConnectTimeout() {
|
||||
return this.connectTimeout;
|
||||
}
|
||||
|
||||
public void setConnectTimeout(Duration connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
public Transport getTransport() {
|
||||
return this.transport;
|
||||
}
|
||||
@@ -101,4 +112,18 @@ public class OtlpProperties {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public enum Compression {
|
||||
|
||||
/**
|
||||
* Gzip compression.
|
||||
*/
|
||||
GZIP,
|
||||
|
||||
/**
|
||||
* No compression.
|
||||
*/
|
||||
NONE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,24 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.opentelemetry.otlp;
|
||||
package org.springframework.boot.actuate.autoconfigure.tracing.otlp;
|
||||
|
||||
/**
|
||||
* Algorithm used to compress OTLP data.
|
||||
* Transport used to send OTLP data.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public enum Compression {
|
||||
public enum Transport {
|
||||
|
||||
/**
|
||||
* Gzip compression.
|
||||
* HTTP transport.
|
||||
*/
|
||||
GZIP,
|
||||
HTTP,
|
||||
|
||||
/**
|
||||
* No compression.
|
||||
* gRPC transport.
|
||||
*/
|
||||
NONE
|
||||
GRPC
|
||||
|
||||
}
|
||||
@@ -15,6 +15,6 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for tracing with OTLP.
|
||||
* Auto-configuration for exporting traces with OTLP.
|
||||
*/
|
||||
package org.springframework.boot.actuate.autoconfigure.tracing.otlp;
|
||||
|
||||
Reference in New Issue
Block a user