Report Java application data with SkyWalking agent

更新时间:
复制 MD 格式

After you instrument your application by using SkyWalking and report trace data to Managed Service for OpenTelemetry, Managed Service for OpenTelemetry starts to monitor your application. You can view various monitoring data, such as application topology, traces, abnormal transactions, slow transactions, and SQL analysis. This topic describes how to use the SkyWalking Java Agent for automatic instrumentation and provides information about its configurable attributes.

Prerequisites

  • Open the SkyWalking download page and download SkyWalking 6.X.X or a later version (the latest stable version is recommended). Place the extracted agent folder in a directory accessible to the Java process.

  • All plugins are stored in the /plugins directory. To enable a new plugin, add it to this directory before startup. To disable a plugin, remove it from this directory. By default, log files are written to the /logs directory.

Warning

Log files, plugins, and configuration files are located in the agent folder. Do not change the directory structure.

Obtain an endpoint

New console

  1. Log on to the Managed Service for OpenTelemetry console. In the left-side navigation pane, click Integration Center.

  2. On the Integration Center page, click the SkyWalking card in the Open Source Frameworks section.

  3. In the SkyWalking panel, click the Start Integration tab, and then select a region in which you want to report data.

    Note

    When you access a region for the first time, resources are automatically initialized there.

  4. Configure the Connection Type parameter and copy an endpoint.

    If your service is deployed on Alibaba Cloud and resides in the region that you selected, we recommend that you set this parameter to Alibaba Cloud VPC Network. Otherwise, set this parameter to Public Network.

    image.png

Old console

  1. Log on to the Managed Service for OpenTelemetry console.

  2. In the left-side navigation pane, click Cluster Configurations. On the page that appears, click the Access point information tab.

  3. In the top navigation bar, select a region in which you want to report data. In the Cluster Information section, turn on Show Token.

  4. Set the Client parameter to SkyWalking.

    In the Related Information column of the table, copy an endpoint.

    SkyWalking接入点信息

    Note

    If your application is deployed in an Alibaba Cloud production environment, use a VPC endpoint. Otherwise, use a public endpoint.

Background

SkyWalking is a popular Application Performance Monitoring (APM) tool designed for applications built on microservice, Cloud Native, and containerized (Docker, Kubernetes, and Mesos) architectures. At its core, SkyWalking is a distributed tracing system.

To use SkyWalking to report data from your Java application to the Managed Service for OpenTelemetry console, you must first instrument the application. SkyWalking supports both auto-instrumentation for frameworks such as Dubbo, gRPC, JDBC, OkHttp, Spring, Tomcat, Struts, and Jedis, and manual instrumentation with OpenTracing. This topic describes the auto-instrumentation method.

Demo

Code repository: SkyWalking Demo

Instrument a Java application with SkyWalking

  1. Download the SkyWalking Java Agent.

  2. Configure the connection and service information in the SkyWalking Java Agent configuration file.

    collector.backend_service=<endpoint> // Replace with the endpoint obtained from the prerequisites.
    agent.authentication=<token> // Replace with the authentication token obtained from the prerequisites.
    agent.service_name=<service-name> // Replace with your actual service name.
  3. Specify the path to the SkyWalking agent based on your application's runtime environment.

    Note

    In the following examples, replace <skywalking-agent-path> with the absolute path to skywalking-agent.jar in the agent folder.

    Linux Tomcat 7 / Tomcat 8

    Add the following to the first line of tomcat/bin/catalina.sh:

    CATALINA_OPTS="$CATALINA_OPTS -javaagent:<skywalking-agent-path>"; export CATALINA_OPTS

    Windows Tomcat 7 / Tomcat 8

    Add the following to the first line of tomcat/bin/catalina.bat:

    set "CATALINA_OPTS=-javaagent:<skywalking-agent-path>"

    JAR or Spring Boot

    Add the -javaagent parameter to your application's startup command.

    Important

    The -javaagent parameter must appear before the -jar parameter.

    java -javaagent:<skywalking-agent-path> -jar yourApp.jar

    Jetty

    Add the following lines to the {JETTY_HOME}/start.ini configuration file:

    --exec
    -javaagent:<skywalking-agent-path>
  4. Restart your application.

Configurable Java agent attributes

