spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Add auto-configuration for OTLP gRPC format

Open mhalbritter opened this issue 2 years ago • 4 comments

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

mhalbritter avatar Jun 13 '23 08:06 mhalbritter

Hi which version of spring-boot have this feature ?

ShakeelHussain avatar Oct 19 '23 14:10 ShakeelHussain

None at this time as the issue is still open.

wilkinsona avatar Oct 19 '23 15:10 wilkinsona

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

meisten avatar Jun 10 '24 10:06 meisten

I've provided an initial proposal to support OtlpGrpcSpanExporter. See https://github.com/spring-projects/spring-boot/pull/41213 Looking forward to any feedback.

timpeeters avatar Jun 24 '24 09:06 timpeeters

Superseded by #41213.

mhalbritter avatar Jul 04 '24 07:07 mhalbritter