Reputation: 1
Im setting up OpenTelemetry to capture metrics from my app. For reasons, I find it easier to use the spring-boot auto instrumentation https://opentelemetry.io/docs/zero-code/java/spring-boot-starter/getting-started rather than the injected java agent. Among other things is that getting it on the on-prem server is cumbersome and I would rather have the apps themselves setup everything.
I have successfully add metrics and sending of metrics to my collector using the bom
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-bom</artifactId>
<version>2.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
and auto configuration
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
</dependency>
What I would like to do now is register my own custom metrics like this:
private final LongCounter counter = GlobalOpenTelemetry.getMeterProvider().meterBuilder("my-app-meters").build().counterBuilder("my-counter").build();
or something similiar. It does not have to use the GlobalOtel instance but I cannot figure out how I should set it up so that I can retain the auto instrumentation for http.server etc and have my-custom-counter.
My config looks like this:
otel:
instrumentation:
micrometer:
enabled: true
logs:
exporter: none
traces:
exporter: none
metrics:
exporter: console
metric:
export:
interval: 5000
I have tried setting up a bean like:
@Bean
public Meter meterProver() {
return GlobalOpenTelemetry.getMeterProvider().meterBuilder("my-app").build();
}
and then injecting it into my controller. The counter sets up but it does not get exported or is not shown in my result. Im assuming that the actual global registry does not pick up the counter correctly.
Is there a way to use the spring-boot auto instrumentation and manual counters in Otel?
Upvotes: 0
Views: 264