├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .settings.xml ├── .travis.yml ├── LICENSE ├── README.md ├── RELEASE.md ├── header.txt ├── mvnw ├── mvnw.cmd ├── opentracing-redis-common ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── opentracing │ │ └── contrib │ │ └── redis │ │ └── common │ │ ├── Action.java │ │ ├── RedisCommand.java │ │ ├── RedisSpanNameProvider.java │ │ ├── ThrowingAction.java │ │ ├── ThrowingSupplier.java │ │ ├── TracingConfiguration.java │ │ └── TracingHelper.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── common │ ├── RedisSpanNameProviderTest.java │ ├── TracingConfigurationTest.java │ └── TracingHelperTest.java ├── opentracing-redis-jedis ├── pom.xml └── src │ ├── main │ └── java │ │ ├── io │ │ └── opentracing │ │ │ └── contrib │ │ │ └── redis │ │ │ └── jedis │ │ │ ├── TracingJedis.java │ │ │ ├── TracingJedisCluster.java │ │ │ ├── TracingJedisPool.java │ │ │ └── TracingJedisSentinelPool.java │ │ └── redis │ │ └── clients │ │ └── jedis │ │ └── TracingJedisWrapper.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── jedis │ ├── TracingJedisPoolTest.java │ ├── TracingJedisSentinelPoolTest.java │ └── TracingJedisTest.java ├── opentracing-redis-jedis3 ├── pom.xml └── src │ ├── main │ └── java │ │ ├── io │ │ └── opentracing │ │ │ └── contrib │ │ │ └── redis │ │ │ └── jedis3 │ │ │ ├── TracingJedis.java │ │ │ ├── TracingJedisCluster.java │ │ │ ├── TracingJedisPool.java │ │ │ └── TracingJedisSentinelPool.java │ │ └── redis │ │ └── clients │ │ └── jedis │ │ └── TracingJedisWrapper.java │ └── test │ └── java │ └── io.opentracing.contrib.redis.jedis3 │ ├── TracingJedisPoolTest.java │ ├── TracingJedisSentinelPoolTest.java │ └── TracingJedisTest.java ├── opentracing-redis-lettuce-5.0 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── opentracing │ │ └── contrib │ │ └── redis │ │ └── lettuce50 │ │ ├── CompletableRedisFuture.java │ │ ├── TracingRedisAdvancedClusterAsyncCommands.java │ │ ├── TracingRedisAdvancedClusterCommands.java │ │ ├── TracingRedisAsyncCommands.java │ │ ├── TracingRedisCommands.java │ │ ├── TracingRedisPubSubAsyncCommands.java │ │ ├── TracingRedisPubSubCommands.java │ │ ├── TracingRedisPubSubListener.java │ │ ├── TracingStatefulRedisClusterConnection.java │ │ ├── TracingStatefulRedisConnection.java │ │ └── TracingStatefulRedisPubSubConnection.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── lettuce50 │ └── TracingLettuce50Test.java ├── opentracing-redis-lettuce-5.1 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── opentracing │ │ └── contrib │ │ └── redis │ │ └── lettuce51 │ │ ├── CompletableRedisFuture.java │ │ ├── TracingRedisAdvancedClusterAsyncCommands.java │ │ ├── TracingRedisAdvancedClusterCommands.java │ │ ├── TracingRedisAsyncCommands.java │ │ ├── TracingRedisCommands.java │ │ ├── TracingRedisPubSubAsyncCommands.java │ │ ├── TracingRedisPubSubCommands.java │ │ ├── TracingRedisPubSubListener.java │ │ ├── TracingStatefulRedisClusterConnection.java │ │ ├── TracingStatefulRedisConnection.java │ │ └── TracingStatefulRedisPubSubConnection.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── lettuce51 │ └── TracingLettuce51Test.java ├── opentracing-redis-lettuce-5.2 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── opentracing │ │ └── contrib │ │ └── redis │ │ └── lettuce52 │ │ ├── CompletableRedisFuture.java │ │ ├── TracingRedisAdvancedClusterAsyncCommands.java │ │ ├── TracingRedisAdvancedClusterCommands.java │ │ ├── TracingRedisAsyncCommands.java │ │ ├── TracingRedisCommands.java │ │ ├── TracingRedisPubSubAsyncCommands.java │ │ ├── TracingRedisPubSubCommands.java │ │ ├── TracingRedisPubSubListener.java │ │ ├── TracingStatefulRedisClusterConnection.java │ │ ├── TracingStatefulRedisConnection.java │ │ └── TracingStatefulRedisPubSubConnection.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── lettuce52 │ └── TracingLettuce52Test.java ├── opentracing-redis-redisson ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── opentracing │ │ └── contrib │ │ └── redis │ │ └── redisson │ │ ├── CompletableRFuture.java │ │ ├── TracingRAtomicDouble.java │ │ ├── TracingRAtomicLong.java │ │ ├── TracingRBitSet.java │ │ ├── TracingRBlockingDeque.java │ │ ├── TracingRBlockingQueue.java │ │ ├── TracingRBoundedBlockingQueue.java │ │ ├── TracingRBucket.java │ │ ├── TracingRBuckets.java │ │ ├── TracingRCollectionMapReduce.java │ │ ├── TracingRCountDownLatch.java │ │ ├── TracingRDelayedQueue.java │ │ ├── TracingRDeque.java │ │ ├── TracingRDoubleAdder.java │ │ ├── TracingRExpirable.java │ │ ├── TracingRKeys.java │ │ ├── TracingRLexSortedSet.java │ │ ├── TracingRList.java │ │ ├── TracingRListMultimap.java │ │ ├── TracingRLocalCachedMap.java │ │ ├── TracingRLock.java │ │ ├── TracingRLongAdder.java │ │ ├── TracingRMap.java │ │ ├── TracingRMapCache.java │ │ ├── TracingRMapReduce.java │ │ ├── TracingRMapReduceExecutor.java │ │ ├── TracingRMultimap.java │ │ ├── TracingRObject.java │ │ ├── TracingRPermitExpirableSemaphore.java │ │ ├── TracingRPriorityBlockingDeque.java │ │ ├── TracingRPriorityBlockingQueue.java │ │ ├── TracingRPriorityDeque.java │ │ ├── TracingRPriorityQueue.java │ │ ├── TracingRQueue.java │ │ ├── TracingRReadWriteLock.java │ │ ├── TracingRRingBuffer.java │ │ ├── TracingRScoredSortedSet.java │ │ ├── TracingRSemaphore.java │ │ ├── TracingRSet.java │ │ ├── TracingRSetCache.java │ │ ├── TracingRSetMultimap.java │ │ ├── TracingRSetMultimapCache.java │ │ ├── TracingRSortedSet.java │ │ ├── TracingRTransferQueue.java │ │ ├── TracingRedissonClient.java │ │ └── TracingRedissonHelper.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── redisson │ └── TracingRedissonTest.java ├── opentracing-redis-spring-data ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── opentracing │ │ └── contrib │ │ └── redis │ │ └── spring │ │ └── data │ │ └── connection │ │ ├── TracingRedisClusterConnection.java │ │ ├── TracingRedisConnection.java │ │ ├── TracingRedisConnectionFactory.java │ │ └── TracingRedisSentinelConnection.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── spring │ └── data │ ├── connection │ ├── AssertionUtils.java │ ├── MockConfiguration.java │ ├── TracingRedisClusterConnectionTest.java │ ├── TracingRedisConnectionFactoryTest.java │ └── TracingRedisConnectionTest.java │ └── processor │ ├── RedisConnectionFactoryBeanPostProcessor.java │ ├── RedisConnectionFactoryBeanPostProcessorConfiguration.java │ └── RedisConnectionFactoryBeanPostProcessorTest.java ├── opentracing-redis-spring-data2 ├── pom.xml └── src │ ├── main │ └── java │ │ └── io │ │ └── opentracing │ │ └── contrib │ │ └── redis │ │ └── spring │ │ └── data2 │ │ └── connection │ │ ├── TracingReactiveRedisClusterConnection.java │ │ ├── TracingReactiveRedisConnection.java │ │ ├── TracingRedisClusterConnection.java │ │ ├── TracingRedisConnection.java │ │ ├── TracingRedisConnectionFactory.java │ │ └── TracingRedisSentinelConnection.java │ └── test │ └── java │ └── io │ └── opentracing │ └── contrib │ └── redis │ └── spring │ └── data2 │ ├── connection │ ├── AssertionUtils.java │ ├── MockConfiguration.java │ ├── TracingRedisClusterConnectionTest.java │ ├── TracingRedisConnectionFactoryTest.java │ └── TracingRedisConnectionTest.java │ ├── it │ ├── SpringDataRedisTestConfiguration.java │ └── TracingSpringDataRedisTest.java │ └── processor │ ├── RedisConnectionFactoryBeanPostProcessor.java │ ├── RedisConnectionFactoryBeanPostProcessorConfiguration.java │ └── RedisConnectionFactoryBeanPostProcessorTest.java ├── pom.xml └── travis └── publish.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | target/ 4 | 5 | # VS Code 6 | .vscode/ 7 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opentracing-contrib/java-redis-client/9f9def3f0fa0eab5712f125ae774349a688a89dc/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip -------------------------------------------------------------------------------- /.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 21 | 22 | 23 | sonatype 24 | ${env.SONATYPE_USER} 25 | ${env.SONATYPE_PASSWORD} 26 | 27 | 28 | bintray 29 | ${env.BINTRAY_USER} 30 | ${env.BINTRAY_KEY} 31 | 32 | 33 | jfrog-snapshots 34 | ${env.BINTRAY_USER} 35 | ${env.BINTRAY_KEY} 36 | 37 | 38 | github.com 39 | ${env.GH_USER} 40 | ${env.GH_TOKEN} 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | 4 | language: java 5 | jdk: 6 | - oraclejdk8 7 | 8 | git: 9 | quiet: true 10 | 11 | cache: 12 | directories: 13 | - $HOME/.m2/repository 14 | 15 | before_install: 16 | # allocate commits to CI, not the owner of the deploy key 17 | - git config user.name "opentracingci" 18 | - git config user.email "opentracingci+opentracing@googlegroups.com" 19 | 20 | # setup https authentication credentials, used by ./mvnw release:prepare 21 | - git config credential.helper "store --file=.git/credentials" 22 | - echo "https://$GH_TOKEN:@github.com" > .git/credentials 23 | 24 | install: 25 | # Override default travis to use the maven wrapper 26 | - ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -q 27 | 28 | script: 29 | - ./travis/publish.sh 30 | 31 | branches: 32 | except: 33 | - /^[0-9]/ 34 | 35 | after_success: 36 | - mvn -q jacoco:report coveralls:report 37 | 38 | env: 39 | global: 40 | # Ex. travis encrypt BINTRAY_USER=your_github_account 41 | - secure: "dSAhes4XbRi7YTrGgILztF7QNI3hVik2buaMKYBo9gkfNg+1bPxjdGSunXti2FuAm7ic5YSNqHy6mixE7chbIFQl5f0oDDm8kbRU8kAzjucvO0B9M/hbC6MwZuO9+y3QlWbUFrIDQtDK19LOr+xSeXcvFhDuBeFjKnIu6vuvalfaNUIihDQvUe3tJo4YO0EMc9HB7S3l+Os9vMQJTNHR1tt0y9bJkMJqFivVJjnso0H/jUS8g4t0hkmxVjS9OST/OBmzULK3bJ0L7uyd8dbG/YaV0pcjxuhVNoexbdwrCND1EdT4IjvluTPP5x+SU8A5lb6tMwYgPUCeIDAKGFSzxysNguzYXNo6DNHo+zvAUvqgCVzzHs+wbA98YDRdCL4eDKt6AMjKuesrwGiRQM1fY1aPBzxbWCM2Uc4Q3K+rRFM3tgLC49FzYUOjNApnLLa5HQZuhm2wSr45I0rAM4HwVwmS91GC4ujRlnE0SIu7XvSkBWnpRZtWPAJSm9m8Hr1av4fBjKrf4ACKvkyjJPolH6MzEfIJwZbB+M6dPR0vdJ1IlVky7yqpNTCtRH1EdI/yCwTnIV/pIVsY9cJ7jk54Ht9yqrv0gNLeHQvua5lXN8zZdwez7oGCmhUx7qN5Hs/7VidFpOopsleMsWYu26RiUjXaw6kuIxj3yMKyuHX1SRk=" 42 | # Ex. travis encrypt BINTRAY_KEY=xxx-https://bintray.com/profile/edit-xxx --add 43 | - secure: "VVjLpq0GzXJKDMsokAX9Ukciqv30Bs1p6HCWDqdbtL4EbeFXH4DE96Mi9Ve+LF6ccK8ddh20oAWc1taZlgwSFOf1yIB3Q0GyOWLErvpdxO0gA60UGdbHwfctXEk+zdHKUI5heVF+5kTf8/tHhOr7SKcjz+TP2VW86Mdc8CxmLrKxGIQcXZxUaQdndklb0qWD9MJanU0ihaLvAU/XLpRlbITSMkROrP5YYmN4sb/nEiut2Ae2Lv0zyrlTReBWc/ldxWCwSaz/z7N88NORR9EzTX+gzEGn+HDKlHfXDgNgVf0zaetM6rw5g92KQWMT6YxLn8TSQGR2TIGpfRpH0kTaY70h+P8vZAcTv+SkzbadU2A9YAcJuU+xki8yoL5lUZJ5Sh+0UHKPzqmiwsPTkSGYOtGf2Yq3v7jU7o3jc1cMDvjkAe/a0Ot0qhGiAxRd1FIjnvZacOWPAZ2UhTtdDkOg1AsOchRbV83Lh/gZtVLMIp0CdrKUML/RQuCwJVXu7rufE7djx28Tw562xWJXfcGQky9Jb2TpJh4jwCC2DGFWl/LOIih78wlKPMDo+V7TVxcnUlNlqfDtg9CpcEb6gyP6LTNxPgNIogjhrCWI65mGOhcOnCZgX1HNeUlm+24nst+ugE0IMJbUK23W+aXjitqOfzONWy6Gx9t9m8POxxqoXwI=" 44 | # Ex. travis encrypt GH_TOKEN=XXX-https://github.com/settings/tokens-XXX --add 45 | - secure: "KUDBwlA9qzCZlW3GkcXdcrUvouxYPUu1dOg9/C9J08YnYq6SKDJJLdCWOg3iCGeWQ54GDhReCBcPEbgslHnlKBHloDkpL6cxu5jNnZZhsC3VTpGYv1w7xm135BwhY6RouCfa0zoz/2sgU3LJQGVUQo9c11sgvPC7Exq6T/FrF+sT7Djc06EwOt6WcFLI7e0TidiWwBJxfUb+rQPYdmuDhTn2jQJKuuxPBa4UkSG/KPBe51HvnsJfA4rme2VdUIZt0F8NHj6zR6jY2zSf+fV6jvCSXm9SLWwEJnjBi3oOG8vKSAoD2f/c1aX2Bv8sXcSf4HXz0WFc+UMHhsvx/SuURvyRysKosIG2sYCUa78GEI5iNfDX2zBNmW05AfZOGc/Szic2Oq/t/A0Nk3vqTZI9n0qkLfPONgCrX1g8JUq8P4xZprVz4yz/falsg1B3RW7Bpjdahqa7XvS4j9G0LRn0h9gP4f6Yl74sKVmkSaPIAEJLIsLqUT7b/DtV+VAYmjV7r6qqDiBYxF4Bbb8pz0zjj7SRGPYP9mobQvOJsXz+DKytFKf/QqoLsvDFedIPPiLXnzICkzmq4WOmDu/A+thgrokpeQ8/acB8muvtw6iqAFPLqeydyrH3Y33e0XJVIkzxPU/Pmzh6FGLpus0bp+cakFP6EGQkAwFuO8k/0kT1Ye8=" 46 | # Ex. travis encrypt SONATYPE_USER=your_sonatype_account 47 | - secure: "wiVXMjXD484eKFxler1Leu63kDGDuNBfFgqlMYb0LyT7pUnwNypIRqi4/S4p7FyMsy982TMEm2Vg56MN4yrDSZ/NnY4eb7g16dOXlIqaLkytJSAtylhD+f0NCD3rp0PoiBA2YeSwlmFyqSOCdzPnqFqqHEG2kMOgLpc5Qt4sID+cujIQn14H4zikyduihT10ivdmv/2jNVD7DvoJx4KiaOEt4FKUWls//TGUz9NgEDlqTeHqQQ2Yv0rlzzm0RwyTO3U1o2Ua0bVKCetAsptAsGK1gz0xMizhOGpc0olet/AR1eN6XmPixjL8KS12nCySGnBv/1ugXhSLdmifuToMBXMjYqLRIownN99NiVMT2DPVDo3Bwes4OKD5ZFVJskJZEJwlWoNzX25YZ/hDyXoiGuAUpJyyntFeGT7QsRv2XbfCy2bxxn6S6E4wtVcTgRDAHQvEiXOq3+qJFOfiae7DbStYJSUqAawJrt8p+50Agd1+r+fyBVbJ5xvD8G0xFVyHroJgM1YJQFwPCthsIrwXxtHQMuby5EXDHI8UcQ9yvb8D/AvytB/kT/F7k7E0OLEzM0BvQ+Pl3GBJJMOq1ydsWiZ+fb+KRUZf1tTTfY/mwDeRmMPkFAHobKy0sENh+GdwcB2z29RAeNS573pl5pq06ehVoqfQfY+aqs6XrAP2kFc=" 48 | # Ex. travis encrypt SONATYPE_PASSWORD=your_sonatype_password 49 | - secure: "kgaNRDKsM9uzerO7aSiuW2CNQq+0p2WDiQ5Iy5fCOl8sBOiA2em22aa0nj4/2PmGc22OvBMFeKtJy3D53oYl4cLBimGDFg+vYm1BI/TrdD2dKPpP1KqnetZWNIF7LLdezba+rnLt2R2SZ4uxxrMB+9+wOCBDCqAl0k7D1XMuKJBl3u9KPOPxcEgGXWnijoMxe8jkoRnl+hGN8GvIkb3EtrIl3GlSYwWjpTYZ9ojuLrXjlaJy4Q+098worb8gtQFRMpZDc7WLJFqy1ENNGt/9+S5P5sPpGJbfM6aVbyO8A2Yl6+iwdBumPPRMJbPmPWrbwFxSUhZqqMgBWl9Ok4AlzOHxM6rl752EU6IXCQFn+fZ+XLYLDBbB5IuYAKhT60oIUUnBpRJy7BnU71tI6Hf0aXYC1fQACZNal7he16GiehLaLrBQcLArJp/JwO7q6fuv6ovplL++cUddKhp5daZTHh8Uwi1Emi+nUISpEnhYuswWUHwyhl79bXm+fAbTOOKmNnQ+iw2t3pTqyNwQRnIJCznshQlILz9LO4siJGyX87SGzUEWnGsRU2ECQkLDKpCGCJMez8vTmZlTOUAKv12T6dVM9Eq7u/j023Mrx+EsLYgsgu4sV+R3IHpA0I4pTbFfstu7TEz55taTLSRerEYmnrAOp8zzfOnPRn8qxitLTro=" 50 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # OpenTracing Release Process 2 | 3 | This repo uses semantic versions. Please keep this in mind when choosing version numbers. 4 | 5 | For the up-to-date release process, please refer the 6 | [release process from the OpenTracing Java API](https://github.com/opentracing/opentracing-java/blob/master/RELEASE.md). -------------------------------------------------------------------------------- /header.txt: -------------------------------------------------------------------------------- 1 | Copyright ${project.inceptionYear} The OpenTracing Authors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 4 | in compliance with the License. You may obtain a copy of the License at 5 | 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | 8 | Unless required by applicable law or agreed to in writing, software distributed under the License 9 | is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 10 | or implied. See the License for the specific language governing permissions and limitations under 11 | the License. 12 | -------------------------------------------------------------------------------- /opentracing-redis-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-common 26 | 27 | 28 | 29 | com.github.kstyrc 30 | embedded-redis 31 | test 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/Action.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.common; 15 | 16 | @FunctionalInterface 17 | public interface Action { 18 | 19 | void execute(); 20 | } 21 | -------------------------------------------------------------------------------- /opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/RedisSpanNameProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package io.opentracing.contrib.redis.common; 16 | 17 | import java.util.function.Function; 18 | 19 | public class RedisSpanNameProvider { 20 | 21 | public static Function OPERATION_NAME = (operationName) -> 22 | ((operationName == null) ? "unknown" : operationName); 23 | 24 | 25 | public static Function PREFIX_OPERATION_NAME(final String prefix) { 26 | return (operationName) -> 27 | ((prefix == null) ? "" : prefix) 28 | + ((operationName == null) ? "unknown" : operationName); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/ThrowingAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.common; 15 | 16 | @FunctionalInterface 17 | public interface ThrowingAction { 18 | 19 | void execute() throws T; 20 | } 21 | -------------------------------------------------------------------------------- /opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/ThrowingSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.common; 15 | 16 | @FunctionalInterface 17 | public interface ThrowingSupplier { 18 | 19 | V get() throws T; 20 | } 21 | -------------------------------------------------------------------------------- /opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/TracingConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.common; 15 | 16 | import io.opentracing.Tracer; 17 | import java.util.Map; 18 | import java.util.concurrent.ConcurrentHashMap; 19 | import java.util.function.Function; 20 | 21 | public class TracingConfiguration { 22 | static final int DEFAULT_KEYS_MAX_LENGTH = 100; 23 | private final Tracer tracer; 24 | private final boolean traceWithActiveSpanOnly; 25 | private final int keysMaxLength; 26 | private final Function spanNameProvider; 27 | private final Map extensionTags; 28 | 29 | private TracingConfiguration(Tracer tracer, boolean traceWithActiveSpanOnly, int keysMaxLength, 30 | Function spanNameProvider, Map extensionTags) { 31 | this.tracer = tracer; 32 | this.traceWithActiveSpanOnly = traceWithActiveSpanOnly; 33 | this.keysMaxLength = keysMaxLength; 34 | this.spanNameProvider = spanNameProvider; 35 | this.extensionTags = extensionTags; 36 | } 37 | 38 | public Tracer getTracer() { 39 | return tracer; 40 | } 41 | 42 | public boolean isTraceWithActiveSpanOnly() { 43 | return traceWithActiveSpanOnly; 44 | } 45 | 46 | public int getKeysMaxLength() { 47 | return keysMaxLength; 48 | } 49 | 50 | public Function getSpanNameProvider() { 51 | return spanNameProvider; 52 | } 53 | 54 | public Map getExtensionTags() { 55 | return extensionTags; 56 | } 57 | 58 | public TracingConfiguration extensionTag(String key, String value) { 59 | this.extensionTags.putIfAbsent(key, value); 60 | return this; 61 | } 62 | 63 | public static class Builder { 64 | private final Tracer tracer; 65 | private boolean traceWithActiveSpanOnly; 66 | private int keysMaxLength = DEFAULT_KEYS_MAX_LENGTH; 67 | private Function spanNameProvider = RedisSpanNameProvider.OPERATION_NAME; 68 | private Map extensionTags = new ConcurrentHashMap<>(); 69 | 70 | public Builder(Tracer tracer) { 71 | this.tracer = tracer; 72 | } 73 | 74 | /** 75 | * @param traceWithActiveSpanOnly if true then create new spans only if there is an 76 | * active span 77 | */ 78 | public Builder traceWithActiveSpanOnly(boolean traceWithActiveSpanOnly) { 79 | this.traceWithActiveSpanOnly = traceWithActiveSpanOnly; 80 | return this; 81 | } 82 | 83 | /** 84 | * add tag 85 | * 86 | * @param key key 87 | * @param value value 88 | * @return this 89 | */ 90 | public Builder extensionTag(String key, String value) { 91 | this.extensionTags.putIfAbsent(key, value); 92 | return this; 93 | } 94 | 95 | /** 96 | * Customize the span name, default is operation name ({@link RedisSpanNameProvider#OPERATION_NAME}) 97 | * 98 | * @param spanNameProvider function to customize the span name 99 | */ 100 | public Builder withSpanNameProvider(Function spanNameProvider) { 101 | this.spanNameProvider = spanNameProvider; 102 | return this; 103 | } 104 | 105 | /** 106 | * Limit number of keys to add to span (default is 100) 107 | * 108 | * @param keysMaxLength max keys length to add to span 109 | */ 110 | public Builder withKeysMaxLength(int keysMaxLength) { 111 | this.keysMaxLength = keysMaxLength; 112 | return this; 113 | } 114 | 115 | public TracingConfiguration build() { 116 | if (spanNameProvider == null) { 117 | spanNameProvider = RedisSpanNameProvider.OPERATION_NAME; 118 | } 119 | if (keysMaxLength <= 0) { 120 | keysMaxLength = DEFAULT_KEYS_MAX_LENGTH; 121 | } 122 | return new TracingConfiguration(tracer, traceWithActiveSpanOnly, keysMaxLength, 123 | spanNameProvider, extensionTags); 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /opentracing-redis-common/src/test/java/io/opentracing/contrib/redis/common/RedisSpanNameProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package io.opentracing.contrib.redis.common; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import java.util.function.Function; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | 24 | public class RedisSpanNameProviderTest { 25 | 26 | private String prefix = "redis."; 27 | private String actual = ""; 28 | private Function prefixSpanName; 29 | 30 | @Before 31 | public void setUp() { 32 | prefixSpanName = RedisSpanNameProvider.PREFIX_OPERATION_NAME(prefix); 33 | } 34 | 35 | @Test 36 | public void testGetPrefix() { 37 | actual = prefixSpanName.apply("get"); 38 | assertEquals("redis.get", actual); 39 | } 40 | 41 | @Test 42 | public void testSetPrefix() { 43 | actual = prefixSpanName.apply("set"); 44 | assertEquals("redis.set", actual); 45 | } 46 | 47 | @Test 48 | public void testPersistPrefix() { 49 | actual = prefixSpanName.apply("persist"); 50 | assertEquals("redis.persist", actual); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /opentracing-redis-common/src/test/java/io/opentracing/contrib/redis/common/TracingConfigurationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.common; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertFalse; 18 | import static org.junit.Assert.assertNull; 19 | import static org.junit.Assert.assertSame; 20 | import static org.junit.Assert.assertTrue; 21 | 22 | import io.opentracing.Tracer; 23 | import io.opentracing.mock.MockTracer; 24 | import java.util.function.Function; 25 | import org.junit.Test; 26 | 27 | public class TracingConfigurationTest { 28 | 29 | @Test 30 | public void testDefaultValues() { 31 | Tracer tracer = new MockTracer(); 32 | TracingConfiguration configuration = new TracingConfiguration.Builder(tracer).build(); 33 | assertFalse(configuration.isTraceWithActiveSpanOnly()); 34 | assertEquals(TracingConfiguration.DEFAULT_KEYS_MAX_LENGTH, configuration.getKeysMaxLength()); 35 | assertSame(tracer, configuration.getTracer()); 36 | assertSame(RedisSpanNameProvider.OPERATION_NAME, configuration.getSpanNameProvider()); 37 | } 38 | 39 | @Test 40 | public void test() { 41 | Tracer tracer = new MockTracer(); 42 | Function spanNameProvider = RedisSpanNameProvider.PREFIX_OPERATION_NAME("test"); 43 | 44 | TracingConfiguration configuration = new TracingConfiguration.Builder(tracer) 45 | .withKeysMaxLength(10) 46 | .traceWithActiveSpanOnly(true) 47 | .withSpanNameProvider(spanNameProvider) 48 | .build(); 49 | 50 | assertTrue(configuration.isTraceWithActiveSpanOnly()); 51 | assertEquals(10, configuration.getKeysMaxLength()); 52 | assertSame(tracer, configuration.getTracer()); 53 | assertSame(spanNameProvider, configuration.getSpanNameProvider()); 54 | } 55 | 56 | @Test 57 | public void testWrongValues() { 58 | TracingConfiguration configuration = new TracingConfiguration.Builder(null) 59 | .withKeysMaxLength(-20) // will be reverted to TracingConfiguration.DEFAULT_KEYS_MAX_LENGTH 60 | .withSpanNameProvider(null) // will be reverted to RedisSpanNameProvider.OPERATION_NAME 61 | .build(); 62 | 63 | assertFalse(configuration.isTraceWithActiveSpanOnly()); 64 | assertEquals(TracingConfiguration.DEFAULT_KEYS_MAX_LENGTH, configuration.getKeysMaxLength()); 65 | assertNull(configuration.getTracer()); 66 | assertSame(RedisSpanNameProvider.OPERATION_NAME, configuration.getSpanNameProvider()); 67 | } 68 | } -------------------------------------------------------------------------------- /opentracing-redis-common/src/test/java/io/opentracing/contrib/redis/common/TracingHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | 15 | package io.opentracing.contrib.redis.common; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import io.opentracing.Tracer; 20 | import io.opentracing.mock.MockSpan; 21 | import io.opentracing.mock.MockTracer; 22 | import java.util.function.Function; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | 27 | public class TracingHelperTest { 28 | 29 | private Tracer mockTracer = new MockTracer(); 30 | private MockSpan span; 31 | private String prefix = "redis."; 32 | private Function prefixSpanName; 33 | private TracingHelper helperWithProvider; 34 | private TracingHelper helperWithoutProvider; 35 | 36 | @Before 37 | public void setUp() { 38 | prefixSpanName = RedisSpanNameProvider.PREFIX_OPERATION_NAME(prefix); 39 | helperWithProvider = new TracingHelper( 40 | new TracingConfiguration.Builder(mockTracer).withSpanNameProvider(prefixSpanName).build()); 41 | helperWithoutProvider = new TracingHelper(new TracingConfiguration.Builder(mockTracer).build()); 42 | } 43 | 44 | @Test 45 | public void testPrefix() { 46 | span = (MockSpan) (helperWithProvider.buildSpan("get")); 47 | assertEquals("redis.get", span.operationName()); 48 | } 49 | 50 | @Test 51 | public void testDefault() { 52 | span = (MockSpan) (helperWithoutProvider.buildSpan("get")); 53 | assertEquals("get", span.operationName()); 54 | } 55 | 56 | @Test 57 | public void limitKeys() { 58 | TracingHelper helper = new TracingHelper(new TracingConfiguration.Builder(mockTracer) 59 | .withKeysMaxLength(2).build()); 60 | Object[] keys = {"one", "two", "three"}; 61 | assertEquals(2, helper.limitKeys(keys).length); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /opentracing-redis-jedis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-jedis 26 | OpenTracing Instrumentation for Jedis 27 | OpenTracing Instrumentation for Jedis 28 | 29 | 30 | 31 | 32 | io.opentracing.contrib 33 | opentracing-redis-common 34 | ${project.version} 35 | 36 | 37 | 38 | redis.clients 39 | jedis 40 | 2.10.2 41 | provided 42 | 43 | 44 | 45 | com.github.kstyrc 46 | embedded-redis 47 | test 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /opentracing-redis-jedis/src/test/java/io/opentracing/contrib/redis/jedis/TracingJedisPoolTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.jedis; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertTrue; 18 | 19 | import io.opentracing.contrib.redis.common.TracingConfiguration; 20 | import io.opentracing.mock.MockSpan; 21 | import io.opentracing.mock.MockTracer; 22 | import java.util.List; 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import redis.clients.jedis.Jedis; 27 | import redis.clients.jedis.JedisPool; 28 | import redis.embedded.RedisServer; 29 | 30 | public class TracingJedisPoolTest { 31 | 32 | private MockTracer mockTracer = new MockTracer(); 33 | 34 | private RedisServer redisServer; 35 | 36 | @Before 37 | public void before() { 38 | mockTracer.reset(); 39 | 40 | redisServer = RedisServer.builder().setting("bind 127.0.0.1").build(); 41 | redisServer.start(); 42 | } 43 | 44 | @After 45 | public void after() { 46 | if (redisServer != null) { 47 | redisServer.stop(); 48 | } 49 | } 50 | 51 | @Test 52 | public void testPoolReturnsTracedJedis() { 53 | JedisPool pool = new TracingJedisPool(new TracingConfiguration.Builder(mockTracer).build()); 54 | 55 | Jedis jedis = pool.getResource(); 56 | assertEquals("OK", jedis.set("key", "value")); 57 | assertEquals("value", jedis.get("key")); 58 | 59 | jedis.close(); 60 | 61 | List spans = mockTracer.finishedSpans(); 62 | assertEquals(2, spans.size()); 63 | } 64 | 65 | @Test 66 | public void testClosingTracedJedisClosesUnderlyingJedis() { 67 | JedisPool pool = new TracingJedisPool(new TracingConfiguration.Builder(mockTracer).build()); 68 | Jedis resource = pool.getResource(); 69 | assertEquals(1, pool.getNumActive()); 70 | 71 | resource.close(); 72 | assertEquals(0, pool.getNumActive()); 73 | assertEquals(1, pool.getNumIdle()); 74 | 75 | // ensure that resource is reused 76 | Jedis nextResource = pool.getResource(); 77 | assertEquals(1, pool.getNumActive()); 78 | assertEquals(0, pool.getNumIdle()); 79 | nextResource.close(); 80 | } 81 | 82 | @Test 83 | public void shouldReturnResourceToThePoolAndStayConnected() { 84 | //given 85 | TracingJedisPool pool = new TracingJedisPool( 86 | new TracingConfiguration.Builder(mockTracer).build()); 87 | Jedis resource = pool.getResource(); 88 | assertTrue(resource.isConnected()); 89 | 90 | //when 91 | pool.returnResource(resource); 92 | 93 | //then 94 | assertTrue(resource.isConnected()); 95 | } 96 | 97 | @Test 98 | public void shouldReturnResourceToThePoolOnCloseAndStayConnected() { 99 | //given 100 | JedisPool pool = new TracingJedisPool(new TracingConfiguration.Builder(mockTracer).build()); 101 | Jedis resource = pool.getResource(); 102 | assertTrue(resource.isConnected()); 103 | 104 | //when 105 | resource.close(); 106 | 107 | //then - valid resource should not be destroyed but returned to pool & stay connected for at least {@link BaseGenericObjectPool#getMinEvictableIdleTimeMillis()} 108 | assertTrue(resource.isConnected()); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /opentracing-redis-jedis/src/test/java/io/opentracing/contrib/redis/jedis/TracingJedisSentinelPoolTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.jedis; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import io.opentracing.contrib.redis.common.TracingConfiguration; 19 | import io.opentracing.mock.MockSpan; 20 | import io.opentracing.mock.MockTracer; 21 | import io.opentracing.util.ThreadLocalScopeManager; 22 | import java.util.HashSet; 23 | import java.util.List; 24 | import java.util.Set; 25 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | import redis.clients.jedis.Jedis; 30 | import redis.clients.jedis.JedisSentinelPool; 31 | import redis.clients.jedis.Protocol; 32 | import redis.embedded.RedisSentinel; 33 | import redis.embedded.RedisServer; 34 | 35 | public class TracingJedisSentinelPoolTest { 36 | 37 | private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(), 38 | MockTracer.Propagator.TEXT_MAP); 39 | 40 | private RedisServer redisServer; 41 | 42 | private RedisSentinel redisSentinel; 43 | 44 | private static final String MASTER_NAME = "mymaster"; 45 | 46 | private Set sentinels = new HashSet() {{ 47 | add("127.0.0.1:" + (Protocol.DEFAULT_PORT + 1)); 48 | }}; 49 | 50 | @Before 51 | public void before() { 52 | mockTracer.reset(); 53 | 54 | redisServer = RedisServer.builder().build(); 55 | redisServer.start(); 56 | redisSentinel = RedisSentinel.builder().port(Protocol.DEFAULT_PORT + 1).build(); 57 | redisSentinel.start(); 58 | } 59 | 60 | @After 61 | public void after() { 62 | if (redisSentinel != null) { 63 | redisSentinel.stop(); 64 | } 65 | if (redisServer != null) { 66 | redisServer.stop(); 67 | } 68 | } 69 | 70 | @Test 71 | public void testSentinelPoolReturnsTracedJedis() { 72 | JedisSentinelPool pool = new TracingJedisSentinelPool( 73 | new TracingConfiguration.Builder(mockTracer).build(), MASTER_NAME, sentinels, 74 | new GenericObjectPoolConfig()); 75 | Jedis jedis = pool.getResource(); 76 | assertEquals("OK", jedis.set("key", "value")); 77 | assertEquals("value", jedis.get("key")); 78 | 79 | jedis.close(); 80 | pool.destroy(); 81 | 82 | List spans = mockTracer.finishedSpans(); 83 | assertEquals(2, spans.size()); 84 | } 85 | 86 | @Test 87 | public void testClosingTracedJedisClosesUnderlyingJedis() { 88 | JedisSentinelPool pool = new TracingJedisSentinelPool( 89 | new TracingConfiguration.Builder(mockTracer).build(), MASTER_NAME, sentinels, 90 | new GenericObjectPoolConfig()); 91 | Jedis resource = pool.getResource(); 92 | assertEquals(1, pool.getNumActive()); 93 | 94 | resource.close(); 95 | assertEquals(0, pool.getNumActive()); 96 | assertEquals(1, pool.getNumIdle()); 97 | 98 | // ensure that resource is reused 99 | Jedis nextResource = pool.getResource(); 100 | assertEquals(1, pool.getNumActive()); 101 | assertEquals(0, pool.getNumIdle()); 102 | nextResource.close(); 103 | 104 | pool.destroy(); 105 | } 106 | } -------------------------------------------------------------------------------- /opentracing-redis-jedis/src/test/java/io/opentracing/contrib/redis/jedis/TracingJedisTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.jedis; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import io.opentracing.contrib.redis.common.TracingConfiguration; 19 | import io.opentracing.mock.MockSpan; 20 | import io.opentracing.mock.MockTracer; 21 | import io.opentracing.util.ThreadLocalScopeManager; 22 | import java.util.List; 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import redis.clients.jedis.Jedis; 27 | import redis.embedded.RedisServer; 28 | 29 | public class TracingJedisTest { 30 | 31 | private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(), 32 | MockTracer.Propagator.TEXT_MAP); 33 | 34 | private RedisServer redisServer; 35 | 36 | @Before 37 | public void before() throws Exception { 38 | mockTracer.reset(); 39 | 40 | redisServer = RedisServer.builder().setting("bind 127.0.0.1").build(); 41 | redisServer.start(); 42 | } 43 | 44 | @After 45 | public void after() { 46 | if (redisServer != null) { 47 | redisServer.stop(); 48 | } 49 | } 50 | 51 | @Test 52 | public void test() { 53 | Jedis jedis = new TracingJedis(new TracingConfiguration.Builder(mockTracer).build()); 54 | 55 | assertEquals("OK", jedis.set("key", "value")); 56 | assertEquals("value", jedis.get("key")); 57 | 58 | jedis.close(); 59 | 60 | List spans = mockTracer.finishedSpans(); 61 | assertEquals(2, spans.size()); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /opentracing-redis-jedis3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-jedis3 26 | OpenTracing Instrumentation for Jedis 3 27 | OpenTracing Instrumentation for Jedis 3 28 | 29 | 30 | 31 | 32 | io.opentracing.contrib 33 | opentracing-redis-common 34 | ${project.version} 35 | 36 | 37 | 38 | redis.clients 39 | jedis 40 | 3.6.1 41 | provided 42 | 43 | 44 | 45 | com.github.kstyrc 46 | embedded-redis 47 | test 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /opentracing-redis-jedis3/src/test/java/io.opentracing.contrib.redis.jedis3/TracingJedisPoolTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.jedis3; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertTrue; 18 | 19 | import io.opentracing.contrib.redis.common.TracingConfiguration; 20 | import io.opentracing.mock.MockSpan; 21 | import io.opentracing.mock.MockTracer; 22 | import io.opentracing.util.ThreadLocalScopeManager; 23 | import java.util.List; 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import redis.clients.jedis.Jedis; 28 | import redis.clients.jedis.JedisPool; 29 | import redis.embedded.RedisServer; 30 | 31 | public class TracingJedisPoolTest { 32 | 33 | private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(), 34 | MockTracer.Propagator.TEXT_MAP); 35 | 36 | private RedisServer redisServer; 37 | 38 | @Before 39 | public void before() { 40 | mockTracer.reset(); 41 | 42 | redisServer = RedisServer.builder().setting("bind 127.0.0.1").build(); 43 | redisServer.start(); 44 | } 45 | 46 | @After 47 | public void after() { 48 | if (redisServer != null) { 49 | redisServer.stop(); 50 | } 51 | } 52 | 53 | @Test 54 | public void testPoolReturnsTracedJedis() { 55 | JedisPool pool = new TracingJedisPool(new TracingConfiguration.Builder(mockTracer).build()); 56 | 57 | Jedis jedis = pool.getResource(); 58 | assertEquals("OK", jedis.set("key", "value")); 59 | assertEquals("value", jedis.get("key")); 60 | 61 | jedis.close(); 62 | 63 | List spans = mockTracer.finishedSpans(); 64 | assertEquals(2, spans.size()); 65 | } 66 | 67 | @Test 68 | public void testClosingTracedJedisClosesUnderlyingJedis() { 69 | JedisPool pool = new TracingJedisPool(new TracingConfiguration.Builder(mockTracer).build()); 70 | Jedis resource = pool.getResource(); 71 | assertEquals(1, pool.getNumActive()); 72 | 73 | resource.close(); 74 | assertEquals(0, pool.getNumActive()); 75 | assertEquals(1, pool.getNumIdle()); 76 | 77 | // ensure that resource is reused 78 | Jedis nextResource = pool.getResource(); 79 | assertEquals(1, pool.getNumActive()); 80 | assertEquals(0, pool.getNumIdle()); 81 | nextResource.close(); 82 | } 83 | 84 | @Test 85 | public void shouldReturnResourceToThePoolAndStayConnected() { 86 | //given 87 | TracingJedisPool pool = new TracingJedisPool( 88 | new TracingConfiguration.Builder(mockTracer).build()); 89 | Jedis resource = pool.getResource(); 90 | assertTrue(resource.isConnected()); 91 | 92 | //when 93 | pool.returnResource(resource); 94 | 95 | //then 96 | assertTrue(resource.isConnected()); 97 | } 98 | 99 | @Test 100 | public void shouldReturnResourceToThePoolOnCloseAndStayConnected() { 101 | //given 102 | JedisPool pool = new TracingJedisPool(new TracingConfiguration.Builder(mockTracer).build()); 103 | Jedis resource = pool.getResource(); 104 | assertTrue(resource.isConnected()); 105 | 106 | //when 107 | resource.close(); 108 | 109 | //then - valid resource should not be destroyed but returned to pool & stay connected for at least {@link BaseGenericObjectPool#getMinEvictableIdleTimeMillis()} 110 | assertTrue(resource.isConnected()); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /opentracing-redis-jedis3/src/test/java/io.opentracing.contrib.redis.jedis3/TracingJedisSentinelPoolTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.jedis3; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import io.opentracing.contrib.redis.common.TracingConfiguration; 19 | import io.opentracing.mock.MockSpan; 20 | import io.opentracing.mock.MockTracer; 21 | import io.opentracing.util.ThreadLocalScopeManager; 22 | import java.util.HashSet; 23 | import java.util.List; 24 | import java.util.Set; 25 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig; 26 | import org.junit.After; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | import redis.clients.jedis.Jedis; 30 | import redis.clients.jedis.JedisSentinelPool; 31 | import redis.clients.jedis.Protocol; 32 | import redis.embedded.RedisSentinel; 33 | import redis.embedded.RedisServer; 34 | 35 | public class TracingJedisSentinelPoolTest { 36 | 37 | private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(), 38 | MockTracer.Propagator.TEXT_MAP); 39 | 40 | private RedisServer redisServer; 41 | 42 | private RedisSentinel redisSentinel; 43 | 44 | private static final String MASTER_NAME = "mymaster"; 45 | 46 | private Set sentinels = new HashSet() {{ 47 | add("127.0.0.1:" + (Protocol.DEFAULT_PORT + 1)); 48 | }}; 49 | 50 | @Before 51 | public void before() { 52 | mockTracer.reset(); 53 | 54 | redisServer = RedisServer.builder().build(); 55 | redisServer.start(); 56 | redisSentinel = RedisSentinel.builder().port(Protocol.DEFAULT_PORT + 1).build(); 57 | redisSentinel.start(); 58 | } 59 | 60 | @After 61 | public void after() { 62 | if (redisSentinel != null) { 63 | redisSentinel.stop(); 64 | } 65 | if (redisServer != null) { 66 | redisServer.stop(); 67 | } 68 | } 69 | 70 | @Test 71 | public void testSentinelPoolReturnsTracedJedis() { 72 | JedisSentinelPool pool = new TracingJedisSentinelPool( 73 | new TracingConfiguration.Builder(mockTracer).build(), MASTER_NAME, sentinels, 74 | new GenericObjectPoolConfig()); 75 | Jedis jedis = pool.getResource(); 76 | assertEquals("OK", jedis.set("key", "value")); 77 | assertEquals("value", jedis.get("key")); 78 | 79 | jedis.close(); 80 | pool.destroy(); 81 | 82 | List spans = mockTracer.finishedSpans(); 83 | assertEquals(2, spans.size()); 84 | } 85 | 86 | @Test 87 | public void testClosingTracedJedisClosesUnderlyingJedis() { 88 | JedisSentinelPool pool = new TracingJedisSentinelPool( 89 | new TracingConfiguration.Builder(mockTracer).build(), MASTER_NAME, sentinels, 90 | new GenericObjectPoolConfig()); 91 | Jedis resource = pool.getResource(); 92 | assertEquals(1, pool.getNumActive()); 93 | 94 | resource.close(); 95 | assertEquals(0, pool.getNumActive()); 96 | assertEquals(1, pool.getNumIdle()); 97 | 98 | // ensure that resource is reused 99 | Jedis nextResource = pool.getResource(); 100 | assertEquals(1, pool.getNumActive()); 101 | assertEquals(0, pool.getNumIdle()); 102 | nextResource.close(); 103 | 104 | pool.destroy(); 105 | } 106 | } -------------------------------------------------------------------------------- /opentracing-redis-jedis3/src/test/java/io.opentracing.contrib.redis.jedis3/TracingJedisTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.jedis3; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import io.opentracing.contrib.redis.common.TracingConfiguration; 19 | import io.opentracing.mock.MockSpan; 20 | import io.opentracing.mock.MockTracer; 21 | import io.opentracing.util.ThreadLocalScopeManager; 22 | import java.util.List; 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import redis.clients.jedis.Jedis; 27 | import redis.embedded.RedisServer; 28 | 29 | public class TracingJedisTest { 30 | 31 | private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(), 32 | MockTracer.Propagator.TEXT_MAP); 33 | 34 | private RedisServer redisServer; 35 | 36 | @Before 37 | public void before() throws Exception { 38 | mockTracer.reset(); 39 | 40 | redisServer = RedisServer.builder().setting("bind 127.0.0.1").build(); 41 | redisServer.start(); 42 | } 43 | 44 | @After 45 | public void after() { 46 | if (redisServer != null) { 47 | redisServer.stop(); 48 | } 49 | } 50 | 51 | @Test 52 | public void test() { 53 | Jedis jedis = new TracingJedis(new TracingConfiguration.Builder(mockTracer).build()); 54 | 55 | assertEquals("OK", jedis.set("key", "value")); 56 | assertEquals("value", jedis.get("key")); 57 | 58 | jedis.close(); 59 | 60 | List spans = mockTracer.finishedSpans(); 61 | assertEquals(2, spans.size()); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.0/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-lettuce-5.0 26 | OpenTracing Instrumentation for Lettuce 5.0 Redis Client 27 | OpenTracing Instrumentation for Lettuce 5.0 Redis Client 28 | 29 | 30 | 31 | 32 | io.opentracing.contrib 33 | opentracing-redis-common 34 | ${project.version} 35 | 36 | 37 | 38 | io.lettuce 39 | lettuce-core 40 | 5.0.5.RELEASE 41 | provided 42 | 43 | 44 | 45 | com.github.kstyrc 46 | embedded-redis 47 | test 48 | 49 | 50 | 51 | org.awaitility 52 | awaitility 53 | test 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.0/src/main/java/io/opentracing/contrib/redis/lettuce50/CompletableRedisFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce50; 15 | 16 | import io.lettuce.core.RedisFuture; 17 | import java.util.concurrent.CompletableFuture; 18 | import java.util.concurrent.TimeUnit; 19 | 20 | public class CompletableRedisFuture extends CompletableFuture implements RedisFuture { 21 | 22 | private RedisFuture wrappedFuture; 23 | 24 | public CompletableRedisFuture(RedisFuture wrappedFuture) { 25 | this.wrappedFuture = wrappedFuture; 26 | } 27 | 28 | @Override 29 | public String getError() { 30 | return wrappedFuture.getError(); 31 | } 32 | 33 | @Override 34 | public boolean await(long timeout, TimeUnit unit) throws InterruptedException { 35 | return wrappedFuture.await(timeout, unit); 36 | } 37 | } -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.0/src/main/java/io/opentracing/contrib/redis/lettuce50/TracingRedisPubSubAsyncCommands.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce50; 15 | 16 | import io.lettuce.core.RedisFuture; 17 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 18 | import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; 19 | import io.opentracing.Span; 20 | import io.opentracing.contrib.redis.common.TracingConfiguration; 21 | import java.util.Arrays; 22 | 23 | public class TracingRedisPubSubAsyncCommands extends 24 | TracingRedisAsyncCommands implements RedisPubSubAsyncCommands { 25 | private final RedisPubSubAsyncCommands commands; 26 | 27 | public TracingRedisPubSubAsyncCommands( 28 | RedisPubSubAsyncCommands commands, 29 | TracingConfiguration tracingConfiguration) { 30 | super(commands, tracingConfiguration); 31 | this.commands = commands; 32 | } 33 | 34 | @Override 35 | public RedisFuture psubscribe(K... patterns) { 36 | final Span span = helper.buildSpan("psubscribe"); 37 | span.setTag("patterns", Arrays.toString(patterns)); 38 | return prepareRedisFuture(commands.psubscribe(patterns), span); 39 | } 40 | 41 | @Override 42 | public RedisFuture punsubscribe(K... patterns) { 43 | final Span span = helper.buildSpan("punsubscribe"); 44 | span.setTag("patterns", Arrays.toString(patterns)); 45 | return prepareRedisFuture(commands.punsubscribe(patterns), span); 46 | } 47 | 48 | @Override 49 | public RedisFuture subscribe(K... channels) { 50 | final Span span = helper.buildSpan("subscribe"); 51 | span.setTag("channels", Arrays.toString(channels)); 52 | return prepareRedisFuture(commands.subscribe(channels), span); 53 | } 54 | 55 | @Override 56 | public RedisFuture unsubscribe(K... channels) { 57 | final Span span = helper.buildSpan("unsubscribe"); 58 | span.setTag("channels", Arrays.toString(channels)); 59 | return prepareRedisFuture(commands.unsubscribe(channels), span); 60 | } 61 | 62 | @Override 63 | public StatefulRedisPubSubConnection getStatefulConnection() { 64 | return new TracingStatefulRedisPubSubConnection<>(commands.getStatefulConnection(), 65 | tracingConfiguration); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.0/src/main/java/io/opentracing/contrib/redis/lettuce50/TracingRedisPubSubCommands.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce50; 15 | 16 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 17 | import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; 18 | import io.opentracing.Span; 19 | import io.opentracing.contrib.redis.common.TracingConfiguration; 20 | import java.util.Arrays; 21 | 22 | public class TracingRedisPubSubCommands extends TracingRedisCommands implements 23 | RedisPubSubCommands { 24 | private final RedisPubSubCommands commands; 25 | 26 | public TracingRedisPubSubCommands(RedisPubSubCommands commands, 27 | TracingConfiguration tracingConfiguration) { 28 | super(commands, tracingConfiguration); 29 | this.commands = commands; 30 | } 31 | 32 | @Override 33 | public void psubscribe(K... patterns) { 34 | final Span span = helper.buildSpan("psubscribe"); 35 | span.setTag("patterns", Arrays.toString(patterns)); 36 | helper.decorate(span, () -> commands.psubscribe(patterns)); 37 | } 38 | 39 | @Override 40 | public void punsubscribe(K... patterns) { 41 | final Span span = helper.buildSpan("punsubscribe"); 42 | span.setTag("patterns", Arrays.toString(patterns)); 43 | helper.decorate(span, () -> commands.punsubscribe(patterns)); 44 | } 45 | 46 | @Override 47 | public void subscribe(K... channels) { 48 | final Span span = helper.buildSpan("subscribe"); 49 | span.setTag("channels", Arrays.toString(channels)); 50 | helper.decorate(span, () -> commands.subscribe(channels)); 51 | } 52 | 53 | @Override 54 | public void unsubscribe(K... channels) { 55 | final Span span = helper.buildSpan("unsubscribe"); 56 | span.setTag("channels", Arrays.toString(channels)); 57 | helper.decorate(span, () -> commands.unsubscribe(channels)); 58 | } 59 | 60 | @Override 61 | public StatefulRedisPubSubConnection getStatefulConnection() { 62 | return new TracingStatefulRedisPubSubConnection<>(commands.getStatefulConnection(), 63 | tracingConfiguration); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.0/src/main/java/io/opentracing/contrib/redis/lettuce50/TracingRedisPubSubListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce50; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.lettuce.core.pubsub.RedisPubSubListener; 19 | import io.opentracing.Span; 20 | import io.opentracing.contrib.redis.common.TracingConfiguration; 21 | import io.opentracing.contrib.redis.common.TracingHelper; 22 | 23 | public class TracingRedisPubSubListener implements RedisPubSubListener { 24 | 25 | private final RedisPubSubListener listener; 26 | private final TracingHelper helper; 27 | 28 | public TracingRedisPubSubListener(RedisPubSubListener listener, 29 | TracingConfiguration tracingConfiguration) { 30 | this.listener = listener; 31 | this.helper = new TracingHelper(tracingConfiguration); 32 | } 33 | 34 | @Override 35 | public void message(K channel, V message) { 36 | final Span span = helper.buildSpan("message"); 37 | span.setTag("channel", nullable(channel)); 38 | span.setTag("message", nullable(message)); 39 | helper.decorate(span, () -> listener.message(channel, message)); 40 | } 41 | 42 | @Override 43 | public void message(K pattern, K channel, V message) { 44 | final Span span = helper.buildSpan("message"); 45 | span.setTag("pattern", nullable(pattern)); 46 | span.setTag("channel", nullable(channel)); 47 | span.setTag("message", nullable(message)); 48 | helper.decorate(span, () -> listener.message(pattern, channel, message)); 49 | } 50 | 51 | @Override 52 | public void subscribed(K channel, long count) { 53 | final Span span = helper.buildSpan("subscribed"); 54 | span.setTag("channel", nullable(channel)); 55 | span.setTag("count", count); 56 | helper.decorate(span, () -> listener.subscribed(channel, count)); 57 | } 58 | 59 | @Override 60 | public void psubscribed(K pattern, long count) { 61 | final Span span = helper.buildSpan("psubscribed"); 62 | span.setTag("pattern", nullable(pattern)); 63 | span.setTag("count", count); 64 | helper.decorate(span, () -> listener.psubscribed(pattern, count)); 65 | } 66 | 67 | @Override 68 | public void unsubscribed(K channel, long count) { 69 | final Span span = helper.buildSpan("unsubscribed"); 70 | span.setTag("channel", nullable(channel)); 71 | span.setTag("count", count); 72 | helper.decorate(span, () -> listener.unsubscribed(channel, count)); 73 | } 74 | 75 | @Override 76 | public void punsubscribed(K pattern, long count) { 77 | final Span span = helper.buildSpan("punsubscribed"); 78 | span.setTag("pattern", nullable(pattern)); 79 | span.setTag("count", count); 80 | helper.decorate(span, () -> listener.punsubscribed(pattern, count)); 81 | } 82 | 83 | @Override 84 | public boolean equals(Object obj) { 85 | return listener.equals(obj); 86 | } 87 | 88 | @Override 89 | public int hashCode() { 90 | return listener.hashCode(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.0/src/main/java/io/opentracing/contrib/redis/lettuce50/TracingStatefulRedisConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce50; 15 | 16 | import io.lettuce.core.ClientOptions; 17 | import io.lettuce.core.api.StatefulRedisConnection; 18 | import io.lettuce.core.api.async.RedisAsyncCommands; 19 | import io.lettuce.core.api.reactive.RedisReactiveCommands; 20 | import io.lettuce.core.api.sync.RedisCommands; 21 | import io.lettuce.core.protocol.RedisCommand; 22 | import io.opentracing.contrib.redis.common.TracingConfiguration; 23 | import java.time.Duration; 24 | import java.util.Collection; 25 | import java.util.concurrent.TimeUnit; 26 | 27 | public class TracingStatefulRedisConnection implements StatefulRedisConnection { 28 | 29 | private final StatefulRedisConnection connection; 30 | final TracingConfiguration tracingConfiguration; 31 | 32 | /** 33 | * @param connection redis connection 34 | * @param tracingConfiguration tracing configuration 35 | */ 36 | public TracingStatefulRedisConnection(StatefulRedisConnection connection, 37 | TracingConfiguration tracingConfiguration) { 38 | this.connection = connection; 39 | this.tracingConfiguration = tracingConfiguration; 40 | } 41 | 42 | @Override 43 | public boolean isMulti() { 44 | return connection.isMulti(); 45 | } 46 | 47 | @Override 48 | public RedisCommands sync() { 49 | return new TracingRedisCommands<>(connection.sync(), tracingConfiguration); 50 | } 51 | 52 | @Override 53 | public RedisAsyncCommands async() { 54 | return new TracingRedisAsyncCommands<>(connection.async(), tracingConfiguration); 55 | } 56 | 57 | @Override 58 | public RedisReactiveCommands reactive() { 59 | return connection.reactive(); 60 | } 61 | 62 | @Override 63 | public void setTimeout(Duration timeout) { 64 | connection.setTimeout(timeout); 65 | } 66 | 67 | @Override 68 | @Deprecated 69 | public void setTimeout(long timeout, TimeUnit unit) { 70 | connection.setTimeout(timeout, unit); 71 | } 72 | 73 | @Override 74 | public Duration getTimeout() { 75 | return connection.getTimeout(); 76 | } 77 | 78 | @Override 79 | public RedisCommand dispatch( 80 | RedisCommand command) { 81 | return connection.dispatch(command); 82 | } 83 | 84 | @Override 85 | public Collection> dispatch( 86 | Collection> redisCommands) { 87 | return connection.dispatch(redisCommands); 88 | } 89 | 90 | @Override 91 | public void close() { 92 | connection.close(); 93 | } 94 | 95 | @Override 96 | public boolean isOpen() { 97 | return connection.isOpen(); 98 | } 99 | 100 | @Override 101 | public ClientOptions getOptions() { 102 | return connection.getOptions(); 103 | } 104 | 105 | @Override 106 | public void reset() { 107 | connection.reset(); 108 | } 109 | 110 | @Override 111 | public void setAutoFlushCommands(boolean autoFlush) { 112 | connection.setAutoFlushCommands(autoFlush); 113 | } 114 | 115 | @Override 116 | public void flushCommands() { 117 | connection.flushCommands(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.0/src/main/java/io/opentracing/contrib/redis/lettuce50/TracingStatefulRedisPubSubConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce50; 15 | 16 | import io.lettuce.core.pubsub.RedisPubSubListener; 17 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 18 | import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; 19 | import io.lettuce.core.pubsub.api.reactive.RedisPubSubReactiveCommands; 20 | import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; 21 | import io.opentracing.contrib.redis.common.TracingConfiguration; 22 | 23 | public class TracingStatefulRedisPubSubConnection extends 24 | TracingStatefulRedisConnection implements 25 | StatefulRedisPubSubConnection { 26 | 27 | private final StatefulRedisPubSubConnection connection; 28 | 29 | public TracingStatefulRedisPubSubConnection( 30 | StatefulRedisPubSubConnection connection, 31 | TracingConfiguration tracingConfiguration) { 32 | super(connection, tracingConfiguration); 33 | this.connection = connection; 34 | } 35 | 36 | @Override 37 | public RedisPubSubCommands sync() { 38 | return new TracingRedisPubSubCommands<>(connection.sync(), tracingConfiguration); 39 | } 40 | 41 | @Override 42 | public RedisPubSubAsyncCommands async() { 43 | return new TracingRedisPubSubAsyncCommands<>(connection.async(), tracingConfiguration); 44 | } 45 | 46 | @Override 47 | public RedisPubSubReactiveCommands reactive() { 48 | return connection.reactive(); 49 | } 50 | 51 | @Override 52 | public void addListener(RedisPubSubListener listener) { 53 | connection.addListener(new TracingRedisPubSubListener<>(listener, tracingConfiguration)); 54 | } 55 | 56 | @Override 57 | public void removeListener(RedisPubSubListener listener) { 58 | connection.removeListener(listener); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-lettuce-5.1 26 | OpenTracing Instrumentation for Lettuce 5.1 Redis Client 27 | OpenTracing Instrumentation for Lettuce 5.1 Redis Client 28 | 29 | 30 | 31 | 32 | io.opentracing.contrib 33 | opentracing-redis-common 34 | ${project.version} 35 | 36 | 37 | 38 | io.lettuce 39 | lettuce-core 40 | 5.1.8.RELEASE 41 | provided 42 | 43 | 44 | 45 | com.github.kstyrc 46 | embedded-redis 47 | test 48 | 49 | 50 | 51 | org.awaitility 52 | awaitility 53 | test 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.1/src/main/java/io/opentracing/contrib/redis/lettuce51/CompletableRedisFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce51; 15 | 16 | import io.lettuce.core.RedisFuture; 17 | import java.util.concurrent.CompletableFuture; 18 | import java.util.concurrent.TimeUnit; 19 | 20 | public class CompletableRedisFuture extends CompletableFuture implements RedisFuture { 21 | 22 | private RedisFuture wrappedFuture; 23 | 24 | public CompletableRedisFuture(RedisFuture wrappedFuture) { 25 | this.wrappedFuture = wrappedFuture; 26 | } 27 | 28 | @Override 29 | public String getError() { 30 | return wrappedFuture.getError(); 31 | } 32 | 33 | @Override 34 | public boolean await(long timeout, TimeUnit unit) throws InterruptedException { 35 | return wrappedFuture.await(timeout, unit); 36 | } 37 | } -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.1/src/main/java/io/opentracing/contrib/redis/lettuce51/TracingRedisPubSubAsyncCommands.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce51; 15 | 16 | import io.lettuce.core.RedisFuture; 17 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 18 | import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; 19 | import io.opentracing.Span; 20 | import io.opentracing.contrib.redis.common.TracingConfiguration; 21 | import java.util.Arrays; 22 | 23 | public class TracingRedisPubSubAsyncCommands extends 24 | TracingRedisAsyncCommands implements RedisPubSubAsyncCommands { 25 | private final RedisPubSubAsyncCommands commands; 26 | 27 | public TracingRedisPubSubAsyncCommands( 28 | RedisPubSubAsyncCommands commands, 29 | TracingConfiguration tracingConfiguration) { 30 | super(commands, tracingConfiguration); 31 | this.commands = commands; 32 | } 33 | 34 | @Override 35 | public RedisFuture psubscribe(K... patterns) { 36 | final Span span = helper.buildSpan("psubscribe"); 37 | span.setTag("patterns", Arrays.toString(patterns)); 38 | return prepareRedisFuture(commands.psubscribe(patterns), span); 39 | } 40 | 41 | @Override 42 | public RedisFuture punsubscribe(K... patterns) { 43 | final Span span = helper.buildSpan("punsubscribe"); 44 | span.setTag("patterns", Arrays.toString(patterns)); 45 | return prepareRedisFuture(commands.punsubscribe(patterns), span); 46 | } 47 | 48 | @Override 49 | public RedisFuture subscribe(K... channels) { 50 | final Span span = helper.buildSpan("subscribe"); 51 | span.setTag("channels", Arrays.toString(channels)); 52 | return prepareRedisFuture(commands.subscribe(channels), span); 53 | } 54 | 55 | @Override 56 | public RedisFuture unsubscribe(K... channels) { 57 | final Span span = helper.buildSpan("unsubscribe"); 58 | span.setTag("channels", Arrays.toString(channels)); 59 | return prepareRedisFuture(commands.unsubscribe(channels), span); 60 | } 61 | 62 | @Override 63 | public StatefulRedisPubSubConnection getStatefulConnection() { 64 | return new TracingStatefulRedisPubSubConnection<>(commands.getStatefulConnection(), 65 | tracingConfiguration); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.1/src/main/java/io/opentracing/contrib/redis/lettuce51/TracingRedisPubSubCommands.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce51; 15 | 16 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 17 | import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; 18 | import io.opentracing.Span; 19 | import io.opentracing.contrib.redis.common.TracingConfiguration; 20 | import java.util.Arrays; 21 | 22 | public class TracingRedisPubSubCommands extends TracingRedisCommands implements 23 | RedisPubSubCommands { 24 | private final RedisPubSubCommands commands; 25 | 26 | public TracingRedisPubSubCommands(RedisPubSubCommands commands, 27 | TracingConfiguration tracingConfiguration) { 28 | super(commands, tracingConfiguration); 29 | this.commands = commands; 30 | } 31 | 32 | @Override 33 | public void psubscribe(K... patterns) { 34 | final Span span = helper.buildSpan("psubscribe"); 35 | span.setTag("patterns", Arrays.toString(patterns)); 36 | helper.decorate(span, () -> commands.psubscribe(patterns)); 37 | } 38 | 39 | @Override 40 | public void punsubscribe(K... patterns) { 41 | final Span span = helper.buildSpan("punsubscribe"); 42 | span.setTag("patterns", Arrays.toString(patterns)); 43 | helper.decorate(span, () -> commands.punsubscribe(patterns)); 44 | } 45 | 46 | @Override 47 | public void subscribe(K... channels) { 48 | final Span span = helper.buildSpan("subscribe"); 49 | span.setTag("channels", Arrays.toString(channels)); 50 | helper.decorate(span, () -> commands.subscribe(channels)); 51 | } 52 | 53 | @Override 54 | public void unsubscribe(K... channels) { 55 | final Span span = helper.buildSpan("unsubscribe"); 56 | span.setTag("channels", Arrays.toString(channels)); 57 | helper.decorate(span, () -> commands.unsubscribe(channels)); 58 | } 59 | 60 | @Override 61 | public StatefulRedisPubSubConnection getStatefulConnection() { 62 | return new TracingStatefulRedisPubSubConnection<>(commands.getStatefulConnection(), 63 | tracingConfiguration); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.1/src/main/java/io/opentracing/contrib/redis/lettuce51/TracingRedisPubSubListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce51; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.lettuce.core.pubsub.RedisPubSubListener; 19 | import io.opentracing.Span; 20 | import io.opentracing.contrib.redis.common.TracingConfiguration; 21 | import io.opentracing.contrib.redis.common.TracingHelper; 22 | 23 | public class TracingRedisPubSubListener implements RedisPubSubListener { 24 | 25 | private final RedisPubSubListener listener; 26 | private final TracingHelper helper; 27 | 28 | public TracingRedisPubSubListener(RedisPubSubListener listener, 29 | TracingConfiguration tracingConfiguration) { 30 | this.listener = listener; 31 | this.helper = new TracingHelper(tracingConfiguration); 32 | } 33 | 34 | @Override 35 | public void message(K channel, V message) { 36 | final Span span = helper.buildSpan("message"); 37 | span.setTag("channel", nullable(channel)); 38 | span.setTag("message", nullable(message)); 39 | helper.decorate(span, () -> listener.message(channel, message)); 40 | } 41 | 42 | @Override 43 | public void message(K pattern, K channel, V message) { 44 | final Span span = helper.buildSpan("message"); 45 | span.setTag("pattern", nullable(pattern)); 46 | span.setTag("channel", nullable(channel)); 47 | span.setTag("message", nullable(message)); 48 | helper.decorate(span, () -> listener.message(pattern, channel, message)); 49 | } 50 | 51 | @Override 52 | public void subscribed(K channel, long count) { 53 | final Span span = helper.buildSpan("subscribed"); 54 | span.setTag("channel", nullable(channel)); 55 | span.setTag("count", count); 56 | helper.decorate(span, () -> listener.subscribed(channel, count)); 57 | } 58 | 59 | @Override 60 | public void psubscribed(K pattern, long count) { 61 | final Span span = helper.buildSpan("psubscribed"); 62 | span.setTag("pattern", nullable(pattern)); 63 | span.setTag("count", count); 64 | helper.decorate(span, () -> listener.psubscribed(pattern, count)); 65 | } 66 | 67 | @Override 68 | public void unsubscribed(K channel, long count) { 69 | final Span span = helper.buildSpan("unsubscribed"); 70 | span.setTag("channel", nullable(channel)); 71 | span.setTag("count", count); 72 | helper.decorate(span, () -> listener.unsubscribed(channel, count)); 73 | } 74 | 75 | @Override 76 | public void punsubscribed(K pattern, long count) { 77 | final Span span = helper.buildSpan("punsubscribed"); 78 | span.setTag("pattern", nullable(pattern)); 79 | span.setTag("count", count); 80 | helper.decorate(span, () -> listener.punsubscribed(pattern, count)); 81 | } 82 | 83 | @Override 84 | public boolean equals(Object obj) { 85 | return listener.equals(obj); 86 | } 87 | 88 | @Override 89 | public int hashCode() { 90 | return listener.hashCode(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.1/src/main/java/io/opentracing/contrib/redis/lettuce51/TracingStatefulRedisConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce51; 15 | 16 | import io.lettuce.core.ClientOptions; 17 | import io.lettuce.core.api.StatefulRedisConnection; 18 | import io.lettuce.core.api.async.RedisAsyncCommands; 19 | import io.lettuce.core.api.reactive.RedisReactiveCommands; 20 | import io.lettuce.core.api.sync.RedisCommands; 21 | import io.lettuce.core.protocol.RedisCommand; 22 | import io.lettuce.core.resource.ClientResources; 23 | import io.opentracing.contrib.redis.common.TracingConfiguration; 24 | import java.time.Duration; 25 | import java.util.Collection; 26 | import java.util.concurrent.CompletableFuture; 27 | import java.util.concurrent.TimeUnit; 28 | 29 | public class TracingStatefulRedisConnection implements StatefulRedisConnection { 30 | 31 | private final StatefulRedisConnection connection; 32 | final TracingConfiguration tracingConfiguration; 33 | 34 | /** 35 | * @param connection redis connection 36 | * @param tracingConfiguration tracing configuration 37 | */ 38 | public TracingStatefulRedisConnection(StatefulRedisConnection connection, 39 | TracingConfiguration tracingConfiguration) { 40 | this.connection = connection; 41 | this.tracingConfiguration = tracingConfiguration; 42 | } 43 | 44 | @Override 45 | public boolean isMulti() { 46 | return connection.isMulti(); 47 | } 48 | 49 | @Override 50 | public RedisCommands sync() { 51 | return new TracingRedisCommands<>(connection.sync(), tracingConfiguration); 52 | } 53 | 54 | @Override 55 | public RedisAsyncCommands async() { 56 | return new TracingRedisAsyncCommands<>(connection.async(), tracingConfiguration); 57 | } 58 | 59 | @Override 60 | public RedisReactiveCommands reactive() { 61 | return connection.reactive(); 62 | } 63 | 64 | @Override 65 | public void setTimeout(Duration timeout) { 66 | connection.setTimeout(timeout); 67 | } 68 | 69 | @Override 70 | @Deprecated 71 | public void setTimeout(long timeout, TimeUnit unit) { 72 | connection.setTimeout(timeout, unit); 73 | } 74 | 75 | @Override 76 | public Duration getTimeout() { 77 | return connection.getTimeout(); 78 | } 79 | 80 | @Override 81 | public RedisCommand dispatch( 82 | RedisCommand command) { 83 | return connection.dispatch(command); 84 | } 85 | 86 | @Override 87 | public Collection> dispatch( 88 | Collection> redisCommands) { 89 | return connection.dispatch(redisCommands); 90 | } 91 | 92 | @Override 93 | public void close() { 94 | connection.close(); 95 | } 96 | 97 | @Override 98 | public CompletableFuture closeAsync() { 99 | return connection.closeAsync(); 100 | } 101 | 102 | @Override 103 | public boolean isOpen() { 104 | return connection.isOpen(); 105 | } 106 | 107 | @Override 108 | public ClientOptions getOptions() { 109 | return connection.getOptions(); 110 | } 111 | 112 | @Override 113 | public ClientResources getResources() { 114 | return connection.getResources(); 115 | } 116 | 117 | @Override 118 | public void reset() { 119 | connection.reset(); 120 | } 121 | 122 | @Override 123 | public void setAutoFlushCommands(boolean autoFlush) { 124 | connection.setAutoFlushCommands(autoFlush); 125 | } 126 | 127 | @Override 128 | public void flushCommands() { 129 | connection.flushCommands(); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.1/src/main/java/io/opentracing/contrib/redis/lettuce51/TracingStatefulRedisPubSubConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce51; 15 | 16 | import io.lettuce.core.pubsub.RedisPubSubListener; 17 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 18 | import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; 19 | import io.lettuce.core.pubsub.api.reactive.RedisPubSubReactiveCommands; 20 | import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; 21 | import io.opentracing.contrib.redis.common.TracingConfiguration; 22 | 23 | public class TracingStatefulRedisPubSubConnection extends 24 | TracingStatefulRedisConnection implements 25 | StatefulRedisPubSubConnection { 26 | 27 | private final StatefulRedisPubSubConnection connection; 28 | 29 | public TracingStatefulRedisPubSubConnection( 30 | StatefulRedisPubSubConnection connection, 31 | TracingConfiguration tracingConfiguration) { 32 | super(connection, tracingConfiguration); 33 | this.connection = connection; 34 | } 35 | 36 | @Override 37 | public RedisPubSubCommands sync() { 38 | return new TracingRedisPubSubCommands<>(connection.sync(), tracingConfiguration); 39 | } 40 | 41 | @Override 42 | public RedisPubSubAsyncCommands async() { 43 | return new TracingRedisPubSubAsyncCommands<>(connection.async(), tracingConfiguration); 44 | } 45 | 46 | @Override 47 | public RedisPubSubReactiveCommands reactive() { 48 | return connection.reactive(); 49 | } 50 | 51 | @Override 52 | public void addListener(RedisPubSubListener listener) { 53 | connection.addListener(new TracingRedisPubSubListener<>(listener, tracingConfiguration)); 54 | } 55 | 56 | @Override 57 | public void removeListener(RedisPubSubListener listener) { 58 | connection.removeListener(listener); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-lettuce-5.2 26 | OpenTracing Instrumentation for Lettuce 5.2 Redis Client 27 | OpenTracing Instrumentation for Lettuce 5.2 Redis Client 28 | 29 | 30 | 31 | 32 | io.opentracing.contrib 33 | opentracing-redis-common 34 | ${project.version} 35 | 36 | 37 | 38 | io.lettuce 39 | lettuce-core 40 | 5.2.2.RELEASE 41 | provided 42 | 43 | 44 | 45 | com.github.kstyrc 46 | embedded-redis 47 | test 48 | 49 | 50 | 51 | org.awaitility 52 | awaitility 53 | test 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.2/src/main/java/io/opentracing/contrib/redis/lettuce52/CompletableRedisFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce52; 15 | 16 | import io.lettuce.core.RedisFuture; 17 | import java.util.concurrent.CompletableFuture; 18 | import java.util.concurrent.TimeUnit; 19 | 20 | public class CompletableRedisFuture extends CompletableFuture implements RedisFuture { 21 | 22 | private RedisFuture wrappedFuture; 23 | 24 | public CompletableRedisFuture(RedisFuture wrappedFuture) { 25 | this.wrappedFuture = wrappedFuture; 26 | } 27 | 28 | @Override 29 | public String getError() { 30 | return wrappedFuture.getError(); 31 | } 32 | 33 | @Override 34 | public boolean await(long timeout, TimeUnit unit) throws InterruptedException { 35 | return wrappedFuture.await(timeout, unit); 36 | } 37 | } -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.2/src/main/java/io/opentracing/contrib/redis/lettuce52/TracingRedisPubSubAsyncCommands.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce52; 15 | 16 | import io.lettuce.core.RedisFuture; 17 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 18 | import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; 19 | import io.opentracing.Span; 20 | import io.opentracing.contrib.redis.common.TracingConfiguration; 21 | import java.util.Arrays; 22 | 23 | public class TracingRedisPubSubAsyncCommands extends 24 | TracingRedisAsyncCommands implements RedisPubSubAsyncCommands { 25 | private final RedisPubSubAsyncCommands commands; 26 | 27 | public TracingRedisPubSubAsyncCommands( 28 | RedisPubSubAsyncCommands commands, 29 | TracingConfiguration tracingConfiguration) { 30 | super(commands, tracingConfiguration); 31 | this.commands = commands; 32 | } 33 | 34 | @Override 35 | public RedisFuture psubscribe(K... patterns) { 36 | final Span span = helper.buildSpan("psubscribe"); 37 | span.setTag("patterns", Arrays.toString(patterns)); 38 | return prepareRedisFuture(commands.psubscribe(patterns), span); 39 | } 40 | 41 | @Override 42 | public RedisFuture punsubscribe(K... patterns) { 43 | final Span span = helper.buildSpan("punsubscribe"); 44 | span.setTag("patterns", Arrays.toString(patterns)); 45 | return prepareRedisFuture(commands.punsubscribe(patterns), span); 46 | } 47 | 48 | @Override 49 | public RedisFuture subscribe(K... channels) { 50 | final Span span = helper.buildSpan("subscribe"); 51 | span.setTag("channels", Arrays.toString(channels)); 52 | return prepareRedisFuture(commands.subscribe(channels), span); 53 | } 54 | 55 | @Override 56 | public RedisFuture unsubscribe(K... channels) { 57 | final Span span = helper.buildSpan("unsubscribe"); 58 | span.setTag("channels", Arrays.toString(channels)); 59 | return prepareRedisFuture(commands.unsubscribe(channels), span); 60 | } 61 | 62 | @Override 63 | public StatefulRedisPubSubConnection getStatefulConnection() { 64 | return new TracingStatefulRedisPubSubConnection<>(commands.getStatefulConnection(), 65 | tracingConfiguration); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.2/src/main/java/io/opentracing/contrib/redis/lettuce52/TracingRedisPubSubCommands.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce52; 15 | 16 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 17 | import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; 18 | import io.opentracing.Span; 19 | import io.opentracing.contrib.redis.common.TracingConfiguration; 20 | import java.util.Arrays; 21 | 22 | public class TracingRedisPubSubCommands extends TracingRedisCommands implements 23 | RedisPubSubCommands { 24 | private final RedisPubSubCommands commands; 25 | 26 | public TracingRedisPubSubCommands(RedisPubSubCommands commands, 27 | TracingConfiguration tracingConfiguration) { 28 | super(commands, tracingConfiguration); 29 | this.commands = commands; 30 | } 31 | 32 | @Override 33 | public void psubscribe(K... patterns) { 34 | final Span span = helper.buildSpan("psubscribe"); 35 | span.setTag("patterns", Arrays.toString(patterns)); 36 | helper.decorate(span, () -> commands.psubscribe(patterns)); 37 | } 38 | 39 | @Override 40 | public void punsubscribe(K... patterns) { 41 | final Span span = helper.buildSpan("punsubscribe"); 42 | span.setTag("patterns", Arrays.toString(patterns)); 43 | helper.decorate(span, () -> commands.punsubscribe(patterns)); 44 | } 45 | 46 | @Override 47 | public void subscribe(K... channels) { 48 | final Span span = helper.buildSpan("subscribe"); 49 | span.setTag("channels", Arrays.toString(channels)); 50 | helper.decorate(span, () -> commands.subscribe(channels)); 51 | } 52 | 53 | @Override 54 | public void unsubscribe(K... channels) { 55 | final Span span = helper.buildSpan("unsubscribe"); 56 | span.setTag("channels", Arrays.toString(channels)); 57 | helper.decorate(span, () -> commands.unsubscribe(channels)); 58 | } 59 | 60 | @Override 61 | public StatefulRedisPubSubConnection getStatefulConnection() { 62 | return new TracingStatefulRedisPubSubConnection<>(commands.getStatefulConnection(), 63 | tracingConfiguration); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.2/src/main/java/io/opentracing/contrib/redis/lettuce52/TracingRedisPubSubListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce52; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.lettuce.core.pubsub.RedisPubSubListener; 19 | import io.opentracing.Span; 20 | import io.opentracing.contrib.redis.common.TracingConfiguration; 21 | import io.opentracing.contrib.redis.common.TracingHelper; 22 | 23 | public class TracingRedisPubSubListener implements RedisPubSubListener { 24 | 25 | private final RedisPubSubListener listener; 26 | private final TracingHelper helper; 27 | 28 | public TracingRedisPubSubListener(RedisPubSubListener listener, 29 | TracingConfiguration tracingConfiguration) { 30 | this.listener = listener; 31 | this.helper = new TracingHelper(tracingConfiguration); 32 | } 33 | 34 | @Override 35 | public void message(K channel, V message) { 36 | final Span span = helper.buildSpan("message"); 37 | span.setTag("channel", nullable(channel)); 38 | span.setTag("message", nullable(message)); 39 | helper.decorate(span, () -> listener.message(channel, message)); 40 | } 41 | 42 | @Override 43 | public void message(K pattern, K channel, V message) { 44 | final Span span = helper.buildSpan("message"); 45 | span.setTag("pattern", nullable(pattern)); 46 | span.setTag("channel", nullable(channel)); 47 | span.setTag("message", nullable(message)); 48 | helper.decorate(span, () -> listener.message(pattern, channel, message)); 49 | } 50 | 51 | @Override 52 | public void subscribed(K channel, long count) { 53 | final Span span = helper.buildSpan("subscribed"); 54 | span.setTag("channel", nullable(channel)); 55 | span.setTag("count", count); 56 | helper.decorate(span, () -> listener.subscribed(channel, count)); 57 | } 58 | 59 | @Override 60 | public void psubscribed(K pattern, long count) { 61 | final Span span = helper.buildSpan("psubscribed"); 62 | span.setTag("pattern", nullable(pattern)); 63 | span.setTag("count", count); 64 | helper.decorate(span, () -> listener.psubscribed(pattern, count)); 65 | } 66 | 67 | @Override 68 | public void unsubscribed(K channel, long count) { 69 | final Span span = helper.buildSpan("unsubscribed"); 70 | span.setTag("channel", nullable(channel)); 71 | span.setTag("count", count); 72 | helper.decorate(span, () -> listener.unsubscribed(channel, count)); 73 | } 74 | 75 | @Override 76 | public void punsubscribed(K pattern, long count) { 77 | final Span span = helper.buildSpan("punsubscribed"); 78 | span.setTag("pattern", nullable(pattern)); 79 | span.setTag("count", count); 80 | helper.decorate(span, () -> listener.punsubscribed(pattern, count)); 81 | } 82 | 83 | @Override 84 | public boolean equals(Object obj) { 85 | return listener.equals(obj); 86 | } 87 | 88 | @Override 89 | public int hashCode() { 90 | return listener.hashCode(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.2/src/main/java/io/opentracing/contrib/redis/lettuce52/TracingStatefulRedisConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce52; 15 | 16 | import io.lettuce.core.ClientOptions; 17 | import io.lettuce.core.api.StatefulRedisConnection; 18 | import io.lettuce.core.api.async.RedisAsyncCommands; 19 | import io.lettuce.core.api.reactive.RedisReactiveCommands; 20 | import io.lettuce.core.api.sync.RedisCommands; 21 | import io.lettuce.core.protocol.RedisCommand; 22 | import io.lettuce.core.resource.ClientResources; 23 | import io.opentracing.contrib.redis.common.TracingConfiguration; 24 | import java.time.Duration; 25 | import java.util.Collection; 26 | import java.util.concurrent.CompletableFuture; 27 | import java.util.concurrent.TimeUnit; 28 | 29 | public class TracingStatefulRedisConnection implements StatefulRedisConnection { 30 | 31 | private final StatefulRedisConnection connection; 32 | final TracingConfiguration tracingConfiguration; 33 | 34 | /** 35 | * @param connection redis connection 36 | * @param tracingConfiguration tracing configuration 37 | */ 38 | public TracingStatefulRedisConnection(StatefulRedisConnection connection, 39 | TracingConfiguration tracingConfiguration) { 40 | this.connection = connection; 41 | this.tracingConfiguration = tracingConfiguration; 42 | } 43 | 44 | @Override 45 | public boolean isMulti() { 46 | return connection.isMulti(); 47 | } 48 | 49 | @Override 50 | public RedisCommands sync() { 51 | return new TracingRedisCommands<>(connection.sync(), tracingConfiguration); 52 | } 53 | 54 | @Override 55 | public RedisAsyncCommands async() { 56 | return new TracingRedisAsyncCommands<>(connection.async(), tracingConfiguration); 57 | } 58 | 59 | @Override 60 | public RedisReactiveCommands reactive() { 61 | return connection.reactive(); 62 | } 63 | 64 | @Override 65 | public void setTimeout(Duration timeout) { 66 | connection.setTimeout(timeout); 67 | } 68 | 69 | @Override 70 | @Deprecated 71 | public void setTimeout(long timeout, TimeUnit unit) { 72 | connection.setTimeout(timeout, unit); 73 | } 74 | 75 | @Override 76 | public Duration getTimeout() { 77 | return connection.getTimeout(); 78 | } 79 | 80 | @Override 81 | public RedisCommand dispatch( 82 | RedisCommand command) { 83 | return connection.dispatch(command); 84 | } 85 | 86 | @Override 87 | public Collection> dispatch( 88 | Collection> redisCommands) { 89 | return connection.dispatch(redisCommands); 90 | } 91 | 92 | @Override 93 | public void close() { 94 | connection.close(); 95 | } 96 | 97 | @Override 98 | public CompletableFuture closeAsync() { 99 | return connection.closeAsync(); 100 | } 101 | 102 | @Override 103 | public boolean isOpen() { 104 | return connection.isOpen(); 105 | } 106 | 107 | @Override 108 | public ClientOptions getOptions() { 109 | return connection.getOptions(); 110 | } 111 | 112 | @Override 113 | public ClientResources getResources() { 114 | return connection.getResources(); 115 | } 116 | 117 | @Override 118 | public void reset() { 119 | connection.reset(); 120 | } 121 | 122 | @Override 123 | public void setAutoFlushCommands(boolean autoFlush) { 124 | connection.setAutoFlushCommands(autoFlush); 125 | } 126 | 127 | @Override 128 | public void flushCommands() { 129 | connection.flushCommands(); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /opentracing-redis-lettuce-5.2/src/main/java/io/opentracing/contrib/redis/lettuce52/TracingStatefulRedisPubSubConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.lettuce52; 15 | 16 | import io.lettuce.core.pubsub.RedisPubSubListener; 17 | import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; 18 | import io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands; 19 | import io.lettuce.core.pubsub.api.reactive.RedisPubSubReactiveCommands; 20 | import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; 21 | import io.opentracing.contrib.redis.common.TracingConfiguration; 22 | 23 | public class TracingStatefulRedisPubSubConnection extends 24 | TracingStatefulRedisConnection implements 25 | StatefulRedisPubSubConnection { 26 | 27 | private final StatefulRedisPubSubConnection connection; 28 | 29 | public TracingStatefulRedisPubSubConnection( 30 | StatefulRedisPubSubConnection connection, 31 | TracingConfiguration tracingConfiguration) { 32 | super(connection, tracingConfiguration); 33 | this.connection = connection; 34 | } 35 | 36 | @Override 37 | public RedisPubSubCommands sync() { 38 | return new TracingRedisPubSubCommands<>(connection.sync(), tracingConfiguration); 39 | } 40 | 41 | @Override 42 | public RedisPubSubAsyncCommands async() { 43 | return new TracingRedisPubSubAsyncCommands<>(connection.async(), tracingConfiguration); 44 | } 45 | 46 | @Override 47 | public RedisPubSubReactiveCommands reactive() { 48 | return connection.reactive(); 49 | } 50 | 51 | @Override 52 | public void addListener(RedisPubSubListener listener) { 53 | connection.addListener(new TracingRedisPubSubListener<>(listener, tracingConfiguration)); 54 | } 55 | 56 | @Override 57 | public void removeListener(RedisPubSubListener listener) { 58 | connection.removeListener(listener); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-redisson 26 | OpenTracing Instrumentation for Redisson 27 | OpenTracing Instrumentation for Redisson 28 | 29 | 30 | 31 | 32 | io.opentracing.contrib 33 | opentracing-redis-common 34 | ${project.version} 35 | 36 | 37 | 38 | org.redisson 39 | redisson 40 | 3.12.2 41 | provided 42 | 43 | 44 | 45 | com.github.kstyrc 46 | embedded-redis 47 | test 48 | 49 | 50 | 51 | org.awaitility 52 | awaitility 53 | test 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/CompletableRFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import java.util.concurrent.CompletableFuture; 17 | import java.util.concurrent.TimeUnit; 18 | import java.util.function.BiConsumer; 19 | import org.redisson.api.RFuture; 20 | 21 | public class CompletableRFuture extends CompletableFuture implements RFuture { 22 | private RFuture wrappedFuture; 23 | 24 | public CompletableRFuture(RFuture wrappedFuture) { 25 | this.wrappedFuture = wrappedFuture; 26 | } 27 | 28 | @Override 29 | public boolean isSuccess() { 30 | return wrappedFuture.isSuccess(); 31 | } 32 | 33 | @Override 34 | public Throwable cause() { 35 | return wrappedFuture.cause(); 36 | } 37 | 38 | @Override 39 | public T getNow() { 40 | return wrappedFuture.getNow(); 41 | } 42 | 43 | @Override 44 | public boolean await(long timeout, TimeUnit unit) throws InterruptedException { 45 | return wrappedFuture.await(timeout, unit); 46 | } 47 | 48 | @Override 49 | public boolean await(long timeoutMillis) throws InterruptedException { 50 | return wrappedFuture.await(timeoutMillis); 51 | } 52 | 53 | @Override 54 | public RFuture sync() throws InterruptedException { 55 | return wrappedFuture.sync(); 56 | } 57 | 58 | @Override 59 | public RFuture syncUninterruptibly() { 60 | return wrappedFuture.syncUninterruptibly(); 61 | } 62 | 63 | @Override 64 | public RFuture await() throws InterruptedException { 65 | return wrappedFuture.await(); 66 | } 67 | 68 | @Override 69 | public RFuture awaitUninterruptibly() { 70 | return wrappedFuture.awaitUninterruptibly(); 71 | } 72 | 73 | @Override 74 | public boolean awaitUninterruptibly(long timeout, TimeUnit unit) { 75 | return wrappedFuture.awaitUninterruptibly(timeout, unit); 76 | } 77 | 78 | @Override 79 | public boolean awaitUninterruptibly(long timeoutMillis) { 80 | return wrappedFuture.awaitUninterruptibly(timeoutMillis); 81 | } 82 | 83 | @Override 84 | public void onComplete(BiConsumer biConsumer) { 85 | wrappedFuture.onComplete(biConsumer); 86 | } 87 | } -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRBoundedBlockingQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | 17 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 18 | 19 | import io.opentracing.Span; 20 | import java.util.concurrent.TimeUnit; 21 | import org.redisson.api.RBoundedBlockingQueue; 22 | import org.redisson.api.RFuture; 23 | 24 | public class TracingRBoundedBlockingQueue extends TracingRBlockingQueue implements 25 | RBoundedBlockingQueue { 26 | private final RBoundedBlockingQueue queue; 27 | private final TracingRedissonHelper tracingRedissonHelper; 28 | 29 | public TracingRBoundedBlockingQueue(RBoundedBlockingQueue queue, 30 | TracingRedissonHelper tracingRedissonHelper) { 31 | super(queue, tracingRedissonHelper); 32 | this.queue = queue; 33 | this.tracingRedissonHelper = tracingRedissonHelper; 34 | } 35 | 36 | @Override 37 | public boolean trySetCapacity(int capacity) { 38 | Span span = tracingRedissonHelper.buildSpan("trySetCapacity", queue); 39 | span.setTag("capacity", capacity); 40 | return tracingRedissonHelper.decorate(span, () -> queue.trySetCapacity(capacity)); 41 | } 42 | 43 | @Override 44 | public RFuture trySetCapacityAsync(int capacity) { 45 | Span span = tracingRedissonHelper.buildSpan("trySetCapacityAsync", queue); 46 | span.setTag("capacity", capacity); 47 | return tracingRedissonHelper.prepareRFuture(span, () -> queue.trySetCapacityAsync(capacity)); 48 | } 49 | 50 | @Override 51 | public RFuture offerAsync(V e, long timeout, TimeUnit unit) { 52 | Span span = tracingRedissonHelper.buildSpan("offerAsync", queue); 53 | span.setTag("element", nullable(e)); 54 | span.setTag("timeout", timeout); 55 | span.setTag("unit", nullable(unit)); 56 | return tracingRedissonHelper.prepareRFuture(span, () -> queue.offerAsync(e, timeout, unit)); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRBuckets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.Arrays; 20 | import java.util.Map; 21 | import org.redisson.api.RBuckets; 22 | import org.redisson.api.RFuture; 23 | 24 | public class TracingRBuckets implements RBuckets { 25 | private final RBuckets buckets; 26 | private final TracingRedissonHelper tracingRedissonHelper; 27 | 28 | public TracingRBuckets(RBuckets buckets, 29 | TracingRedissonHelper tracingRedissonHelper) { 30 | this.buckets = buckets; 31 | this.tracingRedissonHelper = tracingRedissonHelper; 32 | } 33 | 34 | @Override 35 | public Map get(String... keys) { 36 | Span span = tracingRedissonHelper.buildSpan("get"); 37 | span.setTag("keys", Arrays.toString(keys)); 38 | return tracingRedissonHelper.decorate(span, () -> buckets.get(keys)); 39 | } 40 | 41 | @Override 42 | public boolean trySet(Map buckets) { 43 | Span span = tracingRedissonHelper.buildSpan("trySet"); 44 | span.setTag("buckets", nullable(buckets)); 45 | return tracingRedissonHelper.decorate(span, () -> this.buckets.trySet(buckets)); 46 | } 47 | 48 | @Override 49 | public void set(Map buckets) { 50 | Span span = tracingRedissonHelper.buildSpan("set"); 51 | span.setTag("buckets", nullable(buckets)); 52 | tracingRedissonHelper.decorate(span, () -> this.buckets.set(buckets)); 53 | } 54 | 55 | @Override 56 | public long delete(String... keys) { 57 | Span span = tracingRedissonHelper.buildSpan("delete"); 58 | span.setTag("keys", Arrays.toString(keys)); 59 | return tracingRedissonHelper.decorate(span, () -> buckets.delete(keys)); 60 | } 61 | 62 | @Override 63 | public RFuture> getAsync(String... keys) { 64 | Span span = tracingRedissonHelper.buildSpan("getAsync"); 65 | span.setTag("keys", Arrays.toString(keys)); 66 | return tracingRedissonHelper.prepareRFuture(span, () -> buckets.getAsync(keys)); 67 | } 68 | 69 | @Override 70 | public RFuture trySetAsync(Map buckets) { 71 | Span span = tracingRedissonHelper.buildSpan("trySetAsync"); 72 | span.setTag("buckets", nullable(buckets)); 73 | return tracingRedissonHelper.prepareRFuture(span, () -> this.buckets.trySetAsync(buckets)); 74 | } 75 | 76 | @Override 77 | public RFuture setAsync(Map buckets) { 78 | Span span = tracingRedissonHelper.buildSpan("setAsync"); 79 | span.setTag("buckets", nullable(buckets)); 80 | return tracingRedissonHelper.prepareRFuture(span, () -> this.buckets.setAsync(buckets)); 81 | } 82 | 83 | @Override 84 | public RFuture deleteAsync(String... keys) { 85 | Span span = tracingRedissonHelper.buildSpan("deleteAsync"); 86 | span.setTag("keys", nullable(keys)); 87 | return tracingRedissonHelper.prepareRFuture(span, () -> this.buckets.deleteAsync(keys)); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRCollectionMapReduce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import java.util.concurrent.TimeUnit; 17 | import org.redisson.api.mapreduce.RCollectionMapReduce; 18 | import org.redisson.api.mapreduce.RCollectionMapper; 19 | import org.redisson.api.mapreduce.RReducer; 20 | 21 | public class TracingRCollectionMapReduce extends 22 | TracingRMapReduceExecutor implements RCollectionMapReduce { 23 | private final RCollectionMapReduce mapReduce; 24 | private final TracingRedissonHelper tracingRedissonHelper; 25 | 26 | public TracingRCollectionMapReduce(RCollectionMapReduce mapReduce, 27 | TracingRedissonHelper tracingRedissonHelper) { 28 | super(mapReduce, tracingRedissonHelper); 29 | this.mapReduce = mapReduce; 30 | this.tracingRedissonHelper = tracingRedissonHelper; 31 | } 32 | 33 | @Override 34 | public RCollectionMapReduce timeout(long timeout, TimeUnit unit) { 35 | return new TracingRCollectionMapReduce<>(mapReduce.timeout(timeout, unit), 36 | tracingRedissonHelper); 37 | } 38 | 39 | @Override 40 | public RCollectionMapReduce mapper( 41 | RCollectionMapper mapper) { 42 | return new TracingRCollectionMapReduce<>(mapReduce.mapper(mapper), tracingRedissonHelper); 43 | } 44 | 45 | @Override 46 | public RCollectionMapReduce reducer( 47 | RReducer reducer) { 48 | return new TracingRCollectionMapReduce<>(mapReduce.reducer(reducer), tracingRedissonHelper); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRCountDownLatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.concurrent.TimeUnit; 20 | import org.redisson.api.RCountDownLatch; 21 | import org.redisson.api.RFuture; 22 | 23 | public class TracingRCountDownLatch extends TracingRObject implements RCountDownLatch { 24 | private final RCountDownLatch latch; 25 | private final TracingRedissonHelper tracingRedissonHelper; 26 | 27 | public TracingRCountDownLatch(RCountDownLatch latch, 28 | TracingRedissonHelper tracingRedissonHelper) { 29 | super(latch, tracingRedissonHelper); 30 | this.latch = latch; 31 | this.tracingRedissonHelper = tracingRedissonHelper; 32 | } 33 | 34 | @Override 35 | public void await() throws InterruptedException { 36 | Span span = tracingRedissonHelper.buildSpan("await", latch); 37 | tracingRedissonHelper.decorateThrowing(span, () -> latch.await()); 38 | } 39 | 40 | @Override 41 | public boolean await(long timeout, TimeUnit unit) throws InterruptedException { 42 | Span span = tracingRedissonHelper.buildSpan("await", latch); 43 | span.setTag("timeout", timeout); 44 | span.setTag("unit", nullable(unit)); 45 | return tracingRedissonHelper.decorateThrowing(span, () -> latch.await(timeout, unit)); 46 | } 47 | 48 | @Override 49 | public void countDown() { 50 | Span span = tracingRedissonHelper.buildSpan("countDown", latch); 51 | tracingRedissonHelper.decorate(span, latch::countDown); 52 | } 53 | 54 | @Override 55 | public long getCount() { 56 | Span span = tracingRedissonHelper.buildSpan("getCount", latch); 57 | return tracingRedissonHelper.decorate(span, latch::getCount); 58 | } 59 | 60 | @Override 61 | public boolean trySetCount(long count) { 62 | Span span = tracingRedissonHelper.buildSpan("trySetCount", latch); 63 | span.setTag("count", count); 64 | return tracingRedissonHelper.decorateThrowing(span, () -> latch.trySetCount(count)); 65 | } 66 | 67 | @Override 68 | public RFuture awaitAsync() { 69 | Span span = tracingRedissonHelper.buildSpan("awaitAsync", latch); 70 | return tracingRedissonHelper.prepareRFuture(span, latch::awaitAsync); 71 | } 72 | 73 | @Override 74 | public RFuture awaitAsync(long waitTime, TimeUnit unit) { 75 | Span span = tracingRedissonHelper.buildSpan("awaitAsync", latch); 76 | span.setTag("waitTime", waitTime); 77 | span.setTag("unit", nullable(unit)); 78 | return tracingRedissonHelper.prepareRFuture(span, () -> latch.awaitAsync(waitTime, unit)); 79 | } 80 | 81 | @Override 82 | public RFuture countDownAsync() { 83 | Span span = tracingRedissonHelper.buildSpan("countDownAsync", latch); 84 | return tracingRedissonHelper.prepareRFuture(span, latch::countDownAsync); 85 | } 86 | 87 | @Override 88 | public RFuture getCountAsync() { 89 | Span span = tracingRedissonHelper.buildSpan("getCountAsync", latch); 90 | return tracingRedissonHelper.prepareRFuture(span, latch::getCountAsync); 91 | } 92 | 93 | @Override 94 | public RFuture trySetCountAsync(long count) { 95 | Span span = tracingRedissonHelper.buildSpan("trySetCountAsync", latch); 96 | return tracingRedissonHelper.prepareRFuture(span, () -> latch.trySetCountAsync(count)); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRDelayedQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | 17 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 18 | 19 | import io.opentracing.Span; 20 | import java.util.concurrent.TimeUnit; 21 | import org.redisson.api.RDelayedQueue; 22 | import org.redisson.api.RFuture; 23 | 24 | public class TracingRDelayedQueue extends TracingRQueue implements RDelayedQueue { 25 | private final RDelayedQueue queue; 26 | private final TracingRedissonHelper tracingRedissonHelper; 27 | 28 | public TracingRDelayedQueue(RDelayedQueue queue, TracingRedissonHelper tracingRedissonHelper) { 29 | super(queue, tracingRedissonHelper); 30 | this.queue = queue; 31 | this.tracingRedissonHelper = tracingRedissonHelper; 32 | } 33 | 34 | @Override 35 | public void offer(V e, long delay, TimeUnit timeUnit) { 36 | Span span = tracingRedissonHelper.buildSpan("offer", queue); 37 | span.setTag("element", nullable(e)); 38 | span.setTag("delay", delay); 39 | span.setTag("timeUnit", nullable(timeUnit)); 40 | tracingRedissonHelper.decorate(span, () -> queue.offer(e, delay, timeUnit)); 41 | } 42 | 43 | @Override 44 | public RFuture offerAsync(V e, long delay, TimeUnit timeUnit) { 45 | Span span = tracingRedissonHelper.buildSpan("offerAsync", queue); 46 | span.setTag("element", nullable(e)); 47 | span.setTag("delay", delay); 48 | span.setTag("timeUnit", nullable(timeUnit)); 49 | return tracingRedissonHelper.prepareRFuture(span, () -> queue.offerAsync(e, delay, timeUnit)); 50 | } 51 | 52 | 53 | @Override 54 | public void destroy() { 55 | Span span = tracingRedissonHelper.buildSpan("destroy", queue); 56 | tracingRedissonHelper.decorate(span, queue::destroy); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRDoubleAdder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.concurrent.TimeUnit; 20 | import org.redisson.api.RDoubleAdder; 21 | import org.redisson.api.RFuture; 22 | 23 | public class TracingRDoubleAdder extends TracingRExpirable implements RDoubleAdder { 24 | private final RDoubleAdder doubleAdder; 25 | private final TracingRedissonHelper tracingRedissonHelper; 26 | 27 | public TracingRDoubleAdder(RDoubleAdder doubleAdder, 28 | TracingRedissonHelper tracingRedissonHelper) { 29 | super(doubleAdder, tracingRedissonHelper); 30 | this.doubleAdder = doubleAdder; 31 | this.tracingRedissonHelper = tracingRedissonHelper; 32 | } 33 | 34 | @Override 35 | public void add(double x) { 36 | Span span = tracingRedissonHelper.buildSpan("add", doubleAdder); 37 | span.setTag("value", x); 38 | tracingRedissonHelper.decorate(span, () -> doubleAdder.add(x)); 39 | } 40 | 41 | @Override 42 | public void increment() { 43 | Span span = tracingRedissonHelper.buildSpan("increment", doubleAdder); 44 | tracingRedissonHelper.decorate(span, doubleAdder::increment); 45 | } 46 | 47 | @Override 48 | public void decrement() { 49 | Span span = tracingRedissonHelper.buildSpan("decrement", doubleAdder); 50 | tracingRedissonHelper.decorate(span, doubleAdder::decrement); 51 | } 52 | 53 | @Override 54 | public double sum() { 55 | Span span = tracingRedissonHelper.buildSpan("sum", doubleAdder); 56 | return tracingRedissonHelper.decorate(span, doubleAdder::sum); 57 | } 58 | 59 | @Override 60 | public void reset() { 61 | Span span = tracingRedissonHelper.buildSpan("reset", doubleAdder); 62 | tracingRedissonHelper.decorate(span, doubleAdder::reset); 63 | } 64 | 65 | @Override 66 | public RFuture sumAsync() { 67 | Span span = tracingRedissonHelper.buildSpan("sumAsync", doubleAdder); 68 | return tracingRedissonHelper.prepareRFuture(span, doubleAdder::sumAsync); 69 | } 70 | 71 | @Override 72 | public RFuture sumAsync(long timeout, TimeUnit timeUnit) { 73 | Span span = tracingRedissonHelper.buildSpan("sumAsync", doubleAdder); 74 | span.setTag("timeout", timeout); 75 | span.setTag("timeUnit", nullable(timeUnit)); 76 | return tracingRedissonHelper 77 | .prepareRFuture(span, () -> doubleAdder.sumAsync(timeout, timeUnit)); 78 | } 79 | 80 | @Override 81 | public RFuture resetAsync() { 82 | Span span = tracingRedissonHelper.buildSpan("resetAsync", doubleAdder); 83 | return tracingRedissonHelper.prepareRFuture(span, doubleAdder::resetAsync); 84 | } 85 | 86 | @Override 87 | public RFuture resetAsync(long timeout, TimeUnit timeUnit) { 88 | Span span = tracingRedissonHelper.buildSpan("resetAsync", doubleAdder); 89 | span.setTag("timeout", timeout); 90 | span.setTag("timeUnit", nullable(timeUnit)); 91 | return tracingRedissonHelper 92 | .prepareRFuture(span, () -> doubleAdder.resetAsync(timeout, timeUnit)); 93 | } 94 | 95 | @Override 96 | public void destroy() { 97 | Span span = tracingRedissonHelper.buildSpan("destroy", doubleAdder); 98 | tracingRedissonHelper.decorate(span, doubleAdder::destroy); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRExpirable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | 17 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 18 | 19 | import io.opentracing.Span; 20 | import java.util.Date; 21 | import java.util.concurrent.TimeUnit; 22 | import org.redisson.api.RExpirable; 23 | import org.redisson.api.RFuture; 24 | 25 | public class TracingRExpirable extends TracingRObject implements RExpirable { 26 | private final RExpirable expirable; 27 | private final TracingRedissonHelper tracingRedissonHelper; 28 | 29 | public TracingRExpirable(RExpirable expirable, TracingRedissonHelper tracingRedissonHelper) { 30 | super(expirable, tracingRedissonHelper); 31 | this.expirable = expirable; 32 | this.tracingRedissonHelper = tracingRedissonHelper; 33 | } 34 | 35 | @Override 36 | public boolean expire(long timeToLive, TimeUnit timeUnit) { 37 | Span span = tracingRedissonHelper.buildSpan("expire", expirable); 38 | span.setTag("timeToLive", timeToLive); 39 | span.setTag("timeUnit", nullable(timeUnit)); 40 | return tracingRedissonHelper.decorate(span, () -> expirable.expire(timeToLive, timeUnit)); 41 | } 42 | 43 | @Override 44 | public boolean expireAt(long timestamp) { 45 | Span span = tracingRedissonHelper.buildSpan("expireAt", expirable); 46 | span.setTag("timestamp", timestamp); 47 | return tracingRedissonHelper.decorate(span, () -> expirable.expireAt(timestamp)); 48 | } 49 | 50 | @Override 51 | public boolean expireAt(Date timestamp) { 52 | Span span = tracingRedissonHelper.buildSpan("expireAt", expirable); 53 | span.setTag("timestamp", nullable(timestamp)); 54 | return tracingRedissonHelper.decorate(span, () -> expirable.expireAt(timestamp)); 55 | } 56 | 57 | @Override 58 | public boolean clearExpire() { 59 | Span span = tracingRedissonHelper.buildSpan("clearExpire", expirable); 60 | return tracingRedissonHelper.decorate(span, expirable::clearExpire); 61 | } 62 | 63 | @Override 64 | public long remainTimeToLive() { 65 | Span span = tracingRedissonHelper.buildSpan("remainTimeToLive", expirable); 66 | return tracingRedissonHelper.decorate(span, expirable::remainTimeToLive); 67 | } 68 | 69 | @Override 70 | public RFuture expireAsync(long timeToLive, 71 | TimeUnit timeUnit) { 72 | Span span = tracingRedissonHelper.buildSpan("expireAsync", expirable); 73 | span.setTag("timeToLive", timeToLive); 74 | span.setTag("timeUnit", nullable(timeUnit)); 75 | return tracingRedissonHelper 76 | .prepareRFuture(span, () -> expirable.expireAsync(timeToLive, timeUnit)); 77 | } 78 | 79 | @Override 80 | public RFuture expireAtAsync(Date timestamp) { 81 | Span span = tracingRedissonHelper.buildSpan("expireAtAsync", expirable); 82 | span.setTag("timestamp", nullable(timestamp)); 83 | return tracingRedissonHelper.prepareRFuture(span, () -> expirable.expireAtAsync(timestamp)); 84 | } 85 | 86 | @Override 87 | public RFuture expireAtAsync(long timestamp) { 88 | Span span = tracingRedissonHelper.buildSpan("expireAtAsync", expirable); 89 | span.setTag("timestamp", timestamp); 90 | return tracingRedissonHelper.prepareRFuture(span, () -> expirable.expireAtAsync(timestamp)); 91 | } 92 | 93 | @Override 94 | public RFuture clearExpireAsync() { 95 | Span span = tracingRedissonHelper.buildSpan("clearExpireAsync", expirable); 96 | return tracingRedissonHelper.prepareRFuture(span, expirable::clearExpireAsync); 97 | } 98 | 99 | @Override 100 | public RFuture remainTimeToLiveAsync() { 101 | Span span = tracingRedissonHelper.buildSpan("remainTimeToLiveAsync", expirable); 102 | return tracingRedissonHelper.prepareRFuture(span, expirable::remainTimeToLiveAsync); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRListMultimap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | 17 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 18 | 19 | import io.opentracing.Span; 20 | import java.util.List; 21 | import org.redisson.api.RList; 22 | import org.redisson.api.RListMultimap; 23 | 24 | public class TracingRListMultimap extends TracingRMultimap implements 25 | RListMultimap { 26 | private final RListMultimap map; 27 | private final TracingRedissonHelper tracingRedissonHelper; 28 | 29 | public TracingRListMultimap(RListMultimap map, 30 | TracingRedissonHelper tracingRedissonHelper) { 31 | super(map, tracingRedissonHelper); 32 | this.map = map; 33 | this.tracingRedissonHelper = tracingRedissonHelper; 34 | } 35 | 36 | @Override 37 | public RList get(K key) { 38 | Span span = tracingRedissonHelper.buildSpan("get", map); 39 | span.setTag("key", nullable(key)); 40 | return tracingRedissonHelper 41 | .decorate(span, () -> new TracingRList<>(map.get(key), tracingRedissonHelper)); 42 | } 43 | 44 | @Override 45 | public List getAll(K key) { 46 | Span span = tracingRedissonHelper.buildSpan("getAll", map); 47 | span.setTag("key", nullable(key)); 48 | return tracingRedissonHelper.decorate(span, () -> map.getAll(key)); 49 | } 50 | 51 | @Override 52 | public List removeAll(Object key) { 53 | Span span = tracingRedissonHelper.buildSpan("removeAll", map); 54 | span.setTag("key", nullable(key)); 55 | return tracingRedissonHelper.decorate(span, () -> map.removeAll(key)); 56 | } 57 | 58 | @Override 59 | public List replaceValues(K key, Iterable values) { 60 | Span span = tracingRedissonHelper.buildSpan("replaceValues", map); 61 | span.setTag("key", nullable(key)); 62 | span.setTag("values", nullable(values)); 63 | return tracingRedissonHelper.decorate(span, () -> map.replaceValues(key, values)); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRLocalCachedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import io.opentracing.Span; 17 | import java.util.Collection; 18 | import java.util.Map; 19 | import java.util.Set; 20 | import org.redisson.api.RFuture; 21 | import org.redisson.api.RLocalCachedMap; 22 | 23 | public class TracingRLocalCachedMap extends TracingRMap implements 24 | RLocalCachedMap { 25 | private final RLocalCachedMap map; 26 | private final TracingRedissonHelper tracingRedissonHelper; 27 | 28 | public TracingRLocalCachedMap(RLocalCachedMap map, 29 | TracingRedissonHelper tracingRedissonHelper) { 30 | super(map, tracingRedissonHelper); 31 | this.map = map; 32 | this.tracingRedissonHelper = tracingRedissonHelper; 33 | } 34 | 35 | @Override 36 | public void preloadCache() { 37 | Span span = tracingRedissonHelper.buildSpan("preloadCache", map); 38 | tracingRedissonHelper.decorate(span, () -> map.preloadCache()); 39 | } 40 | 41 | @Override 42 | public void preloadCache(int count) { 43 | Span span = tracingRedissonHelper.buildSpan("preloadCache", map); 44 | span.setTag("count", count); 45 | tracingRedissonHelper.decorate(span, () -> map.preloadCache(count)); 46 | } 47 | 48 | @Override 49 | public RFuture clearLocalCacheAsync() { 50 | Span span = tracingRedissonHelper.buildSpan("clearLocalCacheAsync", map); 51 | return tracingRedissonHelper.prepareRFuture(span, map::clearLocalCacheAsync); 52 | } 53 | 54 | @Override 55 | public void clearLocalCache() { 56 | Span span = tracingRedissonHelper.buildSpan("clearLocalCache", map); 57 | tracingRedissonHelper.decorate(span, map::clearLocalCache); 58 | } 59 | 60 | @Override 61 | public Set cachedKeySet() { 62 | Span span = tracingRedissonHelper.buildSpan("cachedKeySet", map); 63 | return tracingRedissonHelper.decorate(span, map::cachedKeySet); 64 | } 65 | 66 | @Override 67 | public Collection cachedValues() { 68 | Span span = tracingRedissonHelper.buildSpan("cachedValues", map); 69 | return tracingRedissonHelper.decorate(span, map::cachedValues); 70 | } 71 | 72 | @Override 73 | public Set> cachedEntrySet() { 74 | Span span = tracingRedissonHelper.buildSpan("cachedEntrySet", map); 75 | return tracingRedissonHelper.decorate(span, map::cachedEntrySet); 76 | } 77 | 78 | @Override 79 | public Map getCachedMap() { 80 | Span span = tracingRedissonHelper.buildSpan("getCachedMap", map); 81 | return tracingRedissonHelper.decorate(span, map::getCachedMap); 82 | } 83 | 84 | @Override 85 | public void destroy() { 86 | Span span = tracingRedissonHelper.buildSpan("destroy", map); 87 | tracingRedissonHelper.decorate(span, map::destroy); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRLongAdder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | 17 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 18 | 19 | import io.opentracing.Span; 20 | import java.util.concurrent.TimeUnit; 21 | import org.redisson.api.RFuture; 22 | import org.redisson.api.RLongAdder; 23 | 24 | public class TracingRLongAdder extends TracingRExpirable implements RLongAdder { 25 | private final RLongAdder longAdder; 26 | private final TracingRedissonHelper tracingRedissonHelper; 27 | 28 | public TracingRLongAdder(RLongAdder longAdder, TracingRedissonHelper tracingRedissonHelper) { 29 | super(longAdder, tracingRedissonHelper); 30 | this.longAdder = longAdder; 31 | this.tracingRedissonHelper = tracingRedissonHelper; 32 | } 33 | 34 | @Override 35 | public void add(long x) { 36 | Span span = tracingRedissonHelper.buildSpan("add", longAdder); 37 | span.setTag("value", x); 38 | tracingRedissonHelper.decorate(span, () -> longAdder.add(x)); 39 | } 40 | 41 | @Override 42 | public void increment() { 43 | Span span = tracingRedissonHelper.buildSpan("increment", longAdder); 44 | tracingRedissonHelper.decorate(span, longAdder::increment); 45 | } 46 | 47 | @Override 48 | public void decrement() { 49 | Span span = tracingRedissonHelper.buildSpan("decrement", longAdder); 50 | tracingRedissonHelper.decorate(span, longAdder::decrement); 51 | } 52 | 53 | @Override 54 | public long sum() { 55 | Span span = tracingRedissonHelper.buildSpan("sum", longAdder); 56 | return tracingRedissonHelper.decorate(span, longAdder::sum); 57 | } 58 | 59 | @Override 60 | public void reset() { 61 | Span span = tracingRedissonHelper.buildSpan("reset", longAdder); 62 | tracingRedissonHelper.decorate(span, longAdder::reset); 63 | } 64 | 65 | @Override 66 | public RFuture sumAsync() { 67 | Span span = tracingRedissonHelper.buildSpan("sumAsync", longAdder); 68 | return tracingRedissonHelper.prepareRFuture(span, longAdder::sumAsync); 69 | } 70 | 71 | @Override 72 | public RFuture sumAsync(long timeout, TimeUnit timeUnit) { 73 | Span span = tracingRedissonHelper.buildSpan("sumAsync", longAdder); 74 | span.setTag("timeout", timeout); 75 | span.setTag("timeUnit", nullable(timeUnit)); 76 | return tracingRedissonHelper.prepareRFuture(span, () -> longAdder.sumAsync(timeout, timeUnit)); 77 | } 78 | 79 | @Override 80 | public RFuture resetAsync() { 81 | Span span = tracingRedissonHelper.buildSpan("resetAsync", longAdder); 82 | return tracingRedissonHelper.prepareRFuture(span, longAdder::resetAsync); 83 | } 84 | 85 | @Override 86 | public RFuture resetAsync(long timeout, TimeUnit timeUnit) { 87 | Span span = tracingRedissonHelper.buildSpan("resetAsync", longAdder); 88 | span.setTag("timeout", timeout); 89 | span.setTag("timeUnit", nullable(timeUnit)); 90 | return tracingRedissonHelper 91 | .prepareRFuture(span, () -> longAdder.resetAsync(timeout, timeUnit)); 92 | } 93 | 94 | @Override 95 | public void destroy() { 96 | Span span = tracingRedissonHelper.buildSpan("destroy", longAdder); 97 | tracingRedissonHelper.decorate(span, longAdder::destroy); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRMapReduce.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import java.util.concurrent.TimeUnit; 17 | import org.redisson.api.mapreduce.RMapReduce; 18 | import org.redisson.api.mapreduce.RMapper; 19 | import org.redisson.api.mapreduce.RReducer; 20 | 21 | public class TracingRMapReduce extends 22 | TracingRMapReduceExecutor implements 23 | RMapReduce { 24 | private final RMapReduce mapReduce; 25 | private final TracingRedissonHelper tracingRedissonHelper; 26 | 27 | public TracingRMapReduce(RMapReduce mapReduce, 28 | TracingRedissonHelper tracingRedissonHelper) { 29 | super(mapReduce, tracingRedissonHelper); 30 | this.mapReduce = mapReduce; 31 | this.tracingRedissonHelper = tracingRedissonHelper; 32 | } 33 | 34 | @Override 35 | public RMapReduce timeout(long timeout, TimeUnit unit) { 36 | return new TracingRMapReduce<>(mapReduce.timeout(timeout, unit), tracingRedissonHelper); 37 | } 38 | 39 | @Override 40 | public RMapReduce mapper( 41 | RMapper mapper) { 42 | return new TracingRMapReduce<>(mapReduce.mapper(mapper), tracingRedissonHelper); 43 | } 44 | 45 | @Override 46 | public RMapReduce reducer( 47 | RReducer reducer) { 48 | return new TracingRMapReduce<>(mapReduce.reducer(reducer), tracingRedissonHelper); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRMapReduceExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.Map; 20 | import org.redisson.api.RFuture; 21 | import org.redisson.api.mapreduce.RCollator; 22 | import org.redisson.api.mapreduce.RMapReduceExecutor; 23 | 24 | public class TracingRMapReduceExecutor implements 25 | RMapReduceExecutor { 26 | private final RMapReduceExecutor executor; 27 | private final TracingRedissonHelper tracingRedissonHelper; 28 | 29 | public TracingRMapReduceExecutor(RMapReduceExecutor executor, 30 | TracingRedissonHelper tracingRedissonHelper) { 31 | this.executor = executor; 32 | this.tracingRedissonHelper = tracingRedissonHelper; 33 | } 34 | 35 | @Override 36 | public Map execute() { 37 | Span span = tracingRedissonHelper.buildSpan("execute"); 38 | return tracingRedissonHelper.decorate(span, () -> executor.execute()); 39 | } 40 | 41 | @Override 42 | public RFuture> executeAsync() { 43 | Span span = tracingRedissonHelper.buildSpan("executeAsync"); 44 | return tracingRedissonHelper.prepareRFuture(span, executor::executeAsync); 45 | } 46 | 47 | @Override 48 | public void execute(String resultMapName) { 49 | Span span = tracingRedissonHelper.buildSpan("execute"); 50 | span.setTag("resultMapName", nullable(resultMapName)); 51 | tracingRedissonHelper.decorate(span, () -> executor.execute(resultMapName)); 52 | } 53 | 54 | @Override 55 | public RFuture executeAsync(String resultMapName) { 56 | Span span = tracingRedissonHelper.buildSpan("executeAsync"); 57 | span.setTag("resultMapName", nullable(resultMapName)); 58 | return tracingRedissonHelper.prepareRFuture(span, () -> executor.executeAsync(resultMapName)); 59 | } 60 | 61 | @Override 62 | public R execute(RCollator collator) { 63 | Span span = tracingRedissonHelper.buildSpan("execute"); 64 | span.setTag("collator", nullable(collator)); 65 | return tracingRedissonHelper.decorate(span, () -> executor.execute(collator)); 66 | } 67 | 68 | @Override 69 | public RFuture executeAsync(RCollator collator) { 70 | Span span = tracingRedissonHelper.buildSpan("executeAsync"); 71 | span.setTag("collator", nullable(collator)); 72 | return tracingRedissonHelper.prepareRFuture(span, () -> executor.executeAsync(collator)); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRPriorityBlockingDeque.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.Comparator; 20 | import java.util.stream.Stream; 21 | import org.redisson.api.RPriorityBlockingDeque; 22 | 23 | public class TracingRPriorityBlockingDeque extends TracingRBlockingDeque implements 24 | RPriorityBlockingDeque { 25 | private final RPriorityBlockingDeque deque; 26 | private final TracingRedissonHelper tracingRedissonHelper; 27 | 28 | public TracingRPriorityBlockingDeque(RPriorityBlockingDeque deque, 29 | TracingRedissonHelper tracingRedissonHelper) { 30 | super(deque, tracingRedissonHelper); 31 | this.deque = deque; 32 | this.tracingRedissonHelper = tracingRedissonHelper; 33 | } 34 | 35 | @Override 36 | public Comparator comparator() { 37 | return deque.comparator(); 38 | } 39 | 40 | @Override 41 | public boolean trySetComparator(Comparator comparator) { 42 | Span span = tracingRedissonHelper.buildSpan("trySetComparator", deque); 43 | span.setTag("comparator", nullable(comparator)); 44 | return tracingRedissonHelper.decorate(span, () -> deque.trySetComparator(comparator)); 45 | } 46 | 47 | @Override 48 | public Stream descendingStream() { 49 | Span span = tracingRedissonHelper.buildSpan("descendingStream", deque); 50 | return tracingRedissonHelper.decorate(span, deque::descendingStream); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRPriorityBlockingQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.Comparator; 20 | import org.redisson.api.RPriorityBlockingQueue; 21 | 22 | public class TracingRPriorityBlockingQueue extends TracingRBlockingQueue implements 23 | RPriorityBlockingQueue { 24 | private final RPriorityBlockingQueue queue; 25 | private final TracingRedissonHelper tracingRedissonHelper; 26 | 27 | public TracingRPriorityBlockingQueue(RPriorityBlockingQueue queue, 28 | TracingRedissonHelper tracingRedissonHelper) { 29 | super(queue, tracingRedissonHelper); 30 | this.queue = queue; 31 | this.tracingRedissonHelper = tracingRedissonHelper; 32 | } 33 | 34 | @Override 35 | public Comparator comparator() { 36 | return queue.comparator(); 37 | } 38 | 39 | @Override 40 | public boolean trySetComparator(Comparator comparator) { 41 | Span span = tracingRedissonHelper.buildSpan("trySetComparator", queue); 42 | span.setTag("comparator", nullable(comparator)); 43 | return tracingRedissonHelper.decorate(span, () -> queue.trySetComparator(comparator)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRReadWriteLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import org.redisson.api.RLock; 17 | import org.redisson.api.RReadWriteLock; 18 | 19 | public class TracingRReadWriteLock implements RReadWriteLock { 20 | private final RReadWriteLock lock; 21 | private final TracingRedissonHelper tracingRedissonHelper; 22 | 23 | public TracingRReadWriteLock(RReadWriteLock lock, TracingRedissonHelper tracingRedissonHelper) { 24 | this.lock = lock; 25 | this.tracingRedissonHelper = tracingRedissonHelper; 26 | } 27 | 28 | @Override 29 | public RLock readLock() { 30 | return new TracingRLock(lock.readLock(), tracingRedissonHelper); 31 | } 32 | 33 | @Override 34 | public RLock writeLock() { 35 | return new TracingRLock(lock.writeLock(), tracingRedissonHelper); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRRingBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import io.opentracing.Span; 17 | import org.redisson.api.RFuture; 18 | import org.redisson.api.RRingBuffer; 19 | 20 | public class TracingRRingBuffer extends TracingRQueue implements RRingBuffer { 21 | private final RRingBuffer ringBuffer; 22 | private final TracingRedissonHelper tracingRedissonHelper; 23 | 24 | public TracingRRingBuffer(RRingBuffer ringBuffer, 25 | TracingRedissonHelper tracingRedissonHelper) { 26 | super(ringBuffer, tracingRedissonHelper); 27 | this.ringBuffer = ringBuffer; 28 | this.tracingRedissonHelper = tracingRedissonHelper; 29 | } 30 | 31 | @Override 32 | public boolean trySetCapacity(int capacity) { 33 | Span span = tracingRedissonHelper.buildSpan("trySetCapacity", ringBuffer); 34 | span.setTag("capacity", capacity); 35 | return tracingRedissonHelper.decorate(span, () -> ringBuffer.trySetCapacity(capacity)); 36 | } 37 | 38 | @Override 39 | public int remainingCapacity() { 40 | Span span = tracingRedissonHelper.buildSpan("remainingCapacity", ringBuffer); 41 | return tracingRedissonHelper.decorate(span, ringBuffer::remainingCapacity); 42 | } 43 | 44 | @Override 45 | public int capacity() { 46 | Span span = tracingRedissonHelper.buildSpan("capacity", ringBuffer); 47 | return tracingRedissonHelper.decorate(span, ringBuffer::capacity); 48 | } 49 | 50 | @Override 51 | public RFuture trySetCapacityAsync(int capacity) { 52 | Span span = tracingRedissonHelper.buildSpan("trySetCapacityAsync", ringBuffer); 53 | span.setTag("capacity", capacity); 54 | return tracingRedissonHelper 55 | .prepareRFuture(span, () -> ringBuffer.trySetCapacityAsync(capacity)); 56 | } 57 | 58 | @Override 59 | public RFuture remainingCapacityAsync() { 60 | Span span = tracingRedissonHelper.buildSpan("remainingCapacityAsync", ringBuffer); 61 | return tracingRedissonHelper.prepareRFuture(span, ringBuffer::remainingCapacityAsync); 62 | } 63 | 64 | @Override 65 | public RFuture capacityAsync() { 66 | Span span = tracingRedissonHelper.buildSpan("capacityAsync", ringBuffer); 67 | return tracingRedissonHelper.prepareRFuture(span, ringBuffer::capacityAsync); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRSetMultimap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.Map.Entry; 20 | import java.util.Set; 21 | import org.redisson.api.RSet; 22 | import org.redisson.api.RSetMultimap; 23 | 24 | public class TracingRSetMultimap extends TracingRMultimap implements 25 | RSetMultimap { 26 | private final RSetMultimap set; 27 | private final TracingRedissonHelper tracingRedissonHelper; 28 | 29 | public TracingRSetMultimap(RSetMultimap set, TracingRedissonHelper tracingRedissonHelper) { 30 | super(set, tracingRedissonHelper); 31 | this.set = set; 32 | this.tracingRedissonHelper = tracingRedissonHelper; 33 | } 34 | 35 | @Override 36 | public RSet get(K key) { 37 | Span span = tracingRedissonHelper.buildSpan("get", set); 38 | span.setTag("key", nullable(key)); 39 | return tracingRedissonHelper 40 | .decorate(span, () -> new TracingRSet<>(set.get(key), tracingRedissonHelper)); 41 | } 42 | 43 | @Override 44 | public Set getAll(K key) { 45 | Span span = tracingRedissonHelper.buildSpan("getAll", set); 46 | span.setTag("key", nullable(key)); 47 | return tracingRedissonHelper.decorate(span, () -> set.getAll(key)); 48 | } 49 | 50 | @Override 51 | public Set removeAll(Object key) { 52 | Span span = tracingRedissonHelper.buildSpan("removeAll", set); 53 | span.setTag("key", nullable(key)); 54 | return tracingRedissonHelper.decorate(span, () -> set.removeAll(key)); 55 | } 56 | 57 | @Override 58 | public Set replaceValues(K key, Iterable values) { 59 | Span span = tracingRedissonHelper.buildSpan("replaceValues", set); 60 | span.setTag("key", nullable(key)); 61 | span.setTag("values", nullable(values)); 62 | return tracingRedissonHelper.decorate(span, () -> set.replaceValues(key, values)); 63 | } 64 | 65 | @Override 66 | public Set> entries() { 67 | Span span = tracingRedissonHelper.buildSpan("entries", set); 68 | return tracingRedissonHelper.decorate(span, set::entries); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRSetMultimapCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.concurrent.TimeUnit; 20 | import org.redisson.api.RFuture; 21 | import org.redisson.api.RSetMultimapCache; 22 | 23 | public class TracingRSetMultimapCache extends TracingRSetMultimap implements 24 | RSetMultimapCache { 25 | private final RSetMultimapCache cache; 26 | private final TracingRedissonHelper tracingRedissonHelper; 27 | 28 | public TracingRSetMultimapCache(RSetMultimapCache cache, 29 | TracingRedissonHelper tracingRedissonHelper) { 30 | super(cache, tracingRedissonHelper); 31 | this.cache = cache; 32 | this.tracingRedissonHelper = tracingRedissonHelper; 33 | } 34 | 35 | @Override 36 | public boolean expireKey(K key, long timeToLive, TimeUnit timeUnit) { 37 | Span span = tracingRedissonHelper.buildSpan("expireKey", cache); 38 | span.setTag("key", nullable(key)); 39 | span.setTag("timeToLive", timeToLive); 40 | span.setTag("timeUnit", nullable(timeUnit)); 41 | return tracingRedissonHelper.decorate(span, () -> cache.expireKey(key, timeToLive, timeUnit)); 42 | } 43 | 44 | @Override 45 | public RFuture expireKeyAsync(K key, long timeToLive, TimeUnit timeUnit) { 46 | Span span = tracingRedissonHelper.buildSpan("expireKeyAsync", cache); 47 | span.setTag("key", nullable(key)); 48 | span.setTag("timeToLive", timeToLive); 49 | span.setTag("timeUnit", nullable(timeUnit)); 50 | return tracingRedissonHelper 51 | .prepareRFuture(span, () -> cache.expireKeyAsync(key, timeToLive, timeUnit)); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRTransferQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import static io.opentracing.contrib.redis.common.TracingHelper.nullable; 17 | 18 | import io.opentracing.Span; 19 | import java.util.concurrent.TimeUnit; 20 | import org.redisson.api.RFuture; 21 | import org.redisson.api.RTransferQueue; 22 | 23 | public class TracingRTransferQueue extends TracingRBlockingQueue implements 24 | RTransferQueue { 25 | private final RTransferQueue queue; 26 | private final TracingRedissonHelper tracingRedissonHelper; 27 | 28 | public TracingRTransferQueue(RTransferQueue queue, 29 | TracingRedissonHelper tracingRedissonHelper) { 30 | super(queue, tracingRedissonHelper); 31 | this.queue = queue; 32 | this.tracingRedissonHelper = tracingRedissonHelper; 33 | } 34 | 35 | @Override 36 | public boolean tryTransfer(V v) { 37 | Span span = tracingRedissonHelper.buildSpan("tryTransfer", queue); 38 | span.setTag("element", nullable(v)); 39 | return tracingRedissonHelper.decorate(span, () -> queue.tryTransfer(v)); 40 | } 41 | 42 | @Override 43 | public void transfer(V v) throws InterruptedException { 44 | Span span = tracingRedissonHelper.buildSpan("transfer", queue); 45 | span.setTag("element", nullable(v)); 46 | tracingRedissonHelper.decorateThrowing(span, () -> queue.transfer(v)); 47 | } 48 | 49 | @Override 50 | public boolean tryTransfer(V v, long timeout, TimeUnit unit) throws InterruptedException { 51 | Span span = tracingRedissonHelper.buildSpan("tryTransfer", queue); 52 | span.setTag("element", nullable(v)); 53 | span.setTag("timeout", timeout); 54 | span.setTag("unit", nullable(unit)); 55 | return tracingRedissonHelper.decorateThrowing(span, () -> queue.tryTransfer(v, timeout, unit)); 56 | } 57 | 58 | @Override 59 | public boolean hasWaitingConsumer() { 60 | Span span = tracingRedissonHelper.buildSpan("hasWaitingConsumer", queue); 61 | return tracingRedissonHelper.decorateThrowing(span, () -> queue.hasWaitingConsumer()); 62 | } 63 | 64 | @Override 65 | public int getWaitingConsumerCount() { 66 | Span span = tracingRedissonHelper.buildSpan("getWaitingConsumerCount", queue); 67 | return tracingRedissonHelper.decorateThrowing(span, () -> queue.getWaitingConsumerCount()); 68 | } 69 | 70 | 71 | @Override 72 | public RFuture tryTransferAsync(V e) { 73 | Span span = tracingRedissonHelper.buildSpan("tryTransferAsync", queue); 74 | span.setTag("element", nullable(e)); 75 | return tracingRedissonHelper.prepareRFuture(span, () -> queue.tryTransferAsync(e)); 76 | } 77 | 78 | @Override 79 | public RFuture transferAsync(V e) { 80 | Span span = tracingRedissonHelper.buildSpan("transferAsync", queue); 81 | span.setTag("element", nullable(e)); 82 | return tracingRedissonHelper.prepareRFuture(span, () -> queue.transferAsync(e)); 83 | } 84 | 85 | @Override 86 | public RFuture tryTransferAsync(V e, long timeout, TimeUnit unit) { 87 | Span span = tracingRedissonHelper.buildSpan("tryTransferAsync", queue); 88 | span.setTag("element", nullable(e)); 89 | span.setTag("timeout", timeout); 90 | span.setTag("unit", nullable(unit)); 91 | return tracingRedissonHelper 92 | .prepareRFuture(span, () -> queue.tryTransferAsync(e, timeout, unit)); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /opentracing-redis-redisson/src/main/java/io/opentracing/contrib/redis/redisson/TracingRedissonHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.redisson; 15 | 16 | import io.opentracing.Scope; 17 | import io.opentracing.Span; 18 | import io.opentracing.contrib.redis.common.TracingConfiguration; 19 | import io.opentracing.contrib.redis.common.TracingHelper; 20 | import java.util.function.Supplier; 21 | import org.redisson.api.RFuture; 22 | import org.redisson.api.RObject; 23 | 24 | class TracingRedissonHelper extends TracingHelper { 25 | 26 | TracingRedissonHelper(TracingConfiguration tracingConfiguration) { 27 | super(tracingConfiguration); 28 | } 29 | 30 | Span buildSpan(String operationName, RObject rObject) { 31 | return buildSpan(operationName).setTag("name", rObject.getName()); 32 | } 33 | 34 | 35 | private RFuture continueScopeSpan(RFuture redisFuture) { 36 | Span span = tracer.activeSpan(); 37 | CompletableRFuture customRedisFuture = new CompletableRFuture<>(redisFuture); 38 | redisFuture.whenComplete((v, throwable) -> { 39 | try (Scope ignored = tracer.scopeManager().activate(span)) { 40 | if (throwable != null) { 41 | customRedisFuture.completeExceptionally(throwable); 42 | } else { 43 | customRedisFuture.complete(v); 44 | } 45 | } 46 | }); 47 | return customRedisFuture; 48 | } 49 | 50 | private RFuture setCompleteAction(RFuture future, Span span) { 51 | future.whenComplete((v, throwable) -> { 52 | if (throwable != null) { 53 | onError(throwable, span); 54 | } 55 | span.finish(); 56 | }); 57 | 58 | return future; 59 | } 60 | 61 | RFuture prepareRFuture(Span span, Supplier> futureSupplier) { 62 | RFuture future; 63 | try { 64 | future = futureSupplier.get(); 65 | } catch (Exception e) { 66 | onError(e, span); 67 | span.finish(); 68 | throw e; 69 | } 70 | 71 | return continueScopeSpan(setCompleteAction(future, span)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-spring-data 26 | OpenTracing Instrumentation for Spring Data Redis 1.x 27 | OpenTracing Instrumentation for Spring Data Redis 1.x classes 28 | 29 | 30 | 1.8.22.RELEASE 31 | 1.5.21.RELEASE 32 | 4.3.24.RELEASE 33 | 34 | 35 | 36 | 37 | io.opentracing.contrib 38 | opentracing-redis-common 39 | ${project.version} 40 | 41 | 42 | 43 | org.springframework.data 44 | spring-data-redis 45 | ${spring.data.redis.version} 46 | provided 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | ${spring-boot.version} 53 | test 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-starter-data-redis 59 | ${spring-boot.version} 60 | test 61 | 62 | 63 | 64 | org.springframework 65 | spring-test 66 | ${spring.version} 67 | test 68 | 69 | 70 | 71 | com.github.kstyrc 72 | embedded-redis 73 | test 74 | 75 | 76 | 77 | org.mockito 78 | mockito-core 79 | test 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/main/java/io/opentracing/contrib/redis/spring/data/connection/TracingRedisConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.connection; 15 | 16 | import io.opentracing.contrib.redis.common.TracingConfiguration; 17 | import org.springframework.dao.DataAccessException; 18 | import org.springframework.data.redis.connection.RedisClusterConnection; 19 | import org.springframework.data.redis.connection.RedisConnection; 20 | import org.springframework.data.redis.connection.RedisConnectionFactory; 21 | import org.springframework.data.redis.connection.RedisSentinelConnection; 22 | 23 | /** 24 | * OpenTracing instrumentation of a {@link RedisConnectionFactory}. 25 | *

