Unverified Commit 032f4c71 authored by 吴晟's avatar 吴晟 Committed by GitHub
Browse files

Merge pull request #562 from ascrutae/fix/mysql-issue

fix occur ClassCastException when call the method of return generate key
parents 72adebd1 2dcb7b50
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -27,15 +27,14 @@ import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
import org.skywalking.apm.util.StringUtil;

/**
 * {@link ConnectionServiceMethodInterceptor} create an exit span when the client call the following methods in the class
 * that extend {@link java.sql.Connection}.
 * {@link ConnectionServiceMethodInterceptor} create an exit span when the following methods execute:
 * 1. close
 * 2. rollback
 * 3. releaseSavepoint
 * 4. commit
 *
 * @author zhangxin
 */
public class ConnectionServiceMethodInterceptor implements InstanceMethodsAroundInterceptor {
@@ -45,13 +44,7 @@ public class ConnectionServiceMethodInterceptor implements InstanceMethodsAround
        Class<?>[] argumentsTypes,
        MethodInterceptResult result) throws Throwable {
        ConnectionInfo connectInfo = (ConnectionInfo)objInst.getSkyWalkingDynamicField();
        String remotePeer;
        if (!StringUtil.isEmpty(connectInfo.getHosts())) {
            remotePeer = connectInfo.getHosts();
        } else {
            remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort();
        }
        AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), remotePeer);
        AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), connectInfo.getDatabasePeer());
        Tags.DB_TYPE.set(span, "sql");
        Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
        Tags.DB_STATEMENT.set(span, "");
+1 −8
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import org.skywalking.apm.agent.core.context.ContextManager;
import org.skywalking.apm.agent.core.context.tag.Tags;
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.skywalking.apm.util.StringUtil;

/**
 * {@link CallableStatementTracing} create an exit span when the client call the method in the class that extend {@link
@@ -37,13 +36,7 @@ public class CallableStatementTracing {
        ConnectionInfo connectInfo, String method, String sql, Executable<R> exec)
        throws SQLException {
        try {
            String remotePeer;
            if (!StringUtil.isEmpty(connectInfo.getHosts())) {
                remotePeer = connectInfo.getHosts();
            } else {
                remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort();
            }
            AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, remotePeer);
            AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer());
            Tags.DB_TYPE.set(span, "sql");
            SpanLayer.asDB(span);
            Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
+6 −25
Original line number Diff line number Diff line
@@ -31,22 +31,12 @@ public class ConnectionInfo {
     * DB type, such as mysql, oracle, h2.
     */
    private final String dbType;
    /**
     * Database host name.
     */
    private String host;
    /**
     * Database port.
     */
    private int port;
    /**
     * Operation database name.
     */
    private final String databaseName;
    /**
     * Database hosts.
     */
    private String hosts;

    private String databasePeer;

    /**
     * Component
@@ -55,15 +45,14 @@ public class ConnectionInfo {

    public ConnectionInfo(OfficialComponent component, String dbType, String host, int port, String databaseName) {
        this.dbType = dbType;
        this.host = host;
        this.port = port;
        this.databasePeer = host + ":" + port;
        this.databaseName = databaseName;
        this.component = component;
    }

    public ConnectionInfo(OfficialComponent component, String dbType, String hosts, String databaseName) {
        this.dbType = dbType;
        this.hosts = hosts;
        this.databasePeer = hosts;
        this.databaseName = databaseName;
        this.component = component;
    }
@@ -72,20 +61,12 @@ public class ConnectionInfo {
        return dbType;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public String getDatabaseName() {
        return databaseName;
    }

    public String getHosts() {
        return hosts;
    public String getDatabasePeer() {
        return databasePeer;
    }

    public OfficialComponent getComponent() {
+1 −9
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import org.skywalking.apm.agent.core.context.ContextManager;
import org.skywalking.apm.agent.core.context.tag.Tags;
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.skywalking.apm.util.StringUtil;

/**
 * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link
@@ -37,14 +36,7 @@ public class PreparedStatementTracing {
        ConnectionInfo connectInfo, String method, String sql, Executable<R> exec)
        throws SQLException {
        try {
            String remotePeer;
            if (!StringUtil.isEmpty(connectInfo.getHosts())) {
                remotePeer = connectInfo.getHosts();
            } else {
                remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort();
            }

            AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, remotePeer);
            AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/PreparedStatement/" + method, connectInfo.getDatabasePeer());
            Tags.DB_TYPE.set(span, "sql");
            Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
            Tags.DB_STATEMENT.set(span, sql);
+1 −9
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import org.skywalking.apm.agent.core.context.ContextManager;
import org.skywalking.apm.agent.core.context.tag.Tags;
import org.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.skywalking.apm.util.StringUtil;

/**
 * {@link PreparedStatementTracing} create an exit span when the client call the method in the class that extend {@link
@@ -36,14 +35,7 @@ public class StatementTracing {
        ConnectionInfo connectInfo, String method, String sql, Executable<R> exec)
        throws SQLException {
        try {
            String remotePeer;
            if (!StringUtil.isEmpty(connectInfo.getHosts())) {
                remotePeer = connectInfo.getHosts();
            } else {
                remotePeer = connectInfo.getHost() + ":" + connectInfo.getPort();
            }

            AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method, remotePeer);
            AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Statement/" + method, connectInfo.getDatabasePeer());
            Tags.DB_TYPE.set(span, "sql");
            Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
            Tags.DB_STATEMENT.set(span, sql);
Loading