Apache SkyWalking Java Agent Documentation

repository·main·Indexed 21 days ago

https://github.com/apache/skywalking-java

A 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.

Tokens
61.5K
Snippets
162
Records
276
Agent score
73%

What's inside Apache SkyWalking Java Agent

  1. Overview of Apache SkyWalking Java Agent

    main
    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).
  2. Use the Spring Gateway Plugin for tracing

    main

    The 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 GlobalFilter and GatewayFilter implementations. However, it cannot transparently trace logic executed within a .then(...) closure in a WebFlux chain.

  3. Understand the two types of SkyWalking plugins

    main

    SkyWalking supports two primary plugin types for data collection:

    1. Tracing plugin: Follows distributed tracing concepts to collect spans, including tags and logs.
    2. Meter plugin: Collects numeric metrics in Counter, Gauge, and Histogram formats.

    If you are contributing to the main repository, your plugin's data will be verified using the SkyWalking plugin test tool.

  4. What is a Logic Endpoint in SkyWalking

    main

    In 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}, or xxl-job/SimpleJob/${className}.
    • Quartz (optional plugin): Formatted as quartz-scheduler/${className}.
  5. How Configuration Discovery Service (CDS) works

    main

    The 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: value3
  6. Project Context Files for Claude Code

    main

    The repository contains CLAUDE.md files that provide specialized context to Claude Code. These are automatically loaded to assist with specific development areas:

    FilePurpose
    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)
  7. How the Kotlin Coroutine plugin works

    main

    The plugin automates context propagation for Kotlin coroutines using the following lifecycle:

    1. Snapshot: Before a continuation is dispatched, the plugin creates a snapshot of the current tracing context.
    2. Span Creation: Once the thread switches, a new coroutine span is created and marked as a continuation of the snapshot.
    3. Child Spans: Any new spans created in the new thread become children of this coroutine span, maintaining the trace hierarchy.
    4. Cleanup: After the original runnable executes, the coroutine span is stopped to clean up the thread state.
  8. Understand SkyWalking v9.0.0+ Naming Policies for Enhanced Classes

    main

    Starting 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>