The SkyWalking Java agent supports a wide range of user-configurable attributes. For a complete list of attributes, see the config/agent.config file in the sample demo.

Key attributes

The following attributes are based on apache-skywalking-java-agent-8.16.0.

View agent attributes

Parameter

Description

Default

agent.namespace

Specifies the namespace to isolate headers for cross-process propagation. If set, the header format is HeaderName:Namespace.

Not set

agent.service_name

The service name displayed in the SkyWalking UI. This corresponds to Application in v5.x and Service in v6.x. Set a unique name for each service. All instances of a service should share the same name.

Your_ApplicationName

agent.sample_n_per_3_secs

Sets the number of traces to sample every 3 seconds. A value of 0 or less disables sampling.

Not set

agent.authentication

Whether authentication is required depends on the backend configuration. You can view the token on the server endpoint. Most use cases require an authentication extension on the backend. Currently, only basic authentication is implemented.

Not set

agent.span_limit_per_segment

The maximum number of spans in a single segment. SkyWalking uses this setting to estimate application memory usage.

Not set

agent.ignore_suffix

If the first span's operation name matches an entry in this list, the agent discards the segment.

Not set

agent.is_open_debugging_class

If true, SkyWalking saves all instrumented class files to the /debugging directory. The SkyWalking team may request these files to troubleshoot compatibility issues.

Not set

agent.cause_exception_depth

The depth of the exception's cause chain to record.

5

agent.force_reconnection_period

The interval, as a multiple of grpc_channel_check_interval, to force a gRPC reconnection.

1

agent.operation_name_threshold

Sets the recommended maximum length for an operation name. The hard limit is 190.

150

agent.keep_tracing

If true, the agent continues to trace even if the backend is unavailable.

false

osinfo.ipv4_list_size

The maximum number of IPv4 addresses to report.

10

collector.grpc_channel_check_interval

The interval, in seconds, for checking the gRPC channel status.

30

collector.backend_service

The backend address that receives SkyWalking trace data.

127.0.0.1:11800

collector.heartbeat_period

The interval, in seconds, for the agent to send heartbeats.

30

collector.grpc_upstream_timeout

The timeout, in seconds, for the gRPC client to send data upstream.

30

collector.get_profile_task_interval

The interval, in seconds, for the profiler to fetch the list of profiling tasks.

20

logging.level

The agent's log level.

DEBUG

logging.file_name

The name of the log file.

skywalking-api.log

logging.output

The destination for log output. Set to FILE to log to a file or CONSOLE to log to standard output.

FILE

logging.dir

The log directory. If empty, logs are written to stdout.

""

logging.pattern

The log format pattern. The following conversion specifiers are supported:

  • %level: The log level.

  • %timestamp: The current time in yyyy-MM-dd HH:mm:ss:SSS format.

  • %thread: The name of the current thread.

  • %msg: The log message.

  • %class: The simple name of the target class.

  • %throwable: The stack trace of the logged exception.

  • %agent_name: The value of agent.service_name.

%level %timestamp %thread %class : %msg %throwable

logging.max_file_size

The maximum size of a log file. When a log file exceeds this size, the agent archives it and creates a new one.

300 * 1024 * 1024

logging.max_history_files

The maximum number of archived log files to keep. A value of 0 or less means all archived files are kept.

-1

Configuration methods

System properties

Use the -Dskywalking. prefix followed by the attribute name from the agent.config file. For example:

# Configure agent.service_name using a system property
java -javaagent:/path/to/skywalking-agent.jar -Dskywalking.agent.service_name=<your_service_name> -jar your-project.jar

Agent options

Append attributes to the agent path in the JVM arguments.

# Syntax
-javaagent:/path/to/skywalking-agent.jar=[key1]=[value1],[key2]=[value2]
# Example
java -javaagent:/path/to/skywalking-agent.jar=agent.service_name=<your-service-name>,agent.authentication=<your-token> -jar your-project.jar

Environment variables

The SkyWalking agent automatically reads environment variables. You can find the corresponding environment variable for each attribute in the config/agent.config file. For example, the environment variable for agent.service_name is SW_AGENT_NAME.

agent.service_name=${SW_AGENT_NAME:default_name}
# Set the environment variable
export SW_AGENT_NAME=<your_service_name>

Precedence

