Skip to content

Commit

Permalink
Add connect timeout properties for OTLP tracing
Browse files Browse the repository at this point in the history
- Rename OtlpProperties to OtlpTracingProperties

See gh-41460
See gh-42528
  • Loading branch information
mhalbritter committed Oct 8, 2024
1 parent 40bb814 commit b997c0c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +30,7 @@
import org.springframework.util.Assert;

/**
* Configurations imported by {@link OtlpAutoConfiguration}.
* Configurations imported by {@link OtlpTracingAutoConfiguration}.
*
* @author Moritz Halbritter
* @author Eddú Meléndez
Expand All @@ -46,18 +43,18 @@ static class ConnectionDetails {
@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;
}

Expand All @@ -82,29 +79,27 @@ static class Exporters {
@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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
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;

/**
Expand All @@ -31,7 +29,7 @@
* @since 3.1.0
*/
@ConfigurationProperties("management.otlp.tracing")
public class OtlpProperties {
public class OtlpTracingProperties {

/**
* URL to the OTel collector's HTTP API.
Expand All @@ -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.
*/
Expand Down Expand Up @@ -77,6 +80,14 @@ public void setTimeout(Duration timeout) {
this.timeout = timeout;
}

public Duration getConnectTimeout() {
return this.connectTimeout;
}

public void setConnectTimeout(Duration connectTimeout) {
this.connectTimeout = connectTimeout;
}

public Transport getTransport() {
return this.transport;
}
Expand All @@ -101,4 +112,18 @@ public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

public enum Compression {

/**
* Gzip compression.
*/
GZIP,

/**
* No compression.
*/
NONE

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit b997c0c

Please sign in to comment.