Span APIedit

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().

To see an example of using custom spans, see the Custom Spans in Node.js article.

span.transactionedit

  • Type: Transaction

A reference to the parent transaction object.

All spans belong to a transaction.

span.nameedit

  • Type: String
  • Default: unnamed

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

span.typeedit

  • 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 spans of MySQL queries are given the type db.mysql.query.

In the above example, db 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 ext.

span.end()edit

span.end()

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