Skip to content

Commit 6c14d8e

Browse files
committed
Extend PostgreSQL plugin to support JDBC 42.2-42.7
PostgreSQL 42.x removed AbstractJdbc2Statement which handled execute() 0-arg interception in old drivers. Without it, only executeWithFlags(int) was intercepted, producing different span names. Fix: replace executeWithFlags matcher with execute() (all overloads) in PgPreparedStatementInstrumentation and PgCallableStatementInstrumentation. This intercepts the user-facing execute() method, and the internal executeWithFlags() delegation is no longer intercepted (1-level only, no extra memory cost from nested interception). Locally verified: all 9 versions passed (9.2, 9.3, 9.4, 42.2-42.7).
1 parent 1d84302 commit 6c14d8e

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Release Notes.
1717
* Extend GraphQL plugin to support graphql-java 18 -> 24 (20+ requires JDK 17).
1818
* Extend Spring Kafka plugin to support Spring Kafka 2.4 -> 2.9 and 3.0 -> 3.3.
1919
* Enhance test/plugin/run.sh to support extra Maven properties per version in support-version.list (format: version,key=value).
20+
* Extend PostgreSQL plugin to support PostgreSQL JDBC 42.2 -> 42.7. Fix execute() interception: replace executeWithFlags with execute() to match user-facing method names in 42.x (AbstractJdbc2Statement removed in 42.x).
2021
* Extend OkHttp plugin to support OkHttp 4.10 -> 4.12.
2122
* Extend Dubbo 3.x plugin to support Dubbo 3.1 -> 3.3. Replace dubbo-dependencies-zookeeper (removed in 3.3) with direct dependencies in test scenario.
2223

apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2727

2828
import static net.bytebuddy.matcher.ElementMatchers.named;
29-
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
3029
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
3130
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
3231

@@ -42,7 +41,7 @@ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
4241
new InstanceMethodsInterceptPoint() {
4342
@Override
4443
public ElementMatcher<MethodDescription> getMethodsMatcher() {
45-
return named("executeWithFlags").and(takesArgumentWithType(0, "int")).or(named("executeUpdate"));
44+
return named("execute").or(named("executeUpdate"));
4645
}
4746

4847
@Override

apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
2727

2828
import static net.bytebuddy.matcher.ElementMatchers.named;
29-
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
3029
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
3130
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
3231

@@ -42,8 +41,7 @@ public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
4241
new InstanceMethodsInterceptPoint() {
4342
@Override
4443
public ElementMatcher<MethodDescription> getMethodsMatcher() {
45-
return named("execute").and(takesArgumentWithType(0, "java.lang.String"))
46-
.or(named("executeWithFlags").and(takesArgumentWithType(0, "int")))
44+
return named("execute")
4745
.or(named("executeQuery"))
4846
.or(named("executeUpdate"));
4947
}

docs/en/setup/service-agent/java-agent/Supported-list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ metrics based on the tracing data.
4949
* Oracle Driver (Optional¹), See [SkySPM Plugin Repository](https://github.com/SkyAPM/java-plugin-extensions)
5050
* H2 Driver 1.3.x -> 1.4.x
5151
* [ShardingSphere](https://github.com/apache/shardingsphere) 3.0.0, 4.0.0, 4.0.1, 4.1.0, 4.1.1, 5.0.0
52-
* PostgreSQL Driver 8.x, 9.x, 42.x
52+
* PostgreSQL Driver 8.x, 9.x, 42.x (42.2 -> 42.7)
5353
* Mariadb Driver 1.8, 2.x (2.0 -> 2.7)
5454
* [InfluxDB](https://github.com/influxdata/influxdb-java) 2.5 -> 2.17
5555
* [Mssql-Jtds](https://github.com/milesibastos/jTDS) 1.x

test/plugin/scenarios/postgresql-scenario/support-version.list

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# PostgreSQL 42.x changes internal method dispatch: execute() delegates to
18-
# executeWithFlags(), producing different span names. Needs expectedData update
19-
# or investigation of which method to intercept for 42.x.
2017
9.2-1004-jdbc41
2118
9.3-1104-jdbc41
2219
9.4-1206-jdbc42
20+
42.2.29
21+
42.3.10
22+
42.4.5
23+
42.5.6
24+
42.6.2
25+
42.7.10

0 commit comments

Comments
 (0)