26 | * This class delegates invocations to the given {@link RedisConnectionFactory}, returning 27 | * OpenTracing wrappers for {@link RedisConnection} and {@link RedisClusterConnection} only. 28 | * 29 | * @author Daniel del Castillo 30 | */ 31 | public class TracingRedisConnectionFactory implements RedisConnectionFactory { 32 | 33 | private final RedisConnectionFactory delegate; 34 | private final TracingConfiguration tracingConfiguration; 35 | 36 | public TracingRedisConnectionFactory(RedisConnectionFactory delegate, 37 | TracingConfiguration tracingConfiguration) { 38 | this.delegate = delegate; 39 | this.tracingConfiguration = tracingConfiguration; 40 | } 41 | 42 | @Override 43 | public RedisConnection getConnection() { 44 | // support cluster connection 45 | RedisConnection connection = this.delegate.getConnection(); 46 | if (connection instanceof RedisClusterConnection) { 47 | return new TracingRedisClusterConnection((RedisClusterConnection) connection, 48 | tracingConfiguration); 49 | } 50 | return new TracingRedisConnection(connection, tracingConfiguration); 51 | } 52 | 53 | @Override 54 | public RedisClusterConnection getClusterConnection() { 55 | return new TracingRedisClusterConnection(delegate.getClusterConnection(), tracingConfiguration); 56 | } 57 | 58 | @Override 59 | public boolean getConvertPipelineAndTxResults() { 60 | return delegate.getConvertPipelineAndTxResults(); 61 | } 62 | 63 | @Override 64 | public RedisSentinelConnection getSentinelConnection() { 65 | return new TracingRedisSentinelConnection(delegate.getSentinelConnection(), 66 | tracingConfiguration); 67 | } 68 | 69 | @Override 70 | public DataAccessException translateExceptionIfPossible(RuntimeException e) { 71 | return delegate.translateExceptionIfPossible(e); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/main/java/io/opentracing/contrib/redis/spring/data/connection/TracingRedisSentinelConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.connection; 15 | 16 | import io.opentracing.Span; 17 | import io.opentracing.contrib.redis.common.TracingConfiguration; 18 | import io.opentracing.contrib.redis.common.TracingHelper; 19 | import java.io.IOException; 20 | import java.util.Collection; 21 | import org.springframework.data.redis.connection.NamedNode; 22 | import org.springframework.data.redis.connection.RedisSentinelConnection; 23 | import org.springframework.data.redis.connection.RedisServer; 24 | 25 | public class TracingRedisSentinelConnection implements RedisSentinelConnection { 26 | private final RedisSentinelConnection redisSentinelConnection; 27 | private final TracingHelper helper; 28 | 29 | public TracingRedisSentinelConnection(RedisSentinelConnection redisSentinelConnection, 30 | TracingConfiguration configuration) { 31 | this.redisSentinelConnection = redisSentinelConnection; 32 | this.helper = new TracingHelper(configuration); 33 | } 34 | 35 | @Override 36 | public boolean isOpen() { 37 | Span span = helper.buildSpan("isOpen"); 38 | return helper.decorate(span, redisSentinelConnection::isOpen); 39 | } 40 | 41 | @Override 42 | public void failover(NamedNode master) { 43 | Span span = helper.buildSpan("failover"); 44 | helper.decorate(span, () -> redisSentinelConnection.failover(master)); 45 | } 46 | 47 | @Override 48 | public Collection masters() { 49 | Span span = helper.buildSpan("masters"); 50 | return helper.decorate(span, redisSentinelConnection::masters); 51 | } 52 | 53 | @Override 54 | public Collection slaves(NamedNode master) { 55 | Span span = helper.buildSpan("slaves"); 56 | return helper.decorate(span, () -> redisSentinelConnection.slaves(master)); 57 | } 58 | 59 | @Override 60 | public void remove(NamedNode master) { 61 | Span span = helper.buildSpan("remove"); 62 | helper.decorate(span, () -> redisSentinelConnection.remove(master)); 63 | } 64 | 65 | @Override 66 | public void monitor(RedisServer master) { 67 | Span span = helper.buildSpan("monitor"); 68 | helper.decorate(span, () -> redisSentinelConnection.monitor(master)); 69 | } 70 | 71 | @Override 72 | public void close() throws IOException { 73 | Span span = helper.buildSpan("close"); 74 | helper.decorateThrowing(span, () -> redisSentinelConnection.close()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/test/java/io/opentracing/contrib/redis/spring/data/connection/AssertionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.connection; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertTrue; 18 | 19 | import io.opentracing.Scope; 20 | import io.opentracing.mock.MockSpan; 21 | import io.opentracing.mock.MockTracer; 22 | import io.opentracing.tag.Tags; 23 | import java.util.Optional; 24 | 25 | /** 26 | * @author Daniel del Castillo 27 | */ 28 | final class AssertionUtils { 29 | 30 | /** 31 | * Make sure we get one span once we execute a Redis command. 32 | */ 33 | static void commandCreatesNewSpan(MockTracer tracer, String commandName, Runnable command) { 34 | command.run(); 35 | assertEquals(1, tracer.finishedSpans().size()); 36 | assertEquals(commandName, tracer.finishedSpans().get(0).operationName()); 37 | tracer.reset(); 38 | } 39 | 40 | /** 41 | * Make sure that a span is created when an active span exists joins the active 42 | */ 43 | static void commandSpanJoinsActiveSpan(MockTracer tracer, Runnable command) { 44 | final MockSpan parent = tracer.buildSpan("parent").start(); 45 | try (Scope ignored = tracer.activateSpan(parent)) { 46 | command.run(); 47 | assertEquals(1, tracer.finishedSpans().size()); 48 | } 49 | parent.finish(); 50 | 51 | assertEquals(2, tracer.finishedSpans().size()); 52 | Optional redisSpan = tracer.finishedSpans().stream() 53 | .filter((s) -> "java-redis".equals(s.tags().get(Tags.COMPONENT.getKey()))).findFirst(); 54 | 55 | Optional parentSpan = 56 | tracer.finishedSpans().stream().filter((s) -> "parent".equals(s.operationName())) 57 | .findFirst(); 58 | 59 | assertTrue(redisSpan.isPresent()); 60 | assertTrue(parentSpan.isPresent()); 61 | 62 | assertEquals(redisSpan.get().context().traceId(), parentSpan.get().context().traceId()); 63 | assertEquals(redisSpan.get().parentId(), parentSpan.get().context().spanId()); 64 | } 65 | 66 | private AssertionUtils() { 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/test/java/io/opentracing/contrib/redis/spring/data/connection/MockConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.connection; 15 | 16 | import static org.mockito.Mockito.mock; 17 | import static org.mockito.Mockito.when; 18 | 19 | import io.opentracing.contrib.redis.common.TracingConfiguration; 20 | import io.opentracing.mock.MockTracer; 21 | import org.springframework.context.annotation.Bean; 22 | import org.springframework.context.annotation.Configuration; 23 | import org.springframework.data.redis.connection.RedisClusterConnection; 24 | import org.springframework.data.redis.connection.RedisConnection; 25 | import org.springframework.data.redis.connection.RedisConnectionFactory; 26 | 27 | /** 28 | * @author Daniel del Castillo 29 | */ 30 | @Configuration 31 | public class MockConfiguration { 32 | 33 | @Bean 34 | public MockTracer mockTracer() { 35 | return new MockTracer(); 36 | } 37 | 38 | @Bean 39 | public RedisConnection mockRedisConnection() { 40 | return mock(RedisConnection.class); 41 | } 42 | 43 | @Bean 44 | public RedisClusterConnection mockRedisClusterConnection() { 45 | return mock(RedisClusterConnection.class); 46 | } 47 | 48 | @Bean 49 | public RedisConnectionFactory redisConnectionFactory() { 50 | RedisConnectionFactory factory = mock(RedisConnectionFactory.class); 51 | when(factory.getConnection()) 52 | .thenReturn(new TracingRedisConnection(mockRedisConnection(), 53 | new TracingConfiguration.Builder(mockTracer()).traceWithActiveSpanOnly(false).build())); 54 | when(factory.getClusterConnection()).thenReturn( 55 | new TracingRedisClusterConnection(mockRedisClusterConnection(), 56 | new TracingConfiguration.Builder(mockTracer()).traceWithActiveSpanOnly(false).build())); 57 | return factory; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/test/java/io/opentracing/contrib/redis/spring/data/connection/TracingRedisConnectionFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.connection; 15 | 16 | import static org.junit.Assert.assertTrue; 17 | import static org.mockito.Mockito.mock; 18 | import static org.mockito.Mockito.verify; 19 | import static org.mockito.Mockito.when; 20 | 21 | import io.opentracing.Tracer; 22 | import io.opentracing.contrib.redis.common.TracingConfiguration; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | import org.junit.runner.RunWith; 26 | import org.mockito.Mock; 27 | import org.mockito.junit.MockitoJUnitRunner; 28 | import org.springframework.data.redis.connection.RedisClusterConnection; 29 | import org.springframework.data.redis.connection.RedisConnection; 30 | import org.springframework.data.redis.connection.RedisConnectionFactory; 31 | import org.springframework.data.redis.connection.RedisSentinelConnection; 32 | 33 | /** 34 | * @author Daniel del Castillo 35 | */ 36 | @RunWith(MockitoJUnitRunner.class) 37 | public class TracingRedisConnectionFactoryTest { 38 | 39 | @Mock 40 | private Tracer tracer; 41 | 42 | @Mock 43 | private RedisConnectionFactory delegate; 44 | 45 | private TracingRedisConnectionFactory connectionFactory; 46 | 47 | @Before 48 | public void init() { 49 | connectionFactory = new TracingRedisConnectionFactory(delegate, 50 | new TracingConfiguration.Builder(tracer).traceWithActiveSpanOnly(false).build()); 51 | } 52 | 53 | @Test 54 | public void connectionIsTracingRedisConnection() { 55 | RedisConnection connection = connectionFactory.getConnection(); 56 | verify(delegate).getConnection(); 57 | assertTrue(connection instanceof TracingRedisConnection); 58 | } 59 | 60 | @Test 61 | public void connectionIsTracingRedisClusterConnection() { 62 | RedisClusterConnection connection = connectionFactory.getClusterConnection(); 63 | verify(delegate).getClusterConnection(); 64 | assertTrue(connection instanceof TracingRedisClusterConnection); 65 | } 66 | 67 | @Test 68 | public void delegatesCallToGetConvertPipelineAndTxResults() { 69 | connectionFactory.getConvertPipelineAndTxResults(); 70 | verify(delegate).getConvertPipelineAndTxResults(); 71 | } 72 | 73 | @Test 74 | public void delegatesCallToGetSentinelConnection() { 75 | RedisSentinelConnection connection = connectionFactory.getSentinelConnection(); 76 | verify(delegate).getSentinelConnection(); 77 | assertTrue(connection instanceof TracingRedisSentinelConnection); 78 | } 79 | 80 | @Test 81 | public void delegatesCallToTranslateExceptionIfPossible() { 82 | RuntimeException e = mock(RuntimeException.class); 83 | delegate.translateExceptionIfPossible(e); 84 | verify(delegate).translateExceptionIfPossible(e); 85 | } 86 | 87 | @Test 88 | public void delegatesClusterConnectionIfCluster() { 89 | RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); 90 | when(connectionFactory.getConnection()).thenReturn(mock(RedisClusterConnection.class)); 91 | TracingRedisConnectionFactory tracingConnectionFactory = new TracingRedisConnectionFactory( 92 | connectionFactory, 93 | new TracingConfiguration.Builder(tracer).traceWithActiveSpanOnly(false).build()); 94 | assertTrue(tracingConnectionFactory.getConnection() instanceof RedisClusterConnection); 95 | } 96 | 97 | } -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/test/java/io/opentracing/contrib/redis/spring/data/processor/RedisConnectionFactoryBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.processor; 15 | 16 | import io.opentracing.Tracer; 17 | import io.opentracing.contrib.redis.common.TracingConfiguration; 18 | import io.opentracing.contrib.redis.spring.data.connection.TracingRedisConnectionFactory; 19 | import org.springframework.beans.BeansException; 20 | import org.springframework.beans.factory.config.BeanPostProcessor; 21 | import org.springframework.data.redis.connection.RedisConnectionFactory; 22 | import org.springframework.stereotype.Component; 23 | 24 | @Component 25 | public class RedisConnectionFactoryBeanPostProcessor implements BeanPostProcessor { 26 | 27 | private Tracer tracer; 28 | 29 | public RedisConnectionFactoryBeanPostProcessor(Tracer tracer) { 30 | this.tracer = tracer; 31 | } 32 | 33 | 34 | @Override 35 | public Object postProcessBeforeInitialization(Object bean, String beanName) 36 | throws BeansException { 37 | return bean; 38 | } 39 | 40 | @Override 41 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 42 | if (bean instanceof RedisConnectionFactory) { 43 | bean = new TracingRedisConnectionFactory((RedisConnectionFactory) bean, 44 | new TracingConfiguration.Builder(tracer).traceWithActiveSpanOnly(false).build()); 45 | } 46 | return bean; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/test/java/io/opentracing/contrib/redis/spring/data/processor/RedisConnectionFactoryBeanPostProcessorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.processor; 15 | 16 | import io.opentracing.Tracer; 17 | import io.opentracing.mock.MockTracer; 18 | import org.springframework.context.annotation.Bean; 19 | import org.springframework.context.annotation.ComponentScan; 20 | import org.springframework.context.annotation.Configuration; 21 | 22 | @Configuration 23 | @ComponentScan("io.opentracing.contrib.redis.spring.data.processor") 24 | public class RedisConnectionFactoryBeanPostProcessorConfiguration { 25 | @Bean 26 | public Tracer tracer() { 27 | return new MockTracer(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data/src/test/java/io/opentracing/contrib/redis/spring/data/processor/RedisConnectionFactoryBeanPostProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data.processor; 15 | 16 | import static org.junit.Assert.assertTrue; 17 | 18 | import io.opentracing.contrib.redis.spring.data.connection.TracingRedisConnectionFactory; 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 23 | import org.springframework.boot.test.context.SpringBootTest; 24 | import org.springframework.data.redis.connection.RedisConnectionFactory; 25 | import org.springframework.test.context.junit4.SpringRunner; 26 | 27 | @RunWith(SpringRunner.class) 28 | @SpringBootTest(classes = RedisConnectionFactoryBeanPostProcessorConfiguration.class) 29 | @EnableAutoConfiguration 30 | public class RedisConnectionFactoryBeanPostProcessorTest { 31 | 32 | @Autowired 33 | private RedisConnectionFactory redisConnectionFactory; 34 | 35 | @Test 36 | public void test() { 37 | assertTrue(redisConnectionFactory instanceof TracingRedisConnectionFactory); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | opentracing-redis-parent 20 | io.opentracing.contrib 21 | 0.1.17-SNAPSHOT 22 | 23 | 4.0.0 24 | 25 | opentracing-redis-spring-data2 26 | OpenTracing Instrumentation for Spring Data Redis 2.x 27 | OpenTracing Instrumentation for Spring Redis classes 28 | 29 | 30 | 2.2.4.RELEASE 31 | 2.2.4.RELEASE 32 | 5.2.3.RELEASE 33 | 34 | 35 | 36 | 37 | 38 | io.opentracing.contrib 39 | opentracing-redis-common 40 | ${project.version} 41 | 42 | 43 | 44 | org.springframework.data 45 | spring-data-redis 46 | ${spring.data.redis.version} 47 | provided 48 | 49 | 50 | 51 | io.projectreactor 52 | reactor-core 53 | 3.1.9.RELEASE 54 | provided 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | ${spring-boot.version} 61 | test 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-data-redis 67 | ${spring-boot.version} 68 | test 69 | 70 | 71 | 72 | org.springframework 73 | spring-test 74 | ${spring.version} 75 | test 76 | 77 | 78 | 79 | com.github.kstyrc 80 | embedded-redis 81 | test 82 | 83 | 84 | 85 | org.mockito 86 | mockito-core 87 | test 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisSentinelConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.connection; 15 | 16 | import io.opentracing.Span; 17 | import io.opentracing.contrib.redis.common.TracingConfiguration; 18 | import io.opentracing.contrib.redis.common.TracingHelper; 19 | import java.io.IOException; 20 | import java.util.Collection; 21 | import org.springframework.data.redis.connection.NamedNode; 22 | import org.springframework.data.redis.connection.RedisSentinelConnection; 23 | import org.springframework.data.redis.connection.RedisServer; 24 | 25 | public class TracingRedisSentinelConnection implements RedisSentinelConnection { 26 | private final RedisSentinelConnection redisSentinelConnection; 27 | private final TracingHelper helper; 28 | 29 | public TracingRedisSentinelConnection(RedisSentinelConnection redisSentinelConnection, 30 | TracingConfiguration configuration) { 31 | this.redisSentinelConnection = redisSentinelConnection; 32 | this.helper = new TracingHelper(configuration); 33 | } 34 | 35 | @Override 36 | public boolean isOpen() { 37 | Span span = helper.buildSpan("isOpen"); 38 | return helper.decorate(span, redisSentinelConnection::isOpen); 39 | } 40 | 41 | @Override 42 | public void failover(NamedNode master) { 43 | Span span = helper.buildSpan("failover"); 44 | helper.decorate(span, () -> redisSentinelConnection.failover(master)); 45 | } 46 | 47 | @Override 48 | public Collection masters() { 49 | Span span = helper.buildSpan("masters"); 50 | return helper.decorate(span, redisSentinelConnection::masters); 51 | } 52 | 53 | @Override 54 | public Collection slaves(NamedNode master) { 55 | Span span = helper.buildSpan("slaves"); 56 | return helper.decorate(span, () -> redisSentinelConnection.slaves(master)); 57 | } 58 | 59 | @Override 60 | public void remove(NamedNode master) { 61 | Span span = helper.buildSpan("remove"); 62 | helper.decorate(span, () -> redisSentinelConnection.remove(master)); 63 | } 64 | 65 | @Override 66 | public void monitor(RedisServer master) { 67 | Span span = helper.buildSpan("monitor"); 68 | helper.decorate(span, () -> redisSentinelConnection.monitor(master)); 69 | } 70 | 71 | @Override 72 | public void close() throws IOException { 73 | Span span = helper.buildSpan("close"); 74 | helper.decorateThrowing(span, () -> redisSentinelConnection.close()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/connection/AssertionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.connection; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertTrue; 18 | 19 | import io.opentracing.Scope; 20 | import io.opentracing.mock.MockSpan; 21 | import io.opentracing.mock.MockTracer; 22 | import io.opentracing.tag.Tags; 23 | import java.util.Optional; 24 | 25 | /** 26 | * @author Daniel del Castillo 27 | */ 28 | final class AssertionUtils { 29 | 30 | /** 31 | * Make sure we get one span once we execute a Redis command. 32 | */ 33 | static void commandCreatesNewSpan(MockTracer tracer, String commandName, Runnable command) { 34 | command.run(); 35 | assertEquals(1, tracer.finishedSpans().size()); 36 | assertEquals(commandName, tracer.finishedSpans().get(0).operationName()); 37 | tracer.reset(); 38 | } 39 | 40 | /** 41 | * Make sure that a span is created when an active span exists joins the active 42 | */ 43 | static void commandSpanJoinsActiveSpan(MockTracer tracer, Runnable command) { 44 | final MockSpan parent = tracer.buildSpan("parent").start(); 45 | try (Scope ignored = tracer.activateSpan(parent)) { 46 | command.run(); 47 | assertEquals(1, tracer.finishedSpans().size()); 48 | } 49 | parent.finish(); 50 | 51 | assertEquals(2, tracer.finishedSpans().size()); 52 | Optional redisSpan = tracer.finishedSpans().stream() 53 | .filter((s) -> "java-redis".equals(s.tags().get(Tags.COMPONENT.getKey()))).findFirst(); 54 | 55 | Optional parentSpan = 56 | tracer.finishedSpans().stream().filter((s) -> "parent".equals(s.operationName())) 57 | .findFirst(); 58 | 59 | assertTrue(redisSpan.isPresent()); 60 | assertTrue(parentSpan.isPresent()); 61 | 62 | assertEquals(redisSpan.get().context().traceId(), parentSpan.get().context().traceId()); 63 | assertEquals(redisSpan.get().parentId(), parentSpan.get().context().spanId()); 64 | } 65 | 66 | private AssertionUtils() { 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/connection/MockConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.connection; 15 | 16 | import static org.mockito.Mockito.mock; 17 | import static org.mockito.Mockito.when; 18 | 19 | import io.opentracing.contrib.redis.common.TracingConfiguration; 20 | import io.opentracing.mock.MockTracer; 21 | import org.springframework.context.annotation.Bean; 22 | import org.springframework.context.annotation.Configuration; 23 | import org.springframework.data.redis.connection.RedisClusterConnection; 24 | import org.springframework.data.redis.connection.RedisConnection; 25 | import org.springframework.data.redis.connection.RedisConnectionFactory; 26 | 27 | /** 28 | * @author Daniel del Castillo 29 | */ 30 | @Configuration 31 | public class MockConfiguration { 32 | 33 | @Bean 34 | public MockTracer mockTracer() { 35 | return new MockTracer(); 36 | } 37 | 38 | @Bean 39 | public RedisConnection mockRedisConnection() { 40 | return mock(RedisConnection.class); 41 | } 42 | 43 | @Bean 44 | public RedisClusterConnection mockRedisClusterConnection() { 45 | return mock(RedisClusterConnection.class); 46 | } 47 | 48 | @Bean 49 | public RedisConnectionFactory redisConnectionFactory() { 50 | RedisConnectionFactory factory = mock(RedisConnectionFactory.class); 51 | when(factory.getConnection()) 52 | .thenReturn(new TracingRedisConnection(mockRedisConnection(), 53 | new TracingConfiguration.Builder(mockTracer()).traceWithActiveSpanOnly(false).build())); 54 | when(factory.getClusterConnection()).thenReturn( 55 | new TracingRedisClusterConnection(mockRedisClusterConnection(), 56 | new TracingConfiguration.Builder(mockTracer()).traceWithActiveSpanOnly(false).build())); 57 | return factory; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisConnectionFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.connection; 15 | 16 | import static org.junit.Assert.assertTrue; 17 | import static org.mockito.Mockito.mock; 18 | import static org.mockito.Mockito.verify; 19 | import static org.mockito.Mockito.when; 20 | 21 | import io.opentracing.Tracer; 22 | import io.opentracing.contrib.redis.common.TracingConfiguration; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | import org.junit.runner.RunWith; 26 | import org.mockito.Mock; 27 | import org.mockito.junit.MockitoJUnitRunner; 28 | import org.springframework.data.redis.connection.RedisClusterConnection; 29 | import org.springframework.data.redis.connection.RedisConnection; 30 | import org.springframework.data.redis.connection.RedisConnectionFactory; 31 | import org.springframework.data.redis.connection.RedisSentinelConnection; 32 | 33 | /** 34 | * @author Daniel del Castillo 35 | */ 36 | @RunWith(MockitoJUnitRunner.class) 37 | public class TracingRedisConnectionFactoryTest { 38 | 39 | private @Mock 40 | Tracer tracer; 41 | private @Mock 42 | RedisConnectionFactory delegate; 43 | 44 | private TracingRedisConnectionFactory connectionFactory; 45 | 46 | @Before 47 | public void init() { 48 | connectionFactory = new TracingRedisConnectionFactory(delegate, 49 | new TracingConfiguration.Builder(tracer).traceWithActiveSpanOnly(false).build()); 50 | } 51 | 52 | @Test 53 | public void connectionIsTracingRedisConnection() { 54 | RedisConnection connection = connectionFactory.getConnection(); 55 | verify(delegate).getConnection(); 56 | assertTrue(connection instanceof TracingRedisConnection); 57 | } 58 | 59 | @Test 60 | public void connectionIsTracingRedisClusterConnection() { 61 | RedisClusterConnection connection = connectionFactory.getClusterConnection(); 62 | verify(delegate).getClusterConnection(); 63 | assertTrue(connection instanceof TracingRedisClusterConnection); 64 | } 65 | 66 | @Test 67 | public void delegatesCallToGetConvertPipelineAndTxResults() { 68 | connectionFactory.getConvertPipelineAndTxResults(); 69 | verify(delegate).getConvertPipelineAndTxResults(); 70 | } 71 | 72 | @Test 73 | public void delegatesCallToGetSentinelConnection() { 74 | RedisSentinelConnection connection = connectionFactory.getSentinelConnection(); 75 | verify(delegate).getSentinelConnection(); 76 | assertTrue(connection instanceof TracingRedisSentinelConnection); 77 | } 78 | 79 | @Test 80 | public void delegatesCallToTranslateExceptionIfPossible() { 81 | RuntimeException e = mock(RuntimeException.class); 82 | delegate.translateExceptionIfPossible(e); 83 | verify(delegate).translateExceptionIfPossible(e); 84 | } 85 | 86 | @Test 87 | public void delegatesClusterConnectionIfCluster() { 88 | RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class); 89 | when(connectionFactory.getConnection()).thenReturn(mock(RedisClusterConnection.class)); 90 | TracingRedisConnectionFactory tracingConnectionFactory = new TracingRedisConnectionFactory( 91 | connectionFactory, 92 | new TracingConfiguration.Builder(tracer).traceWithActiveSpanOnly(false).build()); 93 | assertTrue(tracingConnectionFactory.getConnection() instanceof RedisClusterConnection); 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/it/SpringDataRedisTestConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.it; 15 | 16 | import io.opentracing.contrib.redis.common.TracingConfiguration; 17 | import io.opentracing.contrib.redis.spring.data2.connection.TracingRedisConnectionFactory; 18 | import io.opentracing.mock.MockTracer; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.data.redis.connection.RedisConnectionFactory; 22 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; 23 | import org.springframework.data.redis.core.StringRedisTemplate; 24 | 25 | @Configuration 26 | public class SpringDataRedisTestConfiguration { 27 | 28 | @Bean 29 | public StringRedisTemplate stringRedisTemplate() { 30 | return new StringRedisTemplate(redisConnectionFactory()); 31 | } 32 | 33 | @Bean 34 | public MockTracer tracer() { 35 | return new MockTracer(); 36 | } 37 | 38 | @Bean 39 | public RedisConnectionFactory redisConnectionFactory() { 40 | LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(); 41 | lettuceConnectionFactory.afterPropertiesSet(); 42 | return new TracingRedisConnectionFactory(lettuceConnectionFactory, 43 | new TracingConfiguration.Builder(tracer()).build()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/it/TracingSpringDataRedisTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.it; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import io.opentracing.mock.MockSpan; 19 | import io.opentracing.mock.MockTracer; 20 | import java.util.List; 21 | import org.junit.AfterClass; 22 | import org.junit.Before; 23 | import org.junit.BeforeClass; 24 | import org.junit.Test; 25 | import org.junit.runner.RunWith; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.data.redis.core.StringRedisTemplate; 28 | import org.springframework.test.context.ContextConfiguration; 29 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 30 | import redis.embedded.RedisServer; 31 | 32 | @ContextConfiguration(classes = {SpringDataRedisTestConfiguration.class}) 33 | @RunWith(SpringJUnit4ClassRunner.class) 34 | public class TracingSpringDataRedisTest { 35 | private static RedisServer redisServer; 36 | 37 | @Autowired 38 | private StringRedisTemplate template; 39 | 40 | @Autowired 41 | private MockTracer tracer; 42 | 43 | @Before 44 | public void before() { 45 | tracer.reset(); 46 | } 47 | 48 | @BeforeClass 49 | public static void beforeClass() { 50 | redisServer = RedisServer.builder().setting("bind 127.0.0.1").build(); 51 | redisServer.start(); 52 | } 53 | 54 | @AfterClass 55 | public static void afterClass() { 56 | if (redisServer != null) { 57 | redisServer.stop(); 58 | } 59 | } 60 | 61 | @Test 62 | public void test() { 63 | template.opsForValue().set("key", "value"); 64 | assertEquals("value", template.opsForValue().get("key")); 65 | 66 | List spans = tracer.finishedSpans(); 67 | assertEquals(2, spans.size()); 68 | 69 | for (MockSpan span : spans) { 70 | assertEquals("key", span.tags().get("key")); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/processor/RedisConnectionFactoryBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.processor; 15 | 16 | import io.opentracing.Tracer; 17 | import io.opentracing.contrib.redis.common.TracingConfiguration; 18 | import io.opentracing.contrib.redis.spring.data2.connection.TracingRedisConnectionFactory; 19 | import org.springframework.beans.BeansException; 20 | import org.springframework.beans.factory.config.BeanPostProcessor; 21 | import org.springframework.data.redis.connection.RedisConnectionFactory; 22 | import org.springframework.stereotype.Component; 23 | 24 | @Component 25 | public class RedisConnectionFactoryBeanPostProcessor implements BeanPostProcessor { 26 | 27 | private Tracer tracer; 28 | 29 | public RedisConnectionFactoryBeanPostProcessor(Tracer tracer) { 30 | this.tracer = tracer; 31 | } 32 | 33 | @Override 34 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 35 | if (bean instanceof RedisConnectionFactory) { 36 | bean = new TracingRedisConnectionFactory((RedisConnectionFactory) bean, 37 | new TracingConfiguration.Builder(tracer).traceWithActiveSpanOnly(false).build()); 38 | } 39 | return bean; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/processor/RedisConnectionFactoryBeanPostProcessorConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.processor; 15 | 16 | import io.opentracing.Tracer; 17 | import io.opentracing.mock.MockTracer; 18 | import org.springframework.context.annotation.Bean; 19 | import org.springframework.context.annotation.ComponentScan; 20 | import org.springframework.context.annotation.Configuration; 21 | 22 | @Configuration 23 | @ComponentScan("io.opentracing.contrib.redis.spring.data2.processor") 24 | public class RedisConnectionFactoryBeanPostProcessorConfiguration { 25 | @Bean 26 | public Tracer tracer() { 27 | return new MockTracer(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/processor/RedisConnectionFactoryBeanPostProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 The OpenTracing Authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 | * in compliance with the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 | * or implied. See the License for the specific language governing permissions and limitations under 12 | * the License. 13 | */ 14 | package io.opentracing.contrib.redis.spring.data2.processor; 15 | 16 | import static org.junit.Assert.assertTrue; 17 | 18 | import io.opentracing.contrib.redis.spring.data2.connection.TracingRedisConnectionFactory; 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 23 | import org.springframework.boot.test.context.SpringBootTest; 24 | import org.springframework.data.redis.connection.RedisConnectionFactory; 25 | import org.springframework.test.context.junit4.SpringRunner; 26 | 27 | @RunWith(SpringRunner.class) 28 | @SpringBootTest(classes = RedisConnectionFactoryBeanPostProcessorConfiguration.class) 29 | @EnableAutoConfiguration 30 | public class RedisConnectionFactoryBeanPostProcessorTest { 31 | 32 | @Autowired 33 | private RedisConnectionFactory redisConnectionFactory; 34 | 35 | @Test 36 | public void test() { 37 | assertTrue(redisConnectionFactory instanceof TracingRedisConnectionFactory); 38 | } 39 | } 40 | --------------------------------------------------------------------------------