apache / skywalking

APM, Application Performance Monitoring System
https://skywalking.apache.org/
Apache License 2.0
23.93k stars 6.53k forks source link

[Bug] db.instance is incorrect in PostgreSQL plugin #11552

Closed mitht closed 1 year ago

mitht commented 1 year ago

Search before asking

Apache SkyWalking Component

OAP server (apache/skywalking)

What happened

Trace postgresql sql data using agent 8.14.0; Database connection address:

spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/testdb?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true

The database is testdb, but db.instance:Shanghai&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&allowMultiQueries=true

image

What you expected to happen

db.instance=testdb

How to reproduce

agent: apache-skywalking-java-agent-8.14.0 apm: apache-skywalking-apm-bin-9.3

springBoot version: 2.6.6 postgres version: 12

com.alibaba druid 1.2.16
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.2.18</version>
    </dependency>
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.3.2</version>
    </dependency>

Anything else

Every time

Are you willing to submit a pull request to fix on your own?

Code of Conduct

wu-sheng commented 1 year ago

You could debug PostgreSQLURLParser to find out the reason.

mitht commented 1 year ago

您可以调试一下PostgreSQLURLParser,找出原因。

Thank you for your answer

edit:

protected URLLocation fetchDatabaseNameIndexRange() {
    String protocol = url.split("//")[0];
    String address = url.split("//")[1];
    String ip = address.split(":")[0];
    String port_db_url = address.split(":")[1];
    String port = port_db_url.split("/")[0];
    String db_left = protocol + "//" + ip + ":" + port + "/";
    return new URLLocation(db_left.length(), url.length());
}
image
wu-sheng commented 1 year ago

I can see a patch to fix this. https://github.com/apache/skywalking-java/pull/649