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, meter, and logger to create custom Spans, Metrics and Logs.
    public void myMethod() {
        // Span example
        Tracer tracer = GlobalOpenTelemetry.getTracer("my-tracer-scope-name");
        Span span = tracer.spanBuilder("spanName").startSpan();

        // Metric example
        LongCounter counter = GlobalOpenTelemetry.meterBuilder("meterScope").build().counterBuilder("myCounter").build();

        // Logs example
        Logger logger = GlobalOpenTelemetry.get().getLogsBridge().get("logScope");
        logger.logRecordBuilder().setBody("Log body").emit();

You can find more details on how to create and customize all kinds of signals by following OpenTelemetry’s Java SDK guide on manually creating signals.