Skip to content

Commit

Permalink
Merge 494acf1 into 829e0cc
Browse files Browse the repository at this point in the history
  • Loading branch information
malafeev authored Dec 11, 2018
2 parents 829e0cc + 494acf1 commit e7b8518
Show file tree
Hide file tree
Showing 52 changed files with 11,310 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2017-2018 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.opentracing.contrib.redis.common;

@FunctionalInterface
public interface ThrowingSupplier<T extends Exception, V> {

V get() throws T;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;


public class TracingHelper {

public static final String COMPONENT_NAME = "java-redis";
public static final String DB_TYPE = "redis";
private final Tracer tracer;
private final boolean traceWithActiveSpanOnly;
private final Function<String, String> spanNameProvider;
Expand All @@ -51,7 +53,7 @@ private static SpanBuilder builder(String operationName, Tracer tracer,
return getNullSafeTracer(tracer).buildSpan(spanNameProvider.apply(operationName))
.withTag(Tags.COMPONENT.getKey(), COMPONENT_NAME)
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
.withTag(Tags.DB_TYPE.getKey(), "redis");
.withTag(Tags.DB_TYPE.getKey(), DB_TYPE);
}

public static Span buildSpan(String operationName, boolean traceWithActiveSpanOnly,
Expand Down Expand Up @@ -148,6 +150,13 @@ public static String toString(byte[][] array) {
return "[" + String.join(", ", list) + "]";
}

public static String collectionToString(Collection<?> collection) {
if (collection == null) {
return "";
}
return collection.stream().map(Object::toString).collect(Collectors.joining(", "));
}

public static String toString(Collection<byte[]> collection) {
if (collection == null) {
return "null";
Expand Down Expand Up @@ -193,9 +202,19 @@ public static <V> String toStringMap2(Map<byte[], V> map) {
return "{" + String.join(", ", list) + "}";
}

public <T> T decorate(Span span, Supplier<T> action) {
public static <K, V> String mapToString(Map<K, V> map) {
if (map == null) {
return "";
}
return map.entrySet()
.stream()
.map(entry -> entry.getKey() + " -> " + entry.getValue())
.collect(Collectors.joining(", "));
}

public <T> T decorate(Span span, Supplier<T> supplier) {
try (Scope ignore = getNullSafeTracer().scopeManager().activate(span, false)) {
return action.get();
return supplier.get();
} catch (Exception e) {
onError(e, span);
throw e;
Expand All @@ -211,7 +230,7 @@ public static Tracer getNullSafeTracer(final Tracer tracer) {
return tracer;
}

private Tracer getNullSafeTracer() {
public Tracer getNullSafeTracer() {
return getNullSafeTracer(tracer);
}

Expand All @@ -236,4 +255,16 @@ public <T extends Exception> void decorateThrowing(Span span, ThrowingAction<T>
span.finish();
}
}

public <T extends Exception, V> V decorateThrowing(Span span, ThrowingSupplier<T, V> supplier)
throws T {
try (Scope ignore = getNullSafeTracer().scopeManager().activate(span, false)) {
return supplier.get();
} catch (Exception e) {
onError(e, span);
throw e;
} finally {
span.finish();
}
}
}
2 changes: 2 additions & 0 deletions opentracing-redis-jedis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>opentracing-redis-jedis</artifactId>
<name>OpenTracing Instrumentation for Jedis</name>
<description>OpenTracing Instrumentation for Jedis</description>

<dependencies>

Expand Down
2 changes: 2 additions & 0 deletions opentracing-redis-jedis3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>opentracing-redis-jedis3</artifactId>
<name>OpenTracing Instrumentation for Jedis 3</name>
<description>OpenTracing Instrumentation for Jedis 3</description>

<dependencies>

Expand Down
2 changes: 1 addition & 1 deletion opentracing-redis-lettuce/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>opentracing-redis-lettuce</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<name>OpenTracing Instrumentation for Lettuce Redis Client</name>
<description>OpenTracing Instrumentation for Lettuce Redis Client</description>

<dependencies>
Expand Down
53 changes: 53 additions & 0 deletions opentracing-redis-redisson/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017-2018 The OpenTracing Authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing permissions and limitations under
the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>opentracing-redis-parent</artifactId>
<groupId>io.opentracing.contrib</groupId>
<version>0.0.14-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>opentracing-redis-redisson</artifactId>
<name>OpenTracing Instrumentation for Redisson</name>
<description>OpenTracing Instrumentation for Redisson</description>

<dependencies>

<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-redis-common</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.9.0</version>
</dependency>

<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2017-2018 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.opentracing.contrib.redis.redisson;

import io.netty.util.concurrent.FutureListener;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RFuture;

public class CompletableRFuture<T> extends CompletableFuture<T> implements RFuture<T> {
private RFuture<T> wrappedFuture;

public CompletableRFuture(RFuture<T> wrappedFuture) {
this.wrappedFuture = wrappedFuture;
}

@Override
public boolean isSuccess() {
return wrappedFuture.isSuccess();
}

@Override
public Throwable cause() {
return wrappedFuture.cause();
}

@Override
public T getNow() {
return wrappedFuture.getNow();
}

@Override
public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
return wrappedFuture.await(timeout, unit);
}

@Override
public boolean await(long timeoutMillis) throws InterruptedException {
return wrappedFuture.await(timeoutMillis);
}

@Override
public RFuture<T> addListener(FutureListener<? super T> listener) {
return wrappedFuture.addListener(listener);
}

@Override
public RFuture<T> addListeners(FutureListener<? super T>... listeners) {
return wrappedFuture.addListeners(listeners);
}

@Override
public RFuture<T> removeListener(FutureListener<? super T> listener) {
return wrappedFuture.removeListener(listener);
}

@Override
public RFuture<T> removeListeners(FutureListener<? super T>... listeners) {
return wrappedFuture.removeListeners(listeners);
}

@Override
public RFuture<T> sync() throws InterruptedException {
return wrappedFuture.sync();
}

@Override
public RFuture<T> syncUninterruptibly() {
return wrappedFuture.syncUninterruptibly();
}

@Override
public RFuture<T> await() throws InterruptedException {
return wrappedFuture.await();
}

@Override
public RFuture<T> awaitUninterruptibly() {
return wrappedFuture.awaitUninterruptibly();
}

@Override
public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
return wrappedFuture.awaitUninterruptibly(timeout, unit);
}

@Override
public boolean awaitUninterruptibly(long timeoutMillis) {
return wrappedFuture.awaitUninterruptibly(timeoutMillis);
}
}
Loading

0 comments on commit e7b8518

Please sign in to comment.