Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ targets:
- type: gradle
path: ./
target: ':instrumentation:alibaba-druid-1.0:library'
- type: gradle
path: ./
target: ':instrumentation:apache-commons-pool2-2.0:javaagent'
- type: gradle
path: ./
target: ':instrumentation:apache-commons-pool2-2.0:library'
- type: gradle
path: ./
target: ':instrumentation:apache-dbcp-2.0:javaagent'
Expand Down
1 change: 1 addition & 0 deletions .github/config/latest-dep-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
"org.apache.camel:camel-undertow#2.+": "2.25.4",
"org.apache.cassandra:java-driver-core#+": "4.19.3",
"org.apache.commons:commons-dbcp2#+": "2.14.0",
"org.apache.commons:commons-pool2#+": "2.13.1",
"org.apache.cxf:cxf-rt-frontend-jaxrs#+": "4.2.2",
"org.apache.cxf:cxf-rt-frontend-jaxrs#3.+": "3.6.11",
"org.apache.cxf:cxf-rt-frontend-jaxws#+": "4.2.2",
Expand Down
1 change: 1 addition & 0 deletions docs/supported-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ These are the supported libraries and frameworks:
| [Apache CXF JAX-RS](https://cxf.apache.org/) | 3.2+ (not including 4.0+ yet) | N/A | Provides `http.route` [2], Controller Spans [3] |
| [Apache CXF JAX-WS](https://cxf.apache.org/) | 3.0+ (not including 4.0+ yet) | N/A | Provides `http.route` [2], Controller Spans [3] |
| [Apache DBCP](https://commons.apache.org/proper/commons-dbcp/) | 2.0+ | [opentelemetry-apache-dbcp-2.0](../instrumentation/apache-dbcp-2.0/library) | [Database Pool Metrics] |
| [Apache Commons Pool 2](https://commons.apache.org/proper/commons-pool/) | 2.0+ | [opentelemetry-apache-commons-pool2-2.0](../instrumentation/apache-commons-pool2-2.0/library) | [Database Pool Metrics] |
| [Apache Dubbo](https://github.com/apache/dubbo/) | 2.7+ | [opentelemetry-apache-dubbo-2.7](../instrumentation/apache-dubbo-2.7/library-autoconfigure) | [RPC Client Spans], [RPC Server Spans] |
| [Apache ElasticJob](https://shardingsphere.apache.org/elasticjob/) | 3.0+ | N/A | none |
| [Apache HBase](https://hbase.apache.org/) | 2.0 - 2.4.x | N/A | [Database Client Spans], [Database Client Metrics] [6] |
Expand Down
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)
}
}
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));
Comment thread
laurit marked this conversation as resolved.
Outdated
}

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);
}
}
}
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());
}
}
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() {}
}
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 instrumentation/apache-commons-pool2-2.0/library/build.gradle.kts
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)
}
}
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);
}
}
Loading
Loading