Search code examples
javaprometheusopentracing

How to configure an OpenTracing Tracer to push data to Prometheus/Grafana in Java


I have a Spring Boot app using OpenTracing and I would like to push its data to Prometheus, so I can query all metrics via Grafana (like in this tutorial https://www.hawkular.org/blog/2017/06/26/opentracing-appmetrics.html).

The problem is, I haven't found any consistent solution to do this, all the examples that I have found so far are outdated, deprecated or lacks documentation.

Ideally, I am looking for some solution which returns an instance of io.opentracing.Tracer, similar to what Jaeger does:

        Tracer tracer = new JaegerTracer.Builder("couchbase")
            .withReporter(new RemoteReporter.Builder()
                    .withSender(new UdpSender(AGENT_HOST, 6831, 0))
                    .build())
            .withSampler(new ConstSampler(true))
            .withScopeManager(new AutoFinishScopeManager())
            .withMetricsFactory(metricsFactory)
            .build();

Best


Solution

  • Note that tracing data (spans) are not the same as "metrics", although there could be some overlap in some cases. I recommend the following blog post on what is the purpose of each, including logging:

    https://peter.bourgon.org/blog/2017/02/21/metrics-tracing-and-logging.html

    That said, there is the OpenTracing library mentioned in the blog post you linked, called opentracing-contrib/java-metrics. It allows you to pick specific spans and record them as data points (metrics). It works as a decorator of a concrete tracer, so, your spans would reach a concrete backend like Jaeger and, additionally, create data points based on the configured spans. The data points are then reported via Micrometer, which can be configured to expose this data in Prometheus format.

    The problem is, I haven't found any consistent solution to do this, all the examples that I have found so far are outdated, deprecated or lacks documentation.

    Please, open an issue on the java-metrics repository with the problems you are facing.