Apache SkyWalking Java Agent Documentation
repository·main·Indexed 21 days ago
https://github.com/apache/skywalking-javaA specialized agent providing native tracing, metrics, and logging for Java applications to enable observability in microservices and cloud-native environments. It integrates with the Apache SkyWalking APM system and supports features such as async-profiler task triggering, custom trace ignoring, and OAL (Observability Analysis Language). The agent supports JDK 8+ and provides mechanisms for TLS, namespace, and token-based authentication.
What's inside Apache SkyWalking Java Agent
- The Apache SkyWalking Java Agent is a specialized agent that provides native tracing, metrics, and logging capabilities for Java projects. It is designed to work with the Apache SkyWalking APM (Application Performance Monitor) system, which is optimized for microservices, cloud-native, and container-based architectures (such as Docker and Kubernetes).
Use the Spring Gateway Plugin for tracing
mainThe Spring Gateway Plugin supports Spring Gateway versions 2.x, 3.x, and 4.x. It provides tracing capabilities by:
- Creating entry spans for incoming calls.
- Continuing trace context propagation within Spring Gateway.
- Creating exit spans for outgoing calls.
It automatically supports
GlobalFilterandGatewayFilterimplementations. However, it cannot transparently trace logic executed within a.then(...)closure in a WebFlux chain.Understand the two types of SkyWalking plugins
mainSkyWalking supports two primary plugin types for data collection:
- Tracing plugin: Follows distributed tracing concepts to collect spans, including tags and logs.
- Meter plugin: Collects numeric metrics in
Counter,Gauge, andHistogramformats.
If you are contributing to the main repository, your plugin's data will be verified using the SkyWalking plugin test tool.
What is a Logic Endpoint in SkyWalking
mainIn SkyWalking, while RPC server-side names (like RESTful API paths or gRPC service names) are typically treated as entry spans with metrics, a Logic Endpoint is a specialized concept that allows plugins or users to define new endpoints without creating entirely new spans. This allows for more granular analysis of specific logical operations within an existing trace.
Several plugins automatically register logic endpoints using specific naming conventions:
- GraphQL: Uses the names of Queries and Mutations.
- Spring Scheduled Tasks: Formatted as
SpringScheduled/${className}/${methodName}. - Apache ShardingSphere ElasticJob: Formatted as
ElasticJob/${jobName}. - XXLJob: Uses formats such as
xxl-job/MethodJob/${className}.${methodName},xxl-job/ScriptJob/${GlueType}/id/${jobId}, orxxl-job/SimpleJob/${className}. - Quartz (optional plugin): Formatted as
quartz-scheduler/${className}.
Manually continue traces across threads
mainWhen your application logic moves work from one thread to another, the trace context may be lost. Use the across thread solution APIs to manually propagate the trace context to the new thread.How Configuration Discovery Service (CDS) works
mainThe Configuration Discovery Service (CDS) provides dynamic configuration for the SkyWalking Java Agent via gRPC. Instead of static files, the agent can receive real-time configuration updates for specific services.
Configurations are structured by service name, where each service can have its own set of key-value pairs. This allows for granular control over agent behavior on a per-service basis.
configurations: serviceA: key1: value1 key2: value2 serviceB: key3: value3Use the SkyWalking Application Toolkit for manual tracing
mainThe Application Toolkit provides libraries that act as a bridge between your application code and the SkyWalking agent. Use the SkyWalking manual APIs if you need to perform the following tasks directly in your code:
- Retrieve the current
trace id. - Set custom tags on the current span.
- Propagate custom data across traces.
- Retrieve the current
Update LAL (Logging Analysis Language) syntax for version 8.7.0
mainStarting with version 8.7.0, there is a breaking change in the LAL syntax: theqps(queries per second) parameter has been removed and replaced withrpm(requests per minute).Project Context Files for Claude Code
mainThe repository contains
CLAUDE.mdfiles that provide specialized context to Claude Code. These are automatically loaded to assist with specific development areas:File Purpose CLAUDE.md(root)Project overview, build system, architecture, and conventions apm-sniffer/apm-sdk-plugin/CLAUDE.mdSDK plugin development guide (V2 API, class matching, testing) apm-sniffer/bootstrap-plugins/CLAUDE.mdBootstrap plugin specifics (JDK class instrumentation) How the Kotlin Coroutine plugin works
mainThe plugin automates context propagation for Kotlin coroutines using the following lifecycle:
- Snapshot: Before a continuation is dispatched, the plugin creates a snapshot of the current tracing context.
- Span Creation: Once the thread switches, a new coroutine span is created and marked as a continuation of the snapshot.
- Child Spans: Any new spans created in the new thread become children of this coroutine span, maintaining the trace hierarchy.
- Cleanup: After the original runnable executes, the coroutine span is stopped to clean up the thread state.
Understand SkyWalking v9.0.0+ Naming Policies for Enhanced Classes
mainStarting from version 9.0.0, Apache SkyWalking uses a predictable naming convention for auxiliary types, fields, and methods to support class re-transformation and hot-swapping alongside other Java agents. All generated names follow the
sw$name trait. This ensures that names remain unchanged even after re-transformation.Key naming strategies include:
- Auxiliary Type Name (
SWAuxiliaryTypeNamingStrategy):<origin_class_name>$<name_trait>$auxiliary$<auxiliary_type_instance_hash> - Interceptor Delegate Field Name (
DelegateNamingResolver):<name_trait>$delegate$<class_name_hash>$<plugin_define_hash>$<intercept_point_hash> - Renamed Origin Method (
SWMethodNameTransformer):<name_trait>$original$<method_name>$<method_description_hash> - Method Cache Value Field (
SWImplementationContextFactory):cachedValue$<name_trait>$<origin_class_name_hash>$<field_value_hash> - Accessor Method Name (
SWImplementationContextFactory):<renamed_origin_method>$accessor$<name_trait>$<origin_class_name_hash>
- Auxiliary Type Name (
Forward Micrometer metrics using SkyWalking Micrometer Register
mainTo integrate existing Micrometer metrics or observations with SkyWalking, use the SkyWalking Micrometer Register.