Skip to content

Commit 2d69df4

Browse files
committed
Merge branch 'feat/python-docs-nav-standardization' of https://github.com/getsentry/sentry-docs into feat/python-docs-nav-standardization
* 'feat/python-docs-nav-standardization' of https://github.com/getsentry/sentry-docs: ref: Allign badges with Sentry’s in-product ones (#15561) feat: Document exporting from OTLP from shopify hydrogen storefronts (#15534) docs(size-analysis): Update sentry-android-gradle-plugin to 6.0.0-beta.2 (#15560) fix(developer docs): Correcting width issues in developer docs for toc (#15559) docs(feature-flag): add documentation for php feature flags (#15443) feat(python): Illustrate types of metrics (#15556) fix(dev-docs): Buffer fixes for logs and metrics (#15513) docs(sourcemaps): Remove mentions of `sentry-cli sourcemaps explain` (#15481) ref(develop/scopes): Clarify unit type for attributes (#15546) ref(develop/spans): Clarify span attribute `unit` and `type` types (#15547) docs(metrics): add upcoming SDKs to Metrics getting started page (#15545) doc(proguard): No inbound filters (#15543) getsentry/relay@9b19609
2 parents 350b787 + cc0727a commit 2d69df4

File tree

27 files changed

+374
-218
lines changed

27 files changed

+374
-218
lines changed

develop-docs/sdk/telemetry/logs.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,11 @@ A new data category for logs has been added to Relay, `log_item`. Both the `log`
390390

391391
### Buffering
392392

393-
Logs should be buffered before being sent. SDKs should keep a buffer of logs on the client (so you can have logs from multiple traces in the buffer) that flushes out based on some kind of condition. We recommend to follow the [telemetry buffer specification outlined](/sdk/telemetry/telemetry-buffer/) in the develop docs, but you should choose the approach that works best for your platform. When starting initial development on the SDK you can choose a simple approach to buffer like flushing logs if the buffer length exceeds 100 items, or if 5 seconds have passed.
393+
SDKs **MUST** buffer logs before sending them. SDKs should keep a buffer of logs and flush it when specific conditions are met. For initial implementation, a simple strategy is fine, for example: flushing logs if the buffer length exceeds 100 items or if 5 seconds have passed. To prevent data loss, the buffer SHOULD forward logs to the transport in the scenarios outlined in the [telemetry buffer data forwarding scenarios](/sdk/telemetry/telemetry-buffer/#data-forwarding-scenarios).
394394

395-
SDKs must have a hard limit of 1000 log events queued up to avoid causing our customers applications going out of memory. Logs added once the hard limit has been reached are dropped.
395+
SDKs **MUST** also have a hard limit of 1000 log events queued up to avoid causing your customers' applications going out of memory. Logs added once this hard limit has been reached are dropped. Also, Relay has a hard limit of 1000 logs per envelope. SDKs **MUST** not exceed this limit. SDKs **SHOULD** batch logs into envelopes of 100 or less.
396+
397+
We used to recommend following the [BatchProcessor](/sdk/telemetry/telemetry-buffer/#batchprocessor-v0), but this page is currently under development. We currently working on a new [telemetry buffer specification](/sdk/telemetry/telemetry-buffer/) that will replace the BatchProcessor.
396398

397399
SDKS should NOT release logging capabilities to users if a buffering implementation has not been added to their SDK when adding logging APIs.
398400

develop-docs/sdk/telemetry/metrics.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ While the metrics functionality for an SDK is in an experimental state, SDKs sho
185185
Sentry.init({
186186
// stable
187187
enableMetrics: true,
188-
188+
189189
// experimental
190190
_experiments: { enableMetrics: true },
191191
});
@@ -449,12 +449,13 @@ A new data category for metrics has been added to Relay, `trace_metric`. Rate li
449449

450450
### Buffering
451451

452-
Metrics should be buffered before being sent. SDKs should keep a buffer of metrics on the client that flushes out based on some kind of condition. We recommend following the [batch processor specification](/sdk/telemetry/spans/batch-processor/) outlined in the develop docs, but you should choose the approach that works best for your platform.
452+
SDKs **MUST** buffer metrics before sending them. SDKs should also keep a buffer of metrics and flush it when specific conditions are met. For initial implementation, a simple strategy is fine, for example: flushing metrics if the buffer length exceeds 100 items or if 5 seconds have passed. To prevent data loss, the buffer **SHOULD** forward metrics to the transport in the scenarios outlined in the [telemetry buffer data forwarding scenarios](/sdk/telemetry/telemetry-buffer/#data-forwarding-scenarios). Furthermore:
453453

454454
- The aggregation window should be time and size based.
455-
- Flush triggers (e.g. SDK shutdown, size thresholds) should be considered based on the platform and use case.
456455
- SDKs should implement safeguards to prevent excessive memory usage from metric buffering.
457456

457+
We're currently working on a concept for buffering different types of telemetry data in [telemetry buffer specification](/sdk/telemetry/telemetry-buffer/).
458+
458459
### Behaviour with other Sentry Telemetry
459460

460461
#### Tracing
@@ -565,5 +566,4 @@ If `debug` is set to `true` in SDK init, calls to the Sentry metrics API should
565566

566567
- [Experimental JS SDK PR #17883 - Metrics API Implementation](https://github.com/getsentry/sentry-javascript/pull/17883/files)
567568
- [Experimental Python SDK PR #4898 - Metrics API Implementation](https://github.com/getsentry/sentry-python/pull/4898)
568-
- [Batch Processor Specification](/sdk/telemetry/spans/batch-processor/)
569-
569+
- [Batch Processor Specification](/sdk/telemetry/telemetry-buffer/batch-processor/)

develop-docs/sdk/telemetry/scopes.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ Users MUST be able to attach attributes to any scope using a dedicated method (e
6161
Attributes are key-value pairs where each value is either a an attribute value or an object containing:
6262

6363
- `value`: The actual attribute value, which MUST match the specified type
64-
- `unit` (optional): The unit of measurement (e.g., `"ms"`, `"s"`, `"bytes"`, `"count"`, `"percent"` or any other string value). SDKs MAY NOT add support for units for the moment, but MUST be able to do so at a later date without a breaking change.
64+
- `unit` (optional): The unit of measurement (e.g., `"millisecond"`, `"second"`, `"byte"`, `"ratio"`).
65+
- SDKs MAY delay adding support for units for the moment, but MUST be able to do so at a later date without a breaking change.
66+
- SDKS MUST allow setting all units supported by Relay's [`MetricUnit` enum](https://getsentry.github.io/relay/relay_metrics/enum.MetricUnit.html) but MUST NOT allow custom units (i.e. arbitrary strings, defined in [`CustomUnit`](https://getsentry.github.io/relay/relay_metrics/struct.CustomUnit.html)) or "none" units (`''` or `'none'`).
6567
- `type` (optional): The type of the attribute. SDKs SHOULD NOT expose this to users if they can reliably infer the type from the value. If not, SDKs MAY allow or require users to set the `type` explicitly.
6668

6769
#### Example Usage

develop-docs/sdk/telemetry/spans/span-protocol.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ The envelope item payload must contain an `items` array with span one and up to
9191
"http.response.status_code": {
9292
"type": "integer",
9393
"value": 200
94+
},
95+
"session.duration": {
96+
"type": "integer",
97+
"value": 164,
98+
"unit": "second"
9499
}
95100
},
96101
"links": [
@@ -158,9 +163,9 @@ Attributes are stored as key-value pairs where each value is an object with type
158163

159164
| Property | Type | Required | Description |
160165
|----------|------|----------|-------------|
161-
| `type` | string | Yes | The data type of the attribute value. Values: `"string"`, `"integer"`, `"double"`, `"boolean"` |
166+
| `type` | string | Yes | The data type of the attribute value. Values: `"string"`, `"integer"`, `"double"`, `"boolean"`, `"string[]"`, `"integer[]"`, `"double[]"`, `"boolean[]"` |
162167
| `value` | any | Yes | The actual attribute value, must match the specified type |
163-
| `unit` | string | No | The unit of the attribute value. Example values: `"ms"`, `"s"`, `"bytes"`, `"count"`, `"percent"` |
168+
| `unit` | string | No | The unit of the attribute value. Example values: `"millisecond"`, `"second"`, `"byte"`, `"ratio"`. Units MUST be one of the [MetricUnit](https://getsentry.github.io/relay/relay_metrics/enum.MetricUnit.html)s supported by Relay, excluding `""`, `"none"` or custom units. |
164169

165170
#### Common Attribute Keys
166171

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: Batch Processor (deprecated)
3+
redirect_from:
4+
- /sdk/telemetry/spans/batch-processor/
5+
sidebar_order: 10
6+
---
7+
8+
<Alert level="warning">
9+
The BatchProcessor is deprecated. Please use the [Telemetry Buffer](/sdk/telemetry/telemetry-buffer/) instead.
10+
</Alert>
11+
12+
<Alert>
13+
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.
14+
</Alert>
15+
16+
# BatchProcessor (deprecated)
17+
18+
This section covers the initial specification of the BatchProcessor, which some SDKs use as a reference when implementing logs. This exists only as a reference until we fully spec out the [telemetry buffer](/sdk/telemetry/telemetry-buffer/) across all platforms.
19+
20+
## Overview
21+
22+
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. At the time of writing, the BatchProcessor only handles spans and logs, but an SDK **MAY** use it for other telemetry data in the future.
23+
24+
## Specification
25+
26+
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.
27+
28+
The BatchProcessor **MUST** start a timeout of 5 seconds when the SDK adds the first span or log. When the timeout expires, the BatchProcessor **MUST** forward all spans or logs to the transport, 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, this avoids running the timeout unnecessarily.
29+
30+
The BatchProcessor **MUST** forward all items to the transport 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, as well as 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.
31+
32+
When the BatchProcessor forwards all spans or logs to the transport, 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.
33+
34+
The BatchProcessor **MUST** forward all spans and logs in memory to the transport to avoid data loss in the following scenarios:
35+
36+
1. When the user calls `SentrySDK.flush()`, the BatchProcessor **MUST** forward all data in memory to the transport, and only then **SHOULD** the transport flush the data.
37+
2. When the user calls `SentrySDK.close()`, the BatchProcessor **MUST** forward all data in memory to the transport. SDKs **SHOULD** keep their existing closing behavior.
38+
3. When the application shuts down gracefully, the BatchProcessor **SHOULD** forward all data in memory to the transport. The transport **SHOULD** keep its existing behavior, which usually stores the data to disk as an envelope. It is not required to call a transport `flush`. 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.
39+
4. When the application moves to the background, the BatchProcessor **SHOULD** forward all the data in memory to the transport and stop the timer. The transport **SHOULD** keep its existing behavior, which usually stores the data to disk as an envelope. It is not required to call the transport `flush`. This is mostly relevant for mobile SDKs.
40+
5. Mobile SDKs **MUST** minimize data loss when sudden process terminations occur. Refer to the [Mobile Telemetry Buffer](/sdk/telemetry/telemetry-buffer/mobile-telemetry-buffer) section for more details.
41+
42+
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.
43+
44+
45+
```Gherkin
46+
Scenario: No spans in BatchProcessor 1 span added
47+
Given no spans in the BatchProcessor
48+
When the SDK finishes 1 span
49+
Then the SDK puts this span to the BatchProcessor
50+
And starts a timeout of 5 seconds
51+
And doesn't forward the span to the transport
52+
53+
Scenario: Span added before timeout exceeds
54+
Given span A in the BatchProcessor
55+
Given 4.9 seconds pass
56+
When the SDK finishes span B
57+
Then the SDK adds span B to the BatchProcessor
58+
And doesn't reset the timeout
59+
And doesn't forward the spans A and B in the BatchProcessor to the transport
60+
61+
Scenario: Timeout exceeds and no spans or logs to send
62+
Given no spans in the BatchProcessor
63+
When the timeout exceeds
64+
Then the BatchProcessor does nothing
65+
And doesn't start a new timeout
66+
67+
Scenario: Spans with size of 1 MiB - 1 byte added, timeout exceeds
68+
Given spans with size of 1 MiB - 1 byte in the BatchProcessor
69+
When the timeout exceeds
70+
Then the SDK adds all the spans to one envelope
71+
And forwards them to the transport
72+
And resets the timeout
73+
And clears the BatchProcessor
74+
75+
Scenario: Spans with size of 1 MiB - 1 byte added within 4.9 seconds
76+
Given spans with size of 1 MiB - 1 byte in the BatchProcessor
77+
When the SDK finishes another span and puts it into the BatchProcessor
78+
Then the BatchProcessor puts all spans into one envelope
79+
And forwards the envelope to the transport
80+
And resets the timeout
81+
And clears the BatchProcessor
82+
83+
Scenario: Unfinished spans
84+
Given no span is in the BatchProcessor
85+
When the SDK starts a span but doesn't finish it
86+
Then the BatchProcessor is empty
87+
88+
Scenario: Span filtered out
89+
Given no span is in the BatchProcessor
90+
When the finishes a span
91+
And the span is filtered out
92+
Then the BatchProcessor is empty
93+
94+
Scenario: Span not sampled
95+
Given no span is in the BatchProcessor
96+
When the finishes a span
97+
And the span is not sampled
98+
Then the BatchProcessor is empty
99+
100+
Scenario: 1 span added application crashes
101+
Given 1 span in the SpansAggregator
102+
When the SDK detects a crash
103+
Then the SDK does nothing with the items in the BatchProcessor
104+
And loses the spans in the BatchProcessor
105+
106+
```
107+
108+
<PageGrid />

0 commit comments

Comments
 (0)