You are viewing docs on Elastic's new documentation system, currently in technical preview. For all other Elastic docs, visit

Compress spans

Compress similar or identical spans to reduce storage overhead, processing power needed, and clutter in the Applications UI.

In some cases, APM agents may collect large amounts of very similar or identical spans in a transaction. For example, this can happen if spans are captured inside a loop or in unoptimized SQL queries that use multiple queries instead of joins to fetch related data.

In such cases, the upper limit of spans per transaction (by default, 500 spans) can be reached quickly, causing the agent to stop capturing potentially more relevant spans for a given transaction.

Capturing similar or identical spans often isn't helpful, especially if they are of very short duration. They can also clutter the UI, and cause processing and storage overhead.

To address this problem, APM agents can compress similar spans into a single span. The compressed span retains most of the original span information, including the overall duration and number of spans it represents.

Regardless of the compression strategy, a span is eligible for compression if:

  • It has not propagated its trace context.
  • It is an exit span (such as database query spans).
  • Its outcome is not "failure".

Compression strategies

The APM agent selects between two strategies to decide if adjacent spans can be compressed. In both strategies, only one previous span needs to be kept in memory. This ensures that the agent doesn't require large amounts of memory to enable span compression.

Same-Kind strategy

The agent uses the same-kind strategy if two adjacent spans have the same:

  • span type
  • span subtype
  • destination.service.resource (e.g. database name)

Exact-Match strategy

The agent uses the exact-match strategy if two adjacent spans have the same:

  • span name
  • span type
  • span subtype
  • destination.service.resource (e.g. database name)


You can specify the maximum span duration in the agent's configuration settings. Spans with a duration longer than the specified value will not be compressed.

For the "Same-Kind" strategy, the default maximum span duration is 0 milliseconds, which means that the "Same-Kind" strategy is disabled by default. For the "Exact-Match" strategy, the default limit is 50 milliseconds.

Agent support

Support for span compression is available in the following agents and can be configured using the options listed below:

AgentSame-kind configExact-match config
Go agent
Java agent
.NET agent
Node.js agent
Python agent

On this page