Type to search.

Span API

Serverless Unavailable

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

Availability

  • Unavailable

    This functionality is not available in Elastic Cloud Serverless.

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.

A span measures the duration of a single event. When a span is created it will measure the time until span.end() is called.

To get a Span object, you need to call apm.startSpan().

  • Type: String
  • Default: Unknown

The name of the span. This can also be set via apm.startSpan().

  • Type: String
  • Default: custom

The type of span. This can also be set via apm.startSpan().

The type is a hierarchical string used to group similar spans together. For instance, all outgoing AJAX requests are given the type external.http.

In the above example, external is considered the type prefix. Though there are no naming restrictions for this prefix, the following are standardized across all Elastic APM agents: app, db, cache, template, and external.

JavaScript
span.addLabels({ [name]: value })

Add several labels on the span. If an error happens during the span, it will also get tagged with the same labels.

Arguments:

  • name - Any string. All periods (.), asterisks (*), and double quotation marks (") will be replaced by underscores (_), as those characters have special meaning in Elasticsearch
  • value - Any string, boolean, or number. All other data types will be converted to a string before being sent to the APM Server.
JavaScript
span.end()

Ends the span. If the span has already ended, nothing happens.