Skip to content

Need to create a bean OtlpHttpSpanExporter before opentelemetry spring boot starter. #11052

Closed
@DineshkumarVG

Description

@DineshkumarVG

Hi,
I am using oauth authentication for otel collector, The token needs to be changed one hour once. I need to set that dynamically. I have used your setHeader with supplier and it was working as expected. I am trying to implement that using @bean annotation. but springboot auto configuration injects the bean before the bean i have created. Anyone please help on this or is there anything i have missed?

It was working fine with the version 2.1.0-alpha

Sample code for reference.
build.gradle

`dependencyManagement {
imports {
mavenBom("io.opentelemetry:opentelemetry-bom:1.36.0")
mavenBom("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha")
}
}

implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter")`

Bean File

`@AutoConfiguration
@ConditionalOnClass({OpenTelemetry.class})
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
public class RefreshToken {

@bean
public OtlpHttpSpanExporter otlpHttpSpanExporter() {
Supplier<Map<String, String>> mapSupplier = () -> {
Map<String, String> map = new HashMap<>();
try {
map.put("Authorization", "Bearer " + refreshToken());
} catch (Exception e) {
throw new RuntimeException(e);
}
return map;
};
return OtlpHttpSpanExporter.builder().setHeaders(mapSupplier)
.setEndpoint("url").build();
}
}`

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions