OpenTracing Instrumentation for Spring Data Redis 2.x

OpenTracing Instrumentation for Spring Redis classes

License

License

Categories

Categories

Redis Data Databases
GroupId

GroupId

io.opentracing.contrib
ArtifactId

ArtifactId

opentracing-redis-spring-data2
Last Version

Last Version

0.1.16
Release Date

Release Date

Type

Type

jar
Description

Description

OpenTracing Instrumentation for Spring Data Redis 2.x
OpenTracing Instrumentation for Spring Redis classes

Download opentracing-redis-spring-data2

How to add to project

<!-- https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-redis-spring-data2/ -->
<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-spring-data2</artifactId>
    <version>0.1.16</version>
</dependency>
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-redis-spring-data2/
implementation 'io.opentracing.contrib:opentracing-redis-spring-data2:0.1.16'
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-redis-spring-data2/
implementation ("io.opentracing.contrib:opentracing-redis-spring-data2:0.1.16")
'io.opentracing.contrib:opentracing-redis-spring-data2:jar:0.1.16'
<dependency org="io.opentracing.contrib" name="opentracing-redis-spring-data2" rev="0.1.16">
  <artifact name="opentracing-redis-spring-data2" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.opentracing.contrib', module='opentracing-redis-spring-data2', version='0.1.16')
)
libraryDependencies += "io.opentracing.contrib" % "opentracing-redis-spring-data2" % "0.1.16"
[io.opentracing.contrib/opentracing-redis-spring-data2 "0.1.16"]

Dependencies

compile (2)

Group / Artifact Type Version
io.opentracing.contrib : opentracing-redis-common jar 0.1.16
io.opentracing : opentracing-noop jar 0.33.0

provided (2)

Group / Artifact Type Version
org.springframework.data : spring-data-redis jar 2.2.4.RELEASE
io.projectreactor : reactor-core jar 3.1.9.RELEASE

test (7)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.2.4.RELEASE
org.springframework.boot : spring-boot-starter-data-redis jar 2.2.4.RELEASE
org.springframework : spring-test jar 5.2.3.RELEASE
com.github.kstyrc : embedded-redis jar 0.6
org.mockito : mockito-core jar 2.27.0
io.opentracing : opentracing-mock jar 0.33.0
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Released Version Apache-2.0 license

OpenTracing Redis Client Instrumentation

OpenTracing instrumentation for Redis Client

Requirements

  • Java 8

Installation

Jedis

Jedis 2

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-jedis</artifactId>
    <version>VERSION</version>
</dependency>

Jedis 3

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-jedis3</artifactId>
    <version>VERSION</version>
</dependency>

Lettuce

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-lettuce-5.2</artifactId>
    <version>VERSION</version>
</dependency>

Redisson

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-redisson</artifactId>
    <version>VERSION</version>
</dependency>

Spring Data Redis 1.x

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-spring-data</artifactId>
    <version>VERSION</version>
</dependency>

Spring Data Redis 2.x

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-redis-spring-data2</artifactId>
    <version>VERSION</version>
</dependency>

Usage

// Instantiate tracer
Tracer tracer = ...

// Create TracingConfiguration
TracingConfiguration tracingConfiguration = new TracingConfiguration.Builder(tracer).build(); 

Jedis

// Create Tracing Jedis
Jedis jedis = new TracingJedis(tracingConfiguration);

jedis.set("foo", "bar");
String value = jedis.get("foo");

Jedis Cluster

Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7379));

// Create Tracing Jedis Cluster
JedisCluster jc = new TracingJedisCluster(jedisClusterNodes, tracingConfiguration);
jc.set("foo", "bar");
String value = jc.get("foo");

Jedis Pool

// Configure the pool
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(10);
poolConfig.setTestOnBorrow(false);

// Create Tracing Jedis Pool
JedisPool pool = new TracingJedisPool(poolConfig, "127.0.0.1", 6379, tracingConfiguration);

try (Jedis jedis = pool.getResource()) {
    // jedis will be automatically closed and returned to the pool at the end of "try" block
    jedis.set("foo", "bar");
    String value = jedis.get("foo");
}

Jedis Sentinel Pool

// Create Tracing Jedis Sentinel Pool
JedisSentinelPool pool = new TracingJedisSentinelPool(tracingConfiguration, MASTER_NAME, sentinels, poolConfig);

try (Jedis jedis = pool.getResource()) {
// jedis will be automatically closed and returned to the pool at the end of "try" block
   jedis.set("foo", "bar"));
   String value = jedis.get("foo"));
}

Jedis Span Name

By default, span names are set to the operation performed by the Jedis object. To customize the span name, provide a Function to the TracingConfiguration object that alters the span name. If a function is not provided, the span name will remain the default. Refer to the RedisSpanNameProvider class for a function that prefixes the operation name.

TracingConfiguration tracingConfiguration = new TracingConfiguration.Builder(tracer)
    .withSpanNameProvider(RedisSpanNameProvider.PREFIX_OPERATION_NAME("redis."))
    .build(); 
//Create Tracing Jedis with custom span name
Jedis jedis = new TracingJedis(tracingConfiguration);
jedis.set("foo", "bar");
//Span name is now set to "redis.set"

Lettuce

// Create client
RedisClient client = RedisClient.create("redis://localhost");

// Decorate StatefulRedisConnection with TracingStatefulRedisConnection
StatefulRedisConnection<String, String> connection = 
    new TracingStatefulRedisConnection(client.connect(), tracingConfiguration);

// Get sync redis commands
RedisCommands<String, String> commands = connection.sync();

// Get async redis commands
RedisAsyncCommands<String, String> commandsAsync = connection.async();

Redisson

// Create Redisson config object
Config = ...

// Create Redisson instance
RedissonClient redissonClient = Redisson.create(config);

// Decorate RedissonClient with TracingRedissonClient
RedissonClient tracingRedissonClient =  new TracingRedissonClient(redissonClient, tracingConfiguration);

// Get object you need using TracingRedissonClient
RMap<MyKey, MyValue> map = tracingRedissonClient.getMap("myMap");

Spring

// Create tracing connection factory bean
@Bean
public RedisConnectionFactory redisConnectionFactory() {
    LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory();
    lettuceConnectionFactory.afterPropertiesSet();
    return new TracingRedisConnectionFactory(lettuceConnectionFactory,
        new TracingConfiguration.Builder(tracer()).build());
}

Note: if you use Lettuce/Jedis you could achieve the same result using the Lettuce/Jedis support when configuring LettuceConnectionFactory/JedisConnectionFactory instead of using a wrapping TracingRedisConnectionFactory.

License

Apache 2.0 License.

io.opentracing.contrib

3rd-Party OpenTracing API Contributions

3rd-party contributions that use OpenTracing. **The repositories in this org are *not* affiliated with the CNCF.**

Versions

Version
0.1.16
0.1.15
0.1.14
0.1.12
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.16