Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release - 9.0 #31

Merged
merged 10 commits into from
Sep 14, 2023
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<!-- Metrics -->
<hibernate-micrometer.version>6.3.0.Final</hibernate-micrometer.version>
<datasource-micrometer.version>1.0.2</datasource-micrometer.version>
<opentelemetry-exporter-otlp.version>1.28.0</opentelemetry-exporter-otlp.version>
<opentelemetry-exporter-otlp.version>1.30.1</opentelemetry-exporter-otlp.version>

<!-- Lombok & Mapstruct -->
<projectlombok.version>1.18.28</projectlombok.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mycompany.microservice.api.infra.otlp;

import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.actuate.autoconfigure.tracing.otlp.OtlpProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

// For some reason breaking change was introduced, and we need to pass a default value
private static final String OTLP_DEFAULT = "http://localhost:4318/api/traces";

// 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(
StringUtils.isNotBlank(properties.getEndpoint())
? properties.getEndpoint()
: OTLP_DEFAULT)
.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();
}
}