14 Mart 2023 Salı

SpringBoot Actuator - Metrics Endpoint Open Telemetry Exporter

Giriş
Açıklaması şöyle
Until Spring Boot 2, Telemetry traces integration was made using Spring Cloud Sleuth. For Spring Boot 3 those features were migrated to Micrometer. Micrometer handles the instrumentation of the application, integrating nicely with Spring Boot and other libraries you are probably using. But Micrometer itself doesn’t export the traces to the remote Open Telemetry endpoint. For doing that we need an additional dependency on the Open Telemetry Exporter.
Maven
Şöyle yaparız
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-otlp</artifactId>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
  <groupId>io.opentelemetry</groupId>
  <artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
SpanExporter Sınıfı
Açıklaması şöyle
The Open Telemetry Exporter will try to export traces to a monitoring tool running locally, but it also provides a class to export them to a remote endpoint. This integration is currently not natively available in Spring Boot 3 (at least I didn’t find it) so you have to register a bean that will handle this task
Örnek
Şöyle yaparız
@Configuration
public class OtelConfiguration {

  @Bean
  SpanExporter otlpHttpSpanExporter() {
    return OtlpHttpSpanExporter
      .builder()
      .addHeader("Content-Type", "application/x-protobuf")
      .setEndpoint("http://remote-monitoring-tool/enpoint/v1/trace")
      .build();
  }
}




Hiç yorum yok:

Yorum Gönder