Instrument Java applications

Instrument your Java application with the Secure Application JVM agent.

The Secure Application Java Virtual Machine (JVM) agent, splunk-otel-javaagent-csa, adds APM instrumentation to your Java application and sends the data it collects to the Splunk Distribution of OpenTelemetry Collector. Follow these steps to add the JVM agent to your application and to configure it to send the OpenTelemetry events and logs that Secure Application needs.

  1. Identify the version of the Secure Application JVM agent that you want to install from https://repo1.maven.org/maven2/com/splunk/splunk-otel-javaagent-csa/. Use version 2.21.1.
  2. Download the JAR file for the version you want to install:
    CODE
    curl -L https://repo1.maven.org/maven2/com/splunk/splunk-otel-javaagent-csa/<version>/splunk-otel-javaagent-csa-<version>.jar -o splunk-otel-javaagent-csa.jar
  3. Start your application with the JVM agent.

    On the command line, configure the agent using system properties or environment variables. System properties override environment variables.

    Table 1. JVM agent parameters
    System property Environment variable Description
    otel.exporter.otlp.endpoint OTEL_EXPORTER_OTLP_ENDPOINT FQDN and gRPC port of your OpenTelemetry collector.

    Example: http://otel-collector:4318

    otel.resource.attributes OTEL_RESOURCE_ATTRIBUTES

    Resource attributes to associate with your Java application.

    Required:

    • service.name (set to same value as otel.service.name)

    Recommended:

    • deployment.environment
    • service.namespace
    otel.service.name OTEL_SERVICE_NAME Service name of your Java application.
    Tip: service.namespace is now an optional parameter in otel.resource.attributes. For information about this parameter, see Service Attributes. For help with the JVM agent, see Instrument Java applications for Splunk Observability Cloud.
    Syntax
    BASH
    java -javaagent:./splunk-otel-javaagent-csa.jar \  
    -Dotel.service.name=<service-name> \ 
    -Dotel.resource.attributes=deployment.environment=<environment-name>,service.name=<service-name>,service.namespace=<namespace-name> \
    -Dotel.exporter.otlp.endpoint=http://<collector-endpoint>:<collector-port> \
    -jar <myapp>.jar

    Substitute placeholders with values specific to your environment.

    Example
    BASH
    java -javaagent:./splunk-otel-javaagent-csa.jar \ 
    -Dotel.service.name=myService \ 
    -Dotel.resource.attributes=deployment.environment=us0,service.name=myService,service.namespace=myServiceNamespace \
    -Dotel.exporter.otlp.endpoint=http://otel-collector:4318 \
    -jar myapp.jar

Your Java application launches with the JVM agent enabled. The JVM agent gathers a list of runtime libraries, formats them as OTLP logs, and sends the data to the OTLP exporter endpoint specified above. The JVM agent reports library data once at application startup and then every 24 hours thereafter.