Skip to content

Commit 8288fc8

Browse files
authored
feat(spans): Document trace attachments (#15705)
1 parent c65609b commit 8288fc8

File tree

2 files changed

+55
-45
lines changed

2 files changed

+55
-45
lines changed

develop-docs/sdk/data-model/envelope-items.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,58 @@ file. It is always associated to an event or transaction.
113113

114114
: _String, optional._ The content type of the attachment payload. Any [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml) may be used; the default is `application/octet-stream`.
115115

116+
### Trace Attachment
117+
118+
Item type `"attachment"` with content type `"application/vnd.sentry.attachment.v2"`. This item contains a raw payload of an attachment together with metadata. Contrary to V1 attachments, trace attachments are only optionally associated with other trace items (spans, logs, ...). Their main association is with the trace itself.
119+
120+
**Envelope Headers:**
121+
122+
- `trace` (optional): If the envelope containing the trace attachment has a [Dynamic Sampling Context](/sdk/telemetry/traces/dynamic-sampling-context), it will be subject to trace-based dynamic sampling rules, and potentially dropped.
123+
124+
**Item Headers:**
125+
126+
The trace attachment item header must contain the following properties:
127+
128+
```json
129+
{
130+
"type": "attachment",
131+
"content_type": "application/vnd.sentry.attachment.v2",
132+
"length": 212341234,
133+
"meta_length": 123
134+
}
135+
```
136+
137+
- `meta_length` is the size of the metadata portion of the payload in bytes (see item description below).
138+
139+
140+
**Item Payload:**
141+
142+
The trace attachment item payload consists of a JSON object containing metadata followed by the attachment body. For example, for a plain text attachment with the body "helloworld", the item payload would look like this:
143+
144+
```json
145+
{ // Attachment Metadata
146+
"trace_id": "12312012123120121231201212312012",
147+
"attachment_id": "019a72d07ffe77208c013ac888b38d9e",
148+
"timestamp": 1760520026.781239,
149+
"filename": "myfile.txt",
150+
"content_type": "text/plain",
151+
"attributes": {
152+
// Arbitrary key value pairs that will end up in EAP.
153+
"foo": {"type": "string", "value": "bar"}
154+
}
155+
}helloworld
156+
```
157+
158+
| Property | Type | Required | Description |
159+
|----------|------|----------|-------------|
160+
| `trace_id` | string | Yes | The trace ID. Determines which `trace` the attachment belongs to. 32-character hexadecimal string. |
161+
| `attachment_id` | string | Yes | 32-character hexadecimal string (a valid [Version 7](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_7_(timestamp_and_random)) or Version 4 UUID without dashes) |
162+
| `timestamp` | float | Yes | a UNIX timestamp corresponding to the attachment's occurrence. It may be the same as the start or end timestamp of the owner span. |
163+
| `filename` | string | No | The file name of the attachment. |
164+
| `content_type` | string | Yes | the content type of the attachment body (not to be confused with the content type of the envelope item, which is always `application/vnd.sentry.attachment.v2`). |
165+
| `attributes` | object | No | arbitrary attributes that will be queryable on the attachment trace item, similar to spans, logs, and trace metrics. |
166+
167+
116168
### Session
117169

118170
Item type `"session"` contains a single session initialization or update to an

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

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -218,49 +218,7 @@ span_id: "438f40bd3b4a41ee"
218218

219219
## Span Attachments
220220

221-
The SDK must implement a new "attachment v2" envelope item, which is used to emit span attachments to Sentry. A span attachment should be emitted in the same envelope as its owner span, so that it can be dropped when the span itself is filtered or rate limited.
222-
223-
### Attachment v2 Envelope Item Header
224-
225-
The envelope item header must contain the following properties:
226-
227-
```json
228-
{
229-
"type": "attachment",
230-
"content_type": "application/vnd.sentry.attachment.v2",
231-
"length": 212341234,
232-
"meta_length": 123,
233-
"span_id": "abcd1234" // or `null`
234-
}
235-
```
236-
237-
- `meta_length` is the size of the metadata portion of the payload in bytes (see item description below).
238-
- `span_id` is the ID of the span that owns the attachment. `span_id: null` is treated as “owned by spans”, but not owned by a specific span. That is, the attachment can be dropped if the span quota is exceeded, but it will not be dropped with a specific span because of e.g. inbound filters.
239-
240-
## Attachment v2 Envelope Item Payload
241-
242-
The attachment item payload consists of JSON object containing metadata followed by the attachment body. For example, for a plain text attachment with the body "Hello World!", the item payload would look like this:
243-
244-
```json
245-
{ // Attachment Metadata
246-
"attachment_id": "019a72d07ffe77208c013ac888b38d9e",
247-
"timestamp": 1760520026.781239,
248-
"filename": "myfile.txt",
249-
"content_type": "text/plain",
250-
"attributes": {
251-
// Arbitrary key value pairs that will end up in EAP.
252-
"foo": {"type": "string", "value": "bar"}
253-
}
254-
}helloworld
255-
```
256-
257-
| Property | Type | Required | Description |
258-
|----------|------|----------|-------------|
259-
| `attachment_id` | string | Yes | 32-character hexadecimal string (a valid [Version 7](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_7_(timestamp_and_random)) or Version 4 UUID without dashes) |
260-
| `timestamp` | float | Yes | a UNIX timestamp corresponding to the attachment's occurrence. It may be the same as the start or end timestamp of the owner span. |
261-
| `filename` | string | No | The file name of the attachment. |
262-
| `content_type` | string | Yes | the content type of the attachment body (not to be confused with the content type of the envelope item, which is always `application/vnd.sentry.attachment.v2`). |
263-
| `attributes` | object | No | arbitrary attributes that will be queryable on the attachment trace item, similar to spans, logs, and trace metrics. |
264-
265-
221+
To associate an attachment with a span, submit a [trace attachment](/sdk/data-model/envelope-items/#trace-attachment) item with an additional `span_id` item header. The trace attachment _should_ be submitted in the same envelope as the span itself.
266222

223+
- `span_id` is the ID of the span that owns the attachment. If set, the attachment will be dropped with the span if the span is dropped by dynamic sampling, inbound filters or rate limits. That is, Relay treats `span_id` as the owner of the attachment.
224+
- The SDK _may_ set the `span_id` item header to an explicit `null` value. `span_id: null` is treated as “owned by spans”, but not owned by a specific span. That is, the attachment can be dropped if the span quota is exceeded, but it will not be dropped with a specific span because of e.g. inbound filters.

0 commit comments

Comments
 (0)