Configuration settings are applied with the following precedence, from highest to lowest: agent options, system properties, environment variables, and the configuration file.

Java agent plug-ins

The SkyWalking Java agent supports a variety of middleware, frameworks, and libraries. All supported plug-ins are available in the /plugins folder of the demo application.

Activate plug-ins

All plug-ins in the /plugins folder are active. To disable a plug-in, remove its JAR file from the /plugins folder.

Officially supported plug-ins

All officially supported plug-ins are located in the /plugins folder.

Optional plug-ins

Optional plug-ins reside in the optional-plugins folder of the agent package or in a third-party repository. To activate an optional plug-in, move its JAR file to the /plugins folder.

optional-plugins/
  apm-customize-enhance-plugin-8.16.0.jar
  apm-ehcache-2.x-plugin-8.16.0.jar
  apm-fastjson-1.x-plugin-8.16.0.jar
  apm-gson-2.x-plugin-8.16.0.jar
  apm-guava-cache-plugin-8.16.0.jar
  apm-jackson-2.x-plugin-8.16.0.jar
  apm-kotlin-coroutine-plugin-8.16.0.jar
  apm-mybatis-3.x-plugin-8.16.0.jar
  apm-quartz-scheduler-2.x-plugin-8.16.0.jar
  apm-resttemplate-6.x-plugin-8.16.0.jar
  apm-sentinel-1.x-plugin-8.16.0.jar
  apm-shenyu-2.4.x-plugin-8.16.0.jar
  apm-spring-annotation-plugin-8.16.0.jar
  apm-spring-cloud-gateway-2.0.x-plugin-8.16.0.jar
  apm-spring-cloud-gateway-2.1.x-plugin-8.16.0.jar
  apm-spring-cloud-gateway-3.x-plugin-8.16.0.jar
  apm-spring-tx-plugin-8.16.0.jar
  apm-spring-webflux-5.x-plugin-8.16.0.jar
  apm-springmvc-annotation-6.x-plugin-8.16.0.jar
  apm-trace-ignore-plugin-8.16.0.jar
  apm-zookeeper-3.4.x-plugin-8.16.0.jar
  trace-sampler-cpu-policy-plugin-8.16.0.jar

Bootstrap plug-ins

Due to potential stability risks, all bootstrap plug-ins are optional. They are located in the bootstrap-plugins folder. To activate a bootstrap plug-in, move its JAR file to the /plugins folder.

bootstrap-plugins/
  apm-jdk-forkjoinpool-plugin-8.16.0.jar
  apm-jdk-http-plugin-8.16.0.jar
  apm-jdk-threading-plugin-8.16.0.jar
  apm-jdk-threadpool-plugin-8.16.0.jar

Supported plug-ins

Some plug-ins are available only from a third-party repository due to potential performance impacts or usage limitations. For more information, see the SkyAPM Java Plugin Extension repository.

Expand to view the list of plug-ins

Framework

Plug-in version

HTTP server

Tomcat 7

Tomcat 8

Tomcat 9

Spring Boot Web 4.x

Spring MVC 3.x, 4.x, 5.x with Servlet 3.x

Nutz Web Framework 1.x

Struts2 MVC 2.3.x - 2.5.x

Resin 3

Resin 4

Jetty Server 9

Spring WebFlux 5.x

Undertow 2.0.0.Final - 2.0.13.Final

RESTEasy 3.1.0.Final - 3.7.0.Final

Play Framework 2.6.x - 2.8.x

Light4J Microservices Framework 1.6.x - 2.x

Netty SocketIO 1.x

HTTP client

Feign 9.x

Netflix Spring Cloud Feign 1.1.x, 1.2.x, 1.3.x

OkHttp 3.x

Apache httpcomponent HttpClient 4.2, 4.3

Spring RestTemplate 4.x

Jetty Client 9

Apache httpcomponent AsyncClient 4.x

HTTP gateway

Spring Cloud Gateway 2.1.x.RELEASE

JDBC

MySQL Driver 5.x, 6.x, 8.x

Oracle Driver

H2 Driver 1.3.x - 1.4.x

Sharding-JDBC 1.5.x

ShardingSphere 3.0.0

ShardingSphere 3.0.0, 4.0.0-RC1

PostgreSQL Driver 8.x, 9.x, 42.x

MariaDB Driver 2.x, 1.8

