Skip to content

Tracing

Mark Paluch edited this page Apr 19, 2023 · 5 revisions

Tracing gives insights about individual Redis commands sent to Redis to trace their frequency, duration and to trace of which commands a particular activity consists. Lettuce provides a tracing SPI to avoid mandatory tracing library dependencies. Lettuce ships integrations with Micrometer Tracing and Brave which can be configured through client resources.

Micrometer Tracing

With Micrometer tracing enabled, Lettuce creates an observation for each Redis command resulting in spans per Command and corresponding Meters if configured in Micrometer’s ObservationContext.

Prerequisites

Lettuce requires the Micrometer Tracing dependency to provide Tracing functionality. Make sure to include that dependency on your classpath.

If using Maven, add the following dependency to your pom.xml:

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-tracing</artifactId>
</dependency>

The following example shows how to configure tracing through ClientResources:

ObservationRegistry observationRegistry = …;

MicrometerTracing tracing = new MicrometerTracing(observationRegistry, "Redis");

ClientResources resources = ClientResources.builder().tracing(tracing).build();

Brave

With Brave tracing enabled, Lettuce creates a span for each Redis command. The following options can be configured:

  • serviceName (defaults to redis).

  • Endpoint customizer. This option can be used together with a custom SocketAddressResolver to attach custom endpoint details.

  • Span customizer. Allows for customization of spans based on the actual Redis Command object.

  • Inclusion/Exclusion of all command arguments in a span. By default, all arguments are included.

Prerequisites

Lettuce requires the Brave dependency (at least 5.1) to provide Tracing functionality. Make sure to include that dependency on your classpath.

If using Maven, add the following dependency to your pom.xml:

<dependency>
    <groupId>io.zipkin.brave</groupId>
    <artifactId>brave</artifactId>
</dependency>

The following example shows how to configure tracing through ClientResources:

brave.Tracing clientTracing = …;

BraveTracing tracing = BraveTracing.builder().tracing(clientTracing)
    .excludeCommandArgsFromSpanTags()
    .serviceName("custom-service-name-goes-here")
    .spanCustomizer((command, span) -> span.tag("cmd", command.getType().name()))
    .build();

ClientResources resources = ClientResources.builder().tracing(tracing).build();

Lettuce ships with a Tracing SPI in io.lettuce.core.tracing that allows custom tracer implementations.

Clone this wiki locally