This documentation contains work-in-progress information for future Elastic Stack and Cloud releases. Use the version selector to view supported release docs. It also contains some Elastic Cloud serverless information. Check out our serverless docs for more details.
Annotations
editAnnotations
editThe 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.
How-to create spans with the annotations API
editHere’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... }
Combine with the span API
editYou 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.