Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lettuce 5.2 instrumentation that uses lettuce's native tracing functionality. #535

Merged
merged 14 commits into from
Jun 18, 2020
1 change: 0 additions & 1 deletion gradle/enforcement/codenarc.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ ruleset {
regex = '^[a-z][\\$_a-zA-Z0-9]*$|^.*\\s.*$'
}
ObjectOverrideMisspelledMethodName
PackageName
ParameterName
PropertyName
VariableName {
Expand Down
12 changes: 1 addition & 11 deletions instrumentation/lettuce/lettuce-5.0/lettuce-5.0.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
anuraaga marked this conversation as resolved.
Show resolved Hide resolved
}

apply from: "$rootDir/gradle/instrumentation.gradle"
Expand All @@ -11,24 +10,15 @@ muzzle {
pass {
group = "io.lettuce"
module = "lettuce-core"
versions = "[5.0.0.RELEASE,)"
versions = "[5.0.0.RELEASE,5.1.0.RELEASE)"
assertInverse = true
}
}

testSets {
latestDepTest {
dirName = 'test'
}
}

dependencies {
compileOnly group: 'io.lettuce', name: 'lettuce-core', version: '5.0.0.RELEASE'
compileOnly group: 'io.lettuce', name: 'lettuce-core', version: '5.0.0.RELEASE'

testCompile group: 'com.github.kstyrc', name: 'embedded-redis', version: '0.6'
testCompile group: 'io.lettuce', name: 'lettuce-core', version: '5.0.0.RELEASE'
testCompile project(':instrumentation:reactor-3.1')

latestDepTestCompile group: 'io.lettuce', name: 'lettuce-core', version: '5.+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package io.opentelemetry.auto.instrumentation.lettuce.v5_0;

import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.google.auto.service.AutoService;
Expand All @@ -34,6 +36,11 @@ public LettuceAsyncCommandsInstrumentation() {
super("lettuce", "lettuce-5", "lettuce-5-async");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
return not(hasClassesNamed("io.lettuce.core.tracing.Tracing"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("io.lettuce.core.AbstractRedisAsyncCommands");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package io.opentelemetry.auto.instrumentation.lettuce.v5_0;

import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPrivate;
import static net.bytebuddy.matcher.ElementMatchers.nameEndsWith;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.returns;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

Expand All @@ -38,6 +40,11 @@ public LettuceClientInstrumentation() {
super("lettuce", "lettuce-5");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
return not(hasClassesNamed("io.lettuce.core.tracing.Tracing"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("io.lettuce.core.RedisClient");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package io.opentelemetry.auto.instrumentation.lettuce.v5_0;

import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.nameEndsWith;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
import static net.bytebuddy.matcher.ElementMatchers.returns;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

Expand All @@ -38,6 +40,11 @@ public LettuceReactiveCommandsInstrumentation() {
super("lettuce", "lettuce-5", "lettuce-5-rx");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
return not(hasClassesNamed("io.lettuce.core.tracing.Tracing"));
}

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("io.lettuce.core.AbstractRedisReactiveCommands");
Expand Down
33 changes: 33 additions & 0 deletions instrumentation/lettuce/lettuce-5.1/lettuce-5.1.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}

apply from: "${rootDir}/gradle/instrumentation.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

muzzle {
pass {
group = "io.lettuce"
module = "lettuce-core"
versions = "[5.1.0.RELEASE,)"
assertInverse = true
}
}

testSets {
latestDepTest {
dirName = 'test'
}
}

dependencies {
compileOnly group: 'io.lettuce', name: 'lettuce-core', version: '5.1.0.RELEASE'

testCompile group: 'com.github.kstyrc', name: 'embedded-redis', version: '0.6'
// Only 5.2+ will have command arguments in the db.statement tag.
testCompile group: 'io.lettuce', name: 'lettuce-core', version: '5.2.0.RELEASE'
testCompile project(':instrumentation:reactor-3.1')

latestDepTestCompile group: 'io.lettuce', name: 'lettuce-core', version: '5.+'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright The OpenTelemetry 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.opentelemetry.auto.instrumentation.lettuce.v5_1;

import static io.opentelemetry.auto.tooling.ClassLoaderMatcher.hasClassesNamed;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
import static net.bytebuddy.matcher.ElementMatchers.named;

import com.google.auto.service.AutoService;
import io.lettuce.core.resource.DefaultClientResources;
import io.opentelemetry.auto.tooling.Instrumenter;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(Instrumenter.class)
public class LettuceClientResourcesInstrumentation extends Instrumenter.Default {

public LettuceClientResourcesInstrumentation() {
super("lettuce", "lettuce-5", "lettuce-5.1");
}

@Override
public ElementMatcher<ClassLoader> classLoaderMatcher() {
return hasClassesNamed("io.lettuce.core.tracing.Tracing");
}

@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return named("io.lettuce.core.resource.DefaultClientResources");
}

@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".OpenTelemetryTracing",
packageName + ".OpenTelemetryTracing$OpenTelemetryTracerProvider",
packageName + ".OpenTelemetryTracing$OpenTelemetryTraceContextProvider",
packageName + ".OpenTelemetryTracing$OpenTelemetryTraceContext",
packageName + ".OpenTelemetryTracing$OpenTelemetryEndpoint",
packageName + ".OpenTelemetryTracing$OpenTelemetryTracer",
packageName + ".OpenTelemetryTracing$OpenTelemetrySpan",
};
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(
isMethod().and(isPublic()).and(isStatic()).and(named("builder")),
LettuceClientResourcesInstrumentation.class.getName() + "$DefaultClientResourcesAdvice");
}

public static class DefaultClientResourcesAdvice {

@Advice.OnMethodExit(suppress = Throwable.class)
public static void methodEnter(@Advice.Return final DefaultClientResources.Builder builder) {
builder.tracing(OpenTelemetryTracing.INSTANCE);
}
}
}
Loading