-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Jojoooo1/release/9.0
Release - 9.0
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/mycompany/microservice/api/infra/otlp/OtlpConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |