Type to search.

API/Code

Serverless Observability

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

APM Agent Java

The Elastic APM Java agent enables you to trace the execution of operations in your Java applications, sending performance metrics and errors to the Elastic APM Server.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

Use the span API to manually create spans for methods of interest. The API is extremely flexible, and offers the ability to customize your spans, by adding labels to them, or by changing the type, name, or timestamp.

Tip

OpenTracing fan? You can use the OpenTracing API, instead of the Agent API, to manually create spans.

  1. Get the current span with currentSpan(), which may or may not have been created with auto-instrumentation.
  2. Create a child span with startSpan().
  3. Activate the span with activate().
  4. Customize the span with the span API.
Java
import co.elastic.apm.api.ElasticApm;
import co.elastic.apm.api.Span;

Span parent = ElasticApm.currentSpan();
Span span = parent.startSpan();
try (Scope scope = span.activate()) {
    span.setName("SELECT FROM customer");
    span.addLabel("foo", "bar");
    // do your thing...
} catch (Exception e) {
    span.captureException(e);
    throw e;
} finally {
    span.end();
}
  1. Get current span
  2. Create a child span
  3. Make this span the active span on the current thread
  4. Override the default span name
  5. Add labels to the span

You can combine annotations with the span API to increase their flexibility. Just get the current span on an annotated method and customize the span to your liking.

Java
@CaptureSpan
private static void spanWithAnnotation(String foo) {
    Span span = ElasticApm.currentSpan();
    span.setTag("foo", foo);
}
  1. Use @CaptureSpan annotation to create a span
  2. Get the current span (the one created via the @CaptureSpan annotation)
  3. Customize the span