-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add commons pool2 instrumentation #19091
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
Open
YaoYingLong
wants to merge
9
commits into
open-telemetry:main
Choose a base branch
from
YaoYingLong:feature/apache-commons-pool2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
969a453
feat: add commons pool2 instrumentation
YaoYingLong 320c1cc
fix: fix unsuccessful CI workflow checks
YaoYingLong 516fcaf
docs: fix Apache Commons Pool 2 library link
YaoYingLong 7d22fb4
feat: replace commons-pool2 db metrics with object pool metrics
YaoYingLong fa7c17a
fix: reserve commons-pool2 pool names only while active
YaoYingLong c56578c
refactor: optimize poolName logic
YaoYingLong 9a8c8d8
feat: optimize module name to apache-commons-pool
YaoYingLong 9ab8cb8
feat: Disable Apache Commons Pool instrumentation by default
YaoYingLong 1825232
fix: spotlessCheck fail
YaoYingLong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
instrumentation/apache-commons-pool2-2.0/javaagent/build.gradle.kts
This file contains hidden or 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,38 @@ | ||
| plugins { | ||
| id("otel.javaagent-instrumentation") | ||
| } | ||
|
|
||
| muzzle { | ||
| pass { | ||
| group.set("org.apache.commons") | ||
| module.set("commons-pool2") | ||
| versions.set("[2.0,)") | ||
| assertInverse.set(true) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| library("org.apache.commons:commons-pool2:2.0") | ||
|
|
||
| implementation(project(":instrumentation:apache-commons-pool2-2.0:library")) | ||
|
|
||
| testImplementation(project(":instrumentation:apache-commons-pool2-2.0:testing")) | ||
| } | ||
|
|
||
| tasks { | ||
| withType<Test>().configureEach { | ||
| systemProperty("collectMetadata", otelProps.collectMetadata) | ||
| } | ||
|
|
||
| val testStableSemconv by registering(Test::class) { | ||
| testClassesDirs = sourceSets.test.get().output.classesDirs | ||
| classpath = sourceSets.test.get().runtimeClasspath | ||
|
|
||
| jvmArgs("-Dotel.semconv-stability.opt-in=database") | ||
| systemProperty("metadataConfig", "otel.semconv-stability.opt-in=database") | ||
| } | ||
|
|
||
| check { | ||
| dependsOn(testStableSemconv) | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
...vaagent/instrumentation/apachecommonspool2/v2_0/BaseGenericObjectPoolInstrumentation.java
This file contains hidden or 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,76 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.apachecommonspool2.v2_0; | ||
|
|
||
| import static io.opentelemetry.javaagent.instrumentation.apachecommonspool2.v2_0.CommonsPool2Singletons.telemetry; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
|
||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import javax.management.ObjectName; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import org.apache.commons.pool2.impl.BaseGenericObjectPool; | ||
| import org.apache.commons.pool2.impl.GenericKeyedObjectPool; | ||
| import org.apache.commons.pool2.impl.GenericObjectPool; | ||
|
|
||
| class BaseGenericObjectPoolInstrumentation implements TypeInstrumentation { | ||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return named("org.apache.commons.pool2.impl.BaseGenericObjectPool"); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| isConstructor() | ||
| .and(takesArguments(3)) | ||
| .and(takesArgument(0, named("org.apache.commons.pool2.impl.BaseObjectPoolConfig"))), | ||
| getClass().getName() + "$ConstructorAdvice"); | ||
|
|
||
| transformer.applyAdviceToMethod( | ||
| named("jmxUnregister").and(takesArguments(0)), | ||
| getClass().getName() + "$JmxUnregisterAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class ConstructorAdvice { | ||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void onExit(@Advice.This BaseGenericObjectPool<?> pool) { | ||
| ObjectName objectName = pool.getJmxName(); | ||
|
|
||
| String type = objectName == null ? null : objectName.getKeyProperty("type"); | ||
| if (type == null) { | ||
| if (pool instanceof GenericKeyedObjectPool) { | ||
| type = "GenericKeyedObjectPool"; | ||
| } else if (pool instanceof GenericObjectPool) { | ||
| type = "GenericObjectPool"; | ||
| } else { | ||
| type = pool.getClass().getSimpleName(); | ||
| } | ||
| } | ||
|
|
||
| String name = objectName == null ? null : objectName.getKeyProperty("name"); | ||
| if (name == null) { | ||
| name = String.valueOf(System.identityHashCode(pool)); | ||
| } | ||
|
|
||
| telemetry().registerMetrics(pool, type + "-" + name); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class JmxUnregisterAdvice { | ||
| @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) | ||
| public static void onExit(@Advice.This BaseGenericObjectPool<?> pool) { | ||
| telemetry().unregisterMetrics(pool); | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
.../javaagent/instrumentation/apachecommonspool2/v2_0/CommonsPool2InstrumentationModule.java
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.apachecommonspool2.v2_0; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import java.util.List; | ||
|
|
||
| @AutoService(InstrumentationModule.class) | ||
| public class CommonsPool2InstrumentationModule extends InstrumentationModule { | ||
| public CommonsPool2InstrumentationModule() { | ||
| super("apache-commons-pool2", "apache-commons-pool2-2.0"); | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return singletonList(new BaseGenericObjectPoolInstrumentation()); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...entelemetry/javaagent/instrumentation/apachecommonspool2/v2_0/CommonsPool2Singletons.java
This file contains hidden or 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,21 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.apachecommonspool2.v2_0; | ||
|
|
||
| import io.opentelemetry.api.GlobalOpenTelemetry; | ||
| import io.opentelemetry.instrumentation.apachecommonspool2.v2_0.CommonsPool2Telemetry; | ||
|
|
||
| public class CommonsPool2Singletons { | ||
|
|
||
| private static final CommonsPool2Telemetry telemetry = | ||
| CommonsPool2Telemetry.create(GlobalOpenTelemetry.get()); | ||
|
|
||
| public static CommonsPool2Telemetry telemetry() { | ||
| return telemetry; | ||
| } | ||
|
|
||
| private CommonsPool2Singletons() {} | ||
| } |
36 changes: 36 additions & 0 deletions
36
...ry/javaagent/instrumentation/apachecommonspool2/v2_0/CommonsPool2InstrumentationTest.java
This file contains hidden or 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,36 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.apachecommonspool2.v2_0; | ||
|
|
||
| import io.opentelemetry.instrumentation.apachecommonspool2.AbstractCommonsPool2InstrumentationTest; | ||
| import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
| import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
| import org.apache.commons.pool2.impl.GenericKeyedObjectPool; | ||
| import org.apache.commons.pool2.impl.GenericObjectPool; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
|
||
| class CommonsPool2InstrumentationTest extends AbstractCommonsPool2InstrumentationTest { | ||
|
|
||
| @RegisterExtension | ||
| static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
|
||
| @Override | ||
| protected InstrumentationExtension testing() { | ||
| return testing; | ||
| } | ||
|
|
||
| @Override | ||
| protected void configure(GenericObjectPool<?> pool, String poolName) {} | ||
|
|
||
| @Override | ||
| protected void configure(GenericKeyedObjectPool<?, ?> pool, String poolName) {} | ||
|
|
||
| @Override | ||
| protected void shutdown(GenericObjectPool<?> pool) {} | ||
|
|
||
| @Override | ||
| protected void shutdown(GenericKeyedObjectPool<?, ?> pool) {} | ||
| } |
23 changes: 23 additions & 0 deletions
23
instrumentation/apache-commons-pool2-2.0/library/build.gradle.kts
This file contains hidden or 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,23 @@ | ||
| plugins { | ||
| id("otel.library-instrumentation") | ||
| id("otel.nullaway-conventions") | ||
| } | ||
|
|
||
| dependencies { | ||
| library("org.apache.commons:commons-pool2:2.0") | ||
|
|
||
| testImplementation(project(":instrumentation:apache-commons-pool2-2.0:testing")) | ||
| } | ||
|
|
||
| tasks { | ||
| val testStableSemconv by registering(Test::class) { | ||
| testClassesDirs = sourceSets.test.get().output.classesDirs | ||
| classpath = sourceSets.test.get().runtimeClasspath | ||
|
|
||
| jvmArgs("-Dotel.semconv-stability.opt-in=database") | ||
| } | ||
|
|
||
| check { | ||
| dependsOn(testStableSemconv) | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
.../java/io/opentelemetry/instrumentation/apachecommonspool2/v2_0/CommonsPool2Telemetry.java
This file contains hidden or 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,34 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.apachecommonspool2.v2_0; | ||
|
|
||
| import io.opentelemetry.api.OpenTelemetry; | ||
|
|
||
| /** Entrypoint for instrumenting Apache Commons Pool 2 object pools. */ | ||
| public final class CommonsPool2Telemetry { | ||
| private final OpenTelemetry openTelemetry; | ||
|
|
||
| /** | ||
| * Returns a new {@link CommonsPool2Telemetry} configured with the given {@link OpenTelemetry}. | ||
| */ | ||
| public static CommonsPool2Telemetry create(OpenTelemetry openTelemetry) { | ||
| return new CommonsPool2Telemetry(openTelemetry); | ||
| } | ||
|
|
||
| private CommonsPool2Telemetry(OpenTelemetry openTelemetry) { | ||
| this.openTelemetry = openTelemetry; | ||
| } | ||
|
|
||
| /** Start collecting metrics for the given supported object pool. */ | ||
| public void registerMetrics(Object pool, String poolName) { | ||
| ConnectionPoolMetrics.registerMetrics(openTelemetry, pool, poolName); | ||
| } | ||
|
|
||
| /** Stop collecting metrics for the given supported object pool. */ | ||
| public void unregisterMetrics(Object pool) { | ||
| ConnectionPoolMetrics.unregisterMetrics(pool); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.