升级到Spring Boot 3.1破坏了我的Otel导出器。

huangapple go评论69阅读模式
英文:

Upgrade to spring boot 3.1 breaks my otel exporter

问题

我更新了otel导出器配置,从

SPRING_SLEUTH_OTEL_EXPORTER_OTLP_ENDPOINT=http://tempo.xxx.svc.cluster.local:4317

MANAGEMENT_OTLP_TRACING_ENDPOINT=http://tempo.xxx.svc.cluster.local:4317

现在日志显示以下错误:

{
	"@timestamp": "2023-06-08T17:56:22.333359047-03:00",
	"level": "ERROR",
	"message": "Failed to export spans. The request could not be executed. Full error message: Connection reset",
	"traceId": "",
	"spanId": "",
	"logger": "io.opentelemetry.exporter.internal.okhttp.OkHttpExporter",
	"thread": "OkHttp http://tempo.observability.svc.cluster.local:4317/..."
}

有人遇到类似的问题吗?

版本信息:

  • spring boot: 3.1
  • micrometer-tracing: 1.1
  • opentelemetry-exporter-otlp: 1.26.0
  • tempo: 2.1
英文:

After upgrading from spring boot 2.7.10 (using sleuth) to 3.1 (micrometer-tracing) I updated my otel exporter config from

SPRING_SLEUTH_OTEL_EXPORTER_OTLP_ENDPOINT=http://tempo.xxx.svc.cluster.local:4317

to

MANAGEMENT_OTLP_TRACING_ENDPOINT=http://tempo.xxx.svc.cluster.local:4317

The log is now showing the following error:

{
	"@timestamp": "2023-06-08T17:56:22.333359047-03:00",
	"level": "ERROR",
	"message": "Failed to export spans. The request could not be executed. Full error message: Connection reset",
	"traceId": "",
	"spanId": "",
	"logger": "io.opentelemetry.exporter.internal.okhttp.OkHttpExporter",
	"thread": "OkHttp http://tempo.observability.svc.cluster.local:4317/..."
}

Has anyone had similar issue ?

version:

  • spring boot: 3.1
  • micrometer-tracing: 1.1
  • opentelemetry-exporter-otlp: 1.26.0
  • tempo: 2.1

答案1

得分: 1

Spring Boot 3.1 OtlpAutoConfiguration 使用 OtlpHttpSpanExporter,因此我们需要覆盖配置如下:

@Configuration
@EnableConfigurationProperties(OtlpProperties.class)
public class OtlpConfiguration {

  // OtlpAutoConfiguration 默认使用 HTTP,我们将其更新为使用 GRPC
  // https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/otlp/OtlpAutoConfiguration.java
  @Bean
  public OtlpGrpcSpanExporter otlpExporter(final OtlpProperties properties) {

    final OtlpGrpcSpanExporterBuilder builder =
        OtlpGrpcSpanExporter.builder()
            .setEndpoint(properties.getEndpoint())
            .setTimeout(properties.getTimeout())
            .setCompression(String.valueOf(properties.getCompression()).toLowerCase());

    for (final Entry<String, String> header : properties.getHeaders().entrySet()) {
      builder.addHeader(header.getKey(), header.getValue());
    }

    return builder.build();
  }
}

这是您提供的代码的翻译部分。

英文:

Spring boot 3.1 OtlpAutoConfiguration uses OtlpHttpSpanExporter so we need to override the configuration with:

@Configuration
@EnableConfigurationProperties(OtlpProperties.class)
public class OtlpConfiguration {

  // OtlpAutoConfiguration use HTTP by default, we update it to use GRPC
  // https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/otlp/OtlpAutoConfiguration.java
  @Bean
  public OtlpGrpcSpanExporter otlpExporter(final OtlpProperties properties) {

    final OtlpGrpcSpanExporterBuilder builder =
        OtlpGrpcSpanExporter.builder()
            .setEndpoint(properties.getEndpoint())
            .setTimeout(properties.getTimeout())
            .setCompression(String.valueOf(properties.getCompression()).toLowerCase());

    for (final Entry<String, String> header : properties.getHeaders().entrySet()) {
      builder.addHeader(header.getKey(), header.getValue());
    }

    return builder.build();
  }
}

huangapple
  • 本文由 发表于 2023年6月9日 04:58:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76435648.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定