RPC framework

Dubbo 2.5.4 - 2.6.0

Dubbox 2.8.4

Apache Dubbo 2.7.0

Motan 0.2.x - 1.1.0

gRPC 1.x

Apache ServiceComb Java Chassis 0.1 - 0.5, 1.0.x

SOFARPC 5.4.0

Armeria 0.63.0 - 0.98.0

Apache Avro 1.7.0 - 1.8.x

Finagle 6.25.0 - 20.1.0

Message queue

RocketMQ 4.x

Kafka 0.11.0.0 - 1.0

ActiveMQ 5.x

RabbitMQ 5.x

Pulsar 2.2.x - 2.4.x

NoSQL

Redis

Jedis 2.x

Redisson client 3.5.2+

Lettuce 5.x

MongoDB

MongoDB Java Driver 2.13 - 2.14, 3.3+

Memcached client

Spymemcached 2.x

Xmemcached 2.x

Elasticsearch

transport-client 5.2.x - 5.6.x

transport-client 6.7.1 - 6.8.4

rest-high-level-client 6.7.1 - 6.8.4

SolrJ 7.0.0 - 7.7.1

SolrJ 7.x

Cassandra 3.x

cassandra-java-driver 3.7.0 - 3.7.2

Service discovery

Netflix Eureka

Distributed coordination

ZooKeeper 3.4.x (excluding 3.4.4)

Spring ecosystem

Spring Bean annotations (@Bean, @Service, @Component, @Repository) 3.x and 4.x

Spring Core Async SuccessCallback/FailureCallback/ListenableFutureCallback 4.x

Hystrix: latency and fault tolerance for distributed systems 1.4.20 - 1.5.12

Scheduler

Elastic-Job 2.x

OpenTracing community support

Canal 1.0.25 - 1.1.2: An Alibaba component for incremental subscription to MySQL binlogs

JSON

GSON 2.8.x

Vert.x ecosystem

Vert.x Eventbus 3.2+

Vert.x Web 3.x

Thread scheduling framework

Spring @Async 4.x and 5.x

Cache

Ehcache 2.x

Kotlin

Coroutine 1.0.1 - 1.3.x

Plug-in development

To develop a custom SkyWalking Java agent plug-in, refer to the official documentation.

Managed Service for OpenTelemetry supports trace reporting. See the official documentation for details on developing a custom trace plug-in.

FAQ

Q: Why doesn't my application appear after the SkyWalking Agent connects to the server?

A: This issue occurs when distributed tracing data is not reported. To verify this, check the {skywalking agent path}/logs/skywalking-api.log file. If data is being reported, you will see a DEBUG log from the SkyWalking Agent like the one below. The key message, TraceSegmentServiceClient : 1 trace segments have been sent to collector., confirms that distributed tracing data was successfully sent to the collector.

DEBUG 2020-03-09 17:18:16:356 SkywalkingAgent-5-ServiceAndEndpointRegisterClient-0 ServiceAndEndpointRegisterClient : ServiceAndEndpointRegisterClient running, status:CONNECTED.
DEBUG 2020-03-09 17:18:19:357 SkywalkingAgent-5-ServiceAndEndpointRegisterClient-0 ServiceAndEndpointRegisterClient : ServiceAndEndpointRegisterClient running, status:CONNECTED.
DEBUG 2020-03-09 17:18:21:301 DataCarrier.DEFAULT.Consumer.0.Thread TraceSegmentServiceClient : 1 trace segments have been sent to collector.
DEBUG 2020-03-09 17:18:22:353 SkywalkingAgent-2-GRPCChannelManager-0 GRPCChannelManager : Selected collector grpc service running, reconnect:false.
DEBUG 2020-03-09 17:18:22:357 SkywalkingAgent-5-ServiceAndEndpointRegisterClient-0 ServiceAndEndpointRegisterClient : ServiceAndEndpointRegisterClient running, status:CONNECTED.
DEBUG 2020-03-09 17:18:25:356 SkywalkingAgent-5-ServiceAndEndpointRegisterClient-0 ServiceAndEndpointRegisterClient : ServiceAndEndpointRegisterClient running, status:CONNECTED.

If data reporting is not occurring, possible causes include enabled sampling, configured filters, or a lack of requests that generate distributed traces.