Annotations
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability 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. 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 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.
Serverless Observability
Generally available
Stack
Generally available
APM Agent Java
Generally available
The annotation API allows you to place annotations on top of methods to automatically create spans for them. This method of creating spans is easier, more robust, and typically more performant than using the API; there’s nothing you can do wrong like forgetting to end a span or close a scope.
Annotations are less flexible when used on their own, but can be combined with the span API for added flexibility.
Here’s an example that uses the @CaptureSpan annotation to create a span for the spanWithAnnotation() method. The span is named spanName, is of type ext, and subtype http.
@CaptureSpan(value = "spanName", type = "ext", subtype = "http")
private static void spanWithAnnotation() {
// do your thing...
}
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.
@CaptureSpan
private static void spanWithAnnotation(String foo) {
Span span = ElasticApm.currentSpan();
span.setTag("foo", foo);
}
- Use
@CaptureSpanannotation to create a span - Get the current span (the one created via the
@CaptureSpanannotation) - Customize the span