Add auto-configuration for OTLP gRPC format
Implement auto-configuration for OpenTelemetry's OtlpGrpcSpanExporter.
Well, since the endpoint URL has to be provided now, it can be used to figure out which type of exporter the user wants to configure and also support the gRPC option.
Originally posted by @vpavic in https://github.com/spring-projects/spring-boot/issues/35596#issuecomment-1588815137
Hi which version of spring-boot have this feature ?
None at this time as the issue is still open.
Maybe it will be useful to someone. Until autoconfiguration is implemented out-of-the-box, you can use this code in your project.
package org.example.infrastructure.monitoring;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpProperties;
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingConnectionDetails;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
class OtlpGrpcExporterAutoConfiguration {
/**
* This is a copy of autoconfiguration {@link io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter} from
* {@link org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpTracingConfigurations}, but for gRPC.
*/
@Bean
OtlpGrpcSpanExporter otlpGrpcSpanExporter(OtlpProperties properties, OtlpTracingConnectionDetails connectionDetails) {
var builder = OtlpGrpcSpanExporter.builder()
.setEndpoint(connectionDetails.getUrl())
.setTimeout(properties.getTimeout())
// TODO: use Enum#name instead of String#valueof. OtlpProperties#Compression
// enum has package private access
.setCompression(String.valueOf(properties.getCompression()).toLowerCase());
properties.getHeaders().forEach(builder::addHeader);
return builder.build();
}
}
application.yml:
management:
otlp:
tracing:
endpoint: http://localhost:4317/v1/traces
compression: gzip
I've provided an initial proposal to support OtlpGrpcSpanExporter.
See https://github.com/spring-projects/spring-boot/pull/41213
Looking forward to any feedback.
Superseded by #41213.