Please take the OpenCensus user survey



To provide client side observability, a Java Redis client Jedis has been instrumented with OpenCensus for tracing and metrics.

Resource Repository link
Jedis wrapper on Github
Maven Central URL


You will need the following:

Before proceeding we’ll need to firstly install the following

Requirement Guide
Redis server
Prometheus Prometheus codelab
Zipkin Zipkin codelab

How it works

The integration extends redis.clients.jedis.Jedis by wrapping most methods with instrumentation that enables tracing and metrics.

Dependency listing

<!-- -->
compile group: 'io.orijtech.integrations', name: 'ocjedis', version: '0.0.3'
<!-- -->
<dependency org="io.orijtech.integrations" name="ocjedis" rev="0.0.3"/>


One just needs to import the integration and use it like they would for Jedis

import io.orijtech.integrations.ocjedis.OcWrapJedis;
import io.orijtech.integrations.ocjedis.Observability;

private static final OcWrapJedis jedis = new OcWrapJedis(redisHost);

Enabling observability

We’ll need to enable stats by registering and enabling all available views

// Enable exporting of all the Jedis specific metrics and views

Available metrics

Metric search suffix Description Tags
jedis/latency The latency of the various methods “method”, “error”, “status”
jedis/calls The calls made by various methods “method”, “error”, “status”
jedis/data_transferred The amount of data transferred “method”, “type”

End to end example

In this end-to-end example, we’ve taken an excerpt from a search service. It checks Redis server if the expensively computed response was already saved. If not found (“cache miss”), it’ll process the response then save it to the cache for later “cache hits”.

package io.opencensus.tutorials.jedis;

import io.opencensus.trace.Tracer;
import io.opencensus.trace.Tracing;
import io.opencensus.trace.Span;
import io.opencensus.trace.Status;
import io.opencensus.trace.config.TraceConfig;
import io.opencensus.trace.samplers.Samplers;
import io.opencensus.common.Scope;

// Enable the exporters.
import io.opencensus.exporter.stats.prometheus.PrometheusStatsCollector;
import io.opencensus.exporter.trace.zipkin.ZipkinTraceExporter;
import io.prometheus.client.exporter.HTTPServer;

import io.orijtech.integrations.ocjedis.OcWrapJedis;
import io.orijtech.integrations.ocjedis.Observability;

public class JedisOpenCensus {
    private static final OcWrapJedis jedis = new OcWrapJedis("localhost");
    private static final Tracer tracer = Tracing.getTracer();

    public static void main(String ...args) {
        // Now enable OpenCensus exporters
        try {
        } catch(Exception e) {
            System.err.println("Failed to create OpenCensus exporters " + e);

        while (true) {
            try {
                // Sleeping for a bit to avoid exhausting CPU.
            } catch (Exception e) {

            // Add user input here.
            String query = "This simulates user input to aid populating observability signals";
            String result = "";

            try (Scope ss = JedisOpenCensus.tracer.spanBuilder("Search").startScopedSpan()) {

                Span span = JedisOpenCensus.tracer.getCurrentSpan();

                // Check Redis if we've memoized the response.
                result = jedis.get(query);
                if (result == null || result == "") {
                    // Cache miss so process and memoize it
                    span.addAnnotation("Cache miss!");
                    result = "$" + query + "$";
                    jedis.set(query, result);
                } else {
                    span.addAnnotation("Cache hit!");
                    // Clear the output so that the next search will be a Cache miss.
            } catch (Exception e) {
                Span span = JedisOpenCensus.tracer.getCurrentSpan();
                System.err.println("Exception "+ e);

            // Finally print out the output.
            System.out.println("< " + result + "\n");

    private static void setupOpenCensusAndExporters() throws Exception {
        // Enable exporting of all the Jedis specific metrics.

        // Change the sampling rate to always sample.
        TraceConfig traceConfig = Tracing.getTraceConfig();

        // Next create the Zipkin trace exporter.
        ZipkinTraceExporter.createAndRegister("http://localhost:9411/api/v2/spans", "itunes-search-client");

        // And then enable the Prometheus exporter too.
        // Start the Prometheus server
        HTTPServer prometheusServer = new HTTPServer(9888, true);
<project xmlns="" xmlns:xsi=""

        <opencensus.version>0.15.0</opencensus.version> <!-- The OpenCensus version to use -->





        <!-- -->






Running it

mvn install && mvn exec:java -Dexec.mainClass=io.opencensus.tutorials.jedis.JedisOpenCensus

Viewing your metrics

Please visit the Prometheus UI at http://localhost:9090

Viewing your traces

Please visit the Zipkin UI at http://localhost:9411/zipkin


Resource URL
OCJedis integration on Github
OCJedis on Maven Central
Jedis project Javadoc
Jedis project Github