Docs » Instrument back-end applications to send spans to Splunk APM » Instrument Java applications for Splunk Observability Cloud » Manually instrument Java applications for Splunk Observability Cloud

Manually instrument Java applications for Splunk Observability Cloud 🔗

Instrumenting applications automatically using the agent of the Splunk Distribution of OpenTelemetry Java covers most needs. Manually instrumenting your application is only necessary when, for example, you need to add custom attributes to spans or need to manually generate spans and metrics.

For instructions on how to manually instrument Java applications, see the Manual instrumentation docs in the OpenTelemetry Java Instrumentation repository at


Manual OTel instrumentation is fully compatible with Splunk automatic JVM instrumentation and is fully supported by Splunk.

Send custom Java application metrics 🔗

The Splunk Distribution of OpenTelemetry Java agent detects if the instrumented application is using Micrometer and injects a special MeterRegistry implementation that lets the agent collect user-defined meters.

Follow these steps to activate custom application metrics:

Add the micrometer-core dependency 🔗

To export custom metrics through the Java agent, add a dependency on the micrometer-core library with version 1.5 and higher:


Register each custom meter 🔗

You must register each custom meter in the global Metrics.globalRegistry instance provided by the Micrometer library. You can use one of meter factory methods provided by the Metrics class, or use meter builders and reference the Metrics.globalRegistry directly, as in the following example:

class MyClass {
Counter myCounter = Metrics.counter("my_custom_counter");
  Timer myTimer = Timer.builder("my_custom_timer").register(Metrics.globalRegistry);

  int foo() {
    return myTimer.record(this::fooImpl);

  private int fooImpl() {
     // ...

For more information on the Micrometer API, see the Micrometer official documentation.