Java Agent and Javassist modify bytecode to join monitoring

problem description

1. We intend to add some bytecodes for monitoring before the actual operation, such as slow sql , dubbo concurrency , development release time to check mybatis/ibatis configuration files

the environmental background of the problems and what methods you have tried

2. We use Instrumentation to import the Agent jar package that we monitor and develop at startup, but we find that the following code using javassist doesn"t work


    <modelVersion>4.0.0</modelVersion>

    <groupId>top.huzhurong.agent</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.23.1-GA</version>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <target>1.8</target>
                    <source>1.8</source>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                        <manifestEntries>
                            <Premain-Class>test.Agent</Premain-Class>
                            <Boot-Class-Path>javassist-3.23.1-GA.jar</Boot-Class-Path>
                            <Can-Redefine-Classes>true</Can-Redefine-Classes>
                            <Can-Set-Native-Method-Prefix>true</Can-Set-Native-Method-Prefix>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

google, Baidu has not found anything, and it is not easy to debug itself. It was possible to use ASM in the past. Thank you in advance

May.11,2021

because I did some processing in agent , I wonder if javassist was not loaded, so I couldn't get ClassPool

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3976d-4edfe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3976d-4edfe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?