Manual Instrumentationedit

The Elastic APM Android Agent automatically instruments Supported technologies, creating spans for interesting events for each case, and some of those automated spans can be configured to better suit different app’s needs. However, if you need to create your own, custom spans, metrics and logs, you can do so by accessing the OpenTelemetry Java SDK APIs that this agent is built on top.

OpenTelemetry Entrypointedit

After completing the setup process, the Agent will have configured the OpenTelemetry entrypoint for you and made it globally accessible. In order to access to the configured OpenTelemetry instance you need to use the GlobalOpenTelemetry class as shown below.

class MyClass {

    // Example of how to obtain an OpenTelemetry tracer to create custom Spans.
    public void myMethod() {
        Tracer tracer = GlobalOpenTelemetry.getTracer("my-tracer-scope-name");
        // You can use your tracer instance as explained in OpenTelemetry's span creation guide: https://opentelemetry.io/docs/instrumentation/java/manual/#create-spans
    }
}

In a similar way you can create other types of signals by accessing their entrypoints through the GlobalOpenTelemetry class, for example for custom metrics, you can use: GlobalOpenTelemetry.getMeter("my-metric-scope-name") and follow OpenTelemetry’s guide on creating manual metrics.