Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Backend Telemetry Buffer
description: Detailed backend telemetry buffer design.
sidebar_order: 1
---

To be defined — full spec lives here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing a link here to the full spec?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a wip comment, so this will get overwritten by the actual doc.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Browser Telemetry Buffer
description: Detailed browser telemetry buffer design.
sidebar_order: 2
---

To be defined — full spec lives here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: GDX Telemetry Buffer
description: Detailed GDX telemetry buffer design.
sidebar_order: 3
---

To be defined — full spec lives here.
128 changes: 128 additions & 0 deletions develop-docs/sdk/telemetry/telemetry-buffer/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
title: Telemetry Buffer
redirect_from:
- /sdk/telemetry/spans/batch-processor/
sidebar_order: 5
---

<Alert level="warning">
🚧 This document is work in progress.
</Alert>

<Alert>
This document uses key words such as "MUST", "SHOULD", and "MAY" as defined in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) to indicate requirement levels.
</Alert>

The telemetry buffer sits between the client and the transport, temporarily buffering high-volume telemetry data such as spans and logs. The client SHOULD continue to pass low-volume telemetry data, such as events, directly to the transport. The telemetry buffer aims to efficiently batch data to reduce the number of outgoing HTTP requests and Sentry envelopes. Without buffering, each span or log would trigger its own request, quickly overwhelming our backends.

```mermaid
flowchart LR
Client[Client] -->|high-volume telemetry data| Buffer[TelemetryBuffer]
Buffer -->|buffered telemetry data| Transport[Transport]
Client -->|low-volume telemetry data| Transport
```

Because telemetry workloads and platform constraints vary widely, buffer requirements differ across environments. For example, backend SDKs need high throughput and backpressure management to handle large data volumes. Mobile SDKs have lower throughput and don't need to worry much about backpressure, but they do need to minimize data loss in the event of abnormal process termination. Browser and GDX SDKs also have different requirements.

Therefore, we recommend implementing different types of telemetry buffers tailored to the platform's needs. As of Nov 5th, 2025, this page is under development, and we're currently refining the requirements for different platforms:

* [Backend Telemetry Buffer](./backend-telemetry-buffer/): Detailed backend design
* [Browser Telemetry Buffer](./browser-telemetry-buffer/): To be defined
* [GDX Telemetry Buffer](./gdx-telemetry-buffer/): To be defined
* [Mobile Telemetry Buffer](./mobile-telemetry-buffer/): To be defined

# Common Requirements

To be defined. Things like common API, client reports, etc.

# BatchProcessor V0

## Overview

The BatchProcessor batches spans and logs into one envelope to reduce the number of HTTP requests. When an SDK implements span streaming or logs, it MUST use a BatchProcessor, which is similar to [OpenTelemetry's Batch Processor](https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/batchprocessor/README.md). The BatchProcessor holds logs and finished spans in memory and batches them together into envelopes. It uses a combination of time and size-based batching. When writing this, the BatchProcessor only handles spans and logs, but an SDK MAY use it for other telemetry data in the future.

## Specification

Whenever the SDK finishes a span or captures a log, it MUST put it into the BatchProcessor. The SDK MUST NOT put unfinished spans into the BatchProcessor.

The BatchProcessor MUST start a timeout of 5 seconds when the SDK adds the first span or log. When the timeout exceeds, the BatchProcessor MUST send all spans or logs, no matter how many items it contains. The SDK MAY choose a different value for the timeout, but it MUST NOT exceed 30 seconds, as this can lead to problems with the span buffer on the backend, which uses a time interval of 60 seconds for determining segments for spans. The BatchProcessor SHOULD only start a new timeout, when it has spans or logs to send, to avoid running the timeout unnecessarily.

The BatchProcessor MUST send all items after the SDK when containing spans or logs exceeding 1MiB in size. The SDK MAY choose a different value for the max batch size keeping the [envelope max sizes](/sdk/data-model/envelopes/#size-limits) in mind. The SDK MUST calculate the size of a span or a log to manage the BatchProcessor's memory footprint. The SDK MUST serialize the span or log and calculate the size based on the serialized JSON bytes. As serialization is expensive, the BatchProcessor SHOULD keep track of the serialized spans and logs and pass these to the envelope to avoid serializing multiple times.

When the BatchProcessor sends all spans or logs, it MUST reset its timeout and remove all spans and logs. The SDK MUST apply filtering and sampling before adding spans or logs to the BatchProcessor. The SDK MUST apply rate limits to spans and logs after they leave the BatchProcessor to send as much data as possible by dropping data as late as possible.

The BatchProcessor MUST send all spans and logs in memory to avoid data loss in the following scenarios:

1. When the user calls `SentrySDK.flush()`, the BatchProcessor MUST send all data in memory.
2. When the user calls `SentrySDK.close()`, the BatchProcessor MUST send all data in memory.
3. When the application shuts down gracefully, the BatchProcessor SHOULD send all data in memory. This is mostly relevant for mobile SDKs already subscribed to these hooks, such as [applicationWillTerminate](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/applicationwillterminate(_:)) on iOS.
4. When the application moves to the background, the BatchProcessor SHOULD send all data in memory and stop the timer. This is mostly relevant for mobile SDKs.
5. We're working on concept for crashes, and will update the specification when we have more details.

The detailed specification is written in the [Gherkin syntax](https://cucumber.io/docs/gherkin/reference/). The specification uses spans as an example, but the same applies to logs or any other future telemetry data.


```Gherkin
Scenario: No spans in BatchProcessor 1 span added
Given no spans in the BatchProcessor
When the SDK finishes 1 span
Then the SDK puts this span to the BatchProcessor
And starts a timeout of 5 seconds
And doesn't send the span to Sentry

Scenario: Span added before timeout exceeds
Given span A in the BatchProcessor
Given 4.9 seconds pass
When the SDK finishes span B
Then the SDK adds span B to the BatchProcessor
And doesn't reset the timeout
And doesn't send the spans A and B in the BatchProcessor to Sentry

Scenario: Timeout exceeds and no spans or logs to send
Given no spans in the BatchProcessor
When the timeout exceeds
Then the BatchProcessor does nothing
And doesn't start a new timeout

Scenario: Spans with size of 1 MiB - 1 byte added, timeout exceeds
Given spans with size of 1 MiB - 1 byte in the BatchProcessor
When the timeout exceeds
Then the SDK adds all the spans to one envelope
And sends them to Sentry
And resets the timeout
And clears the BatchProcessor

Scenario: Spans with size of 1 MiB - 1 byte added within 4.9 seconds
Given spans with size of 1 MiB - 1 byte in the BatchProcessor
When the SDK finishes another span and puts it into the BatchProcessor
Then the BatchProcessor puts all spans into one envelope
And sends the envelope to Sentry
And resets the timeout
And clears the BatchProcessor

Scenario: Unfinished spans
Given no span is in the BatchProcessor
When the SDK starts a span but doesn't finish it
Then the BatchProcessor is empty

Scenario: Span filtered out
Given no span is in the BatchProcessor
When the finishes a span
And the span is filtered out
Then the BatchProcessor is empty

Scenario: Span not sampled
Given no span is in the BatchProcessor
When the finishes a span
And the span is not sampled
Then the BatchProcessor is empty

Scenario: 1 span added application crashes
Given 1 span in the SpansAggregator
When the SDK detects a crash
Then the SDK does nothing with the items in the BatchProcessor
And loses the spans in the BatchProcessor

```

<PageGrid />
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Mobile Telemetry Buffer
description: Detailed mobile telemetry buffer design.
sidebar_order: 4
---

To be defined — full spec lives here.
Loading