Prabal Rakshit
Prabal Rakshit

Reputation: 509

Unable to send Counters to Dynatrace via OTLP

I am using an Open Telemtery JAVA SDK to publish some metrics an OTEL sink like Dynatrace. I am sending gauges, updown counters etc. to dynatrace and see that UpDown Counters are successuflly pushed, but the counters are not. Could you kindly help me understand where I could be going wrong?

The code that I am using OTLP SDK Meter Provider

    @Bean
    public SdkMeterProvider sdkMeterProvider(){
        return SdkMeterProvider.builder()
                .registerMetricReader(
                        PeriodicMetricReader.builder(
                            OtlpHttpMetricExporter.builder()
                                .setEndpoint(otlpApiUrlPrefix+"/v2/otlp/v1/metrics")
                                .addHeader("Authorization", "Api-Token "+otlpApiToken).build())
                            .setInterval(15, TimeUnit.SECONDS)  /** determines the frequency of publishing metrics **/
                        .build())
                .build();
    }

Initializing Updown Counter with callback (This works successfully)

        meter
                .upDownCounterBuilder("otlp.demo.updown.counter.with.callback")
                .setDescription("Demo updown counter with callback")
                .setUnit("boxes")
                .buildWithCallback(result -> result.record(currentvalue, attributes));

Initializing Counter with Callback

      meter
                .counterBuilder("otlp.demo.counter.with.callback")
                .setDescription("Counter with callback")
                .setUnit("count")
                .buildWithCallback(result -> result.record(currentvalue, attributes));

This does not get transmitted to the downstream OTEL Sink (Dyantrace)

Initializing Counter without Callback

        longCounterWithoutCallback = meter
                .counterBuilder("otlp.demo.counter.without.callback")
                .setDescription("Counter without callback")
                .setUnit("count")
                .build();

I am incrementing this counter as follows:

    /** Random increment/ decrement of the counter. Does not control the frequency of metrics export **/
    @Scheduled(cron = "${otlp.metrics.cron}")
    public void processCounter(){
        currentvalue = currentvalue + (-5L + (long) (Math.random() * (20L)));
        logger.info("Successfully modified counter value {}", currentvalue);
        longCounterWithoutCallback.add(1L); // Only increment the counter
    }

I am trying to use this as an example https://github.com/open-telemetry/opentelemetry-java-examples/blob/main/metrics/src/main/java/io/opentelemetry/example/metrics/LongCounterExample.java

Upvotes: 0

Views: 29

Answers (0)

Related Questions