-
Notifications
You must be signed in to change notification settings - Fork 869
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lettuce 5.2 instrumentation that uses lettuce's native tracing fu…
…nctionality. (#535) * Copy Lettuce 5.0 to start 5.1 instrumentation * Begin tracing adapter implementation Co-authored-by: Dustin Neray <[email protected]> * Set floor to 5.2 instead * Move around * Finish * Cleanups * Instrument 5.1+ instead * Cleanup * 5.1 * Remove latestDepTest from lettuce-5.0 since we have a newer lettuce-5.1. * Remove * Remove package check * Spotless Co-authored-by: Dustin Neray <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,731 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.+' | ||
} |
78 changes: 78 additions & 0 deletions
78
...pentelemetry/auto/instrumentation/lettuce/v5_1/LettuceClientResourcesInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.