Common Skywalking plug-ins

Configure override

You can use the configuration override function provided by skywalking to dynamically specify the service name by starting the command, so that the agent only needs to deploy one copy. Skywalking supports several configurations:
System properties
Use skywalking+ The configuration name in the configuration file is overwritten as a system configuration item Why do I need to add a prefix? The system configuration and environment of agent are shared with the target application, so adding prefix can effectively avoid conflict.
The agent is implemented as follows service_ Override of name

-Dskywalking.agent.service_name=skywalking_mysql

Probe configuration (Agent options)
Add the properties after the agent path in JVM arguments.

-javaagent:/path/to/skywalking-agent.jar=[option1]=[value1],[option2]=[value2]

case
The agent is implemented as follows service_ Override of name

-javaagent:/path/to/skywalking-agent.jar=agent.service_name=skywalking_mysql

Special characters
If the configuration contains a separator (, or =), it must be enclosed in quotation marks

-javaagent:/path/to/skywalking-agent.jar=agent.ignore_suffix='.jpg,.jpeg'

System environment variables
case
Due to agent service_ The name configuration item is as follows:

# The service name in UI
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}

SW can be set in the environment variable_ AGENT_ Name to specify the service name.
Override priority
Probe configuration > system configuration > system environment variables > values in configuration file

Therefore, our startup command can be modified to:

java -javaagent:/usr/local/skywalking/apache-skywalking-apm-bin/agent_mysql/skywalking-agent.jar -Dskywalking.agent.service_name=skywalking_mysql -jar skywalking_mysql.jar &

perhaps

java -javaagent:/usr/local/skywalking/apache-skywalking-apm-bin/agent_mysql/skywalking-agent.jar=agent.service_name=skywalking_mysql -jarskywalking_mysql.jar &

Get tracking ID

Skywalking provides our Trace toolkit for printing information or obtaining the corresponding tracking ID when tracking links. We use Spring Boot to write a case, or we can directly use skywalking under resources_ plugins. Jar for testing.
pom:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--skywalking trace tool kit-->
        <dependency>
            <groupId>org.apache.skywalking</groupId>
            <artifactId>apm-toolkit-trace</artifactId>
            <version>${skywalking.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

PluginController:

@RestController
public class PluginController {

    //Get the trace id, which can be queried in the RocketBot trace
    @GetMapping("/getTraceId")
    public String getTraceId(){
        //Make the current link report an error and prompt the error information
        ActiveSpan.error(new RuntimeException("Test-Error-Throwable"));
        //Print info information
        ActiveSpan.info("Test-Info-Msg");
        //Print debug information
        ActiveSpan.debug("Test-debug-Msg");
        return TraceContext.traceId();
    }
}

Use tracecontext Traceid() can print out the ID of the current trace, which is convenient for searching in RocketBot.
ActiveSpan provides three methods to print information:
The error method will change the call to the failed state, and the corresponding stack information and error prompt can be printed at the same time.
The info method prints info level information.
The debug method prints the debug level information.
Deployment mode
1. Skywalking_ plugins. Upload jar to / usr/local/skywalking directory.
2. Start skywalking_plugins application, wait for successful startup.

[root@middleware skywalking-jar]# java -javaagent:/root/apache-skywalking-apm-bin/agent/skywalking-agent.jar -Dskywalking.agent.service_name=skywalking_plugins -Dskywalking.trace.ignore_path=/exclude -Dserver.port=8087 -jar skywalking_plugins.jar  &
[5] 82425
[4]   Killed               java -javaagent:/root/apache-skywalking-apm-bin/agent/skywalking-agent.jar -Dskywalking.agent.service_name=skywalking_plugins -Dskywalking.trace.ignore_path=/exclude -Dserver.port=8087 -jar skywalking_plugins.jar
[root@middleware skywalking-jar]# DEBUG 2020-11-25 10:32:10:952 main AgentPackagePath : The beacon class location is jar:file:/root/apache-skywalking-apm-bin/agent/skywalking-agent.jar!/org/apache/skywalking/apm/agent/core/boot/AgentPackagePath.class.
INFO 2020-11-25 10:32:10:956 main SnifferConfigInitializer : Config file found in /root/apache-skywalking-apm-bin/agent/config/agent.config.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.1.10.RELEASE)

4. Call the interface. The interface address is: http://192.168.1.108:8088/getTraceId
5. If the page displays

The corresponding trace record can be searched, but it shows that the call failed because activespan is used Error method. Click to catch up
Details of the project:

The exception information includes the following parts:
1. The event type is error
2. The exception type passed when calling the method is RuntimeException
3. Test error throwable exception information passed when calling method
4. Exception stack
Through the above content, we can customize the details of invoking exceptions according to the business.

In addition to exception information, info information and debug information will also be printed.

Filter specified endpoints

In the development process, some endpoints (interfaces) do not need to be monitored, such as Swagger related endpoints. At this time, we can use the filtering plug-in provided by Skywalking to filter. In Skywalking_ Write two interfaces in plugins for testing:

@RestController
public class FilterController {
    //This interface can be tracked
    @GetMapping("/include")
    public String include(){
        return "include";
    }

    //This interface is not traceable
    @GetMapping("/exclude")
    public String exclude(){
        return "exclude";
    }
}

Deployment mode
1. Skywalking_ plugins. Upload jar to / usr/local/skywalking directory.
2. Add / agent / optional - plugins / apm-trace-ignore-plugin-6.4.0 Copy the jar plug-in to the plugins directory.

3. Start skywalking_plugins application, wait for successful startup.

[root@middleware skywalking-jar]# java -javaagent:/root/apache-skywalking-apm-bin/agent/skywalking-agent.jar -Dskywalking.agent.service_name=skywalking_plugins -Dskywalking.trace.ignore_path=/exclude -Dserver.port=8087 -jar skywalking_plugins.jar  &

The exclude interface has been filtered, and only the include interface can be seen.

Tags: Microservices

Posted by w1ww on Fri, 06 May 2022 15:41:37 +0300