Skip to content

Commit 725460a

Browse files
feat(logs): Expand attributes section for logs spec and specify defaults for every platform (#13832)
resolves https://linear.app/getsentry/issue/LOGS-28 After testing with some SDKs and getting feedback, we've decided on a list of default attributes the SDKs should try to attach to logs. This includes 1. user attributes from https://develop.sentry.dev/sdk/data-model/event-payloads/user/ 2. browser attributes, parsed from user agents (getsentry/relay#4757) 3. os and device attributes attached to mobile, desktop, and native sdks, based on https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/ I also re-organized this section to make things a bit more clear. --------- Co-authored-by: Philipp Hofmann <[email protected]>
1 parent d427dce commit 725460a

File tree

1 file changed

+89
-17
lines changed

1 file changed

+89
-17
lines changed

develop-docs/sdk/telemetry/logs.mdx

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,33 +268,39 @@ An SDK should implement [Tracing without Performance](/sdk/telemetry/traces/trac
268268

269269
### Default Attributes
270270

271-
By default the SDK should set the following attributes:
271+
By default the SDK should attach the following attributes to a log:
272272

273-
1. `sentry.message.template`: The parameterized template string
274-
2. `sentry.message.parameter.X`: The parameters to the template string. X can either be the number that represent the parameter's position in the template string (`sentry.message.parameter.0`, `sentry.message.parameter.1`, etc) or the parameter's name (`sentry.message.parameter.item_id`, `sentry.message.parameter.user_id`, etc)
275-
3. `sentry.environment`: The environment set in the SDK
276-
4. `sentry.release`: The release set in the SDK
277-
5. `sentry.trace.parent_span_id`: The span id of the span that was active when the log was collected. This should not be set if there was no active span.
278-
6. `sentry.sdk.name`: The name of the SDK that sent the log
279-
7. `sentry.sdk.version`: The version of the SDK that sent the log
280-
8. [BACKEND SDKS ONLY] `server.address`: The address of the server that sent the log. Equivalent to `server_name` we attach to errors and transactions.
281-
282-
Example:
273+
1. `sentry.environment`: The environment set in the SDK if defined.
274+
2. `sentry.release`: The release set in the SDK if defined.
275+
3. `sentry.trace.parent_span_id`: The span id of the span that was active when the log was collected. This should not be set if there was no active span.
276+
4. `sentry.sdk.name`: The name of the SDK that sent the log
277+
5. `sentry.sdk.version`: The version of the SDK that sent the log
283278

284279
```json
285280
{
286-
"sentry.message.template": "Adding item %s for user %s",
287-
"sentry.message.parameter.0": "item_id",
288-
"sentry.message.parameter.1": "user_id",
289281
"sentry.environment": "production",
290282
"sentry.release": "1.0.0",
291283
"sentry.trace.parent_span_id": "b0e6f15b45c36b12",
292284
"sentry.sdk.name": "sentry.javascript.node",
293-
"sentry.sdk.version": "9.11.0",
294-
"server.address": "foo.example.com"
285+
"sentry.sdk.version": "9.11.0"
295286
}
296287
```
297288

289+
If the log was paramaterized the SDK should attach the following
290+
291+
1. `sentry.message.template`: The parameterized template string
292+
2. `sentry.message.parameter.X`: The parameters to the template string. X can either be the number that represent the parameter's position in the template string (`sentry.message.parameter.0`, `sentry.message.parameter.1`, etc) or the parameter's name (`sentry.message.parameter.item_id`, `sentry.message.parameter.user_id`, etc)
293+
294+
```json
295+
{
296+
"sentry.message.template": "Adding item %s for user %s",
297+
"sentry.message.parameter.0": "item_id",
298+
"sentry.message.parameter.1": "user_id"
299+
}
300+
```
301+
302+
#### SDK Integration Attributes
303+
298304
If a log is generated by an SDK integration, the SDK should also set the `sentry.origin` attribute, as per the [Trace Origin](/sdk/telemetry/traces/trace-origin/) documentation. It is assumed that logs without a `sentry.origin` attribute are manually created by the user.
299305

300306
```json
@@ -303,7 +309,73 @@ If a log is generated by an SDK integration, the SDK should also set the `sentry
303309
}
304310
```
305311

306-
Beyond these attributes, we are exploring if the SDK should also send OS, user, and device information automatically (via reading the appropriate contexts from the scope). Given this behaviour can easily be added as a new feature to the SDK, it does not have to be part of the initial SDK implementation until we make a finalized decision.
312+
#### User Attributes
313+
314+
If `sendDefaultPii`/`send_default_pii` is set to `true` in the SDK, the SDK should attach the following user data if available:
315+
316+
1. `user.id`: The user ID. Maps to `id` in the [User](/sdk/data-model/event-payloads/user/) payload.
317+
2. `user.name`: The username. Maps to `username` in the [User](/sdk/data-model/event-payloads/user/) payload.
318+
3. `user.email`: The email address. Maps to `email` in the [User](/sdk/data-model/event-payloads/user/) payload.
319+
320+
```json
321+
{
322+
"user.id": "123",
323+
"user.name": "john.doe",
324+
"user.email": "[email protected]"
325+
}
326+
```
327+
328+
#### User Agent Parsing
329+
330+
By default, Relay should parse the user agent attached to an incoming log envelope to parse `browser` and `os` information for logs. These attributes should be attached by Relay, but SDKs can attach them if they do not forward a user agent when sending logs to Sentry.
331+
332+
1. `browser.name`: Display name of the browser application. Maps to `name` in the [Contexts](/sdk/data-model/event-payloads/contexts/#browser-context) payload.
333+
2. `browser.version`: Version string of the browser. Maps to `version` in the [Contexts](/sdk/data-model/event-payloads/contexts/#browser-context) payload.
334+
335+
```json
336+
{
337+
"browser.name": "Chrome",
338+
"browser.version": "120.0"
339+
}
340+
```
341+
342+
#### Backend SDKs
343+
344+
For backend SDKs (Node.js, Python, PHP, etc.), the SDKs should attach the following:
345+
346+
1. `server.address`: The address of the server that sent the log. Equivalent to [`server_name`](sdk/data-model/event-payloads/#optional-attributes) we attach to errors and transactions.
347+
348+
```json
349+
{
350+
"server.address": "foo.example.com"
351+
}
352+
```
353+
354+
#### Mobile, Desktop, and Native SDKs
355+
356+
For mobile, desktop, and native SDKs (Android, Apple, Electron, etc.), the SDKs should attach the following:
357+
358+
1. `os.name`: The name of the operating system. Maps to `name` in the [Contexts](/sdk/data-model/event-payloads/contexts/#os-context) payload.
359+
2. `os.version`: The version of the operating system. Maps to `version` in the [Contexts](/sdk/data-model/event-payloads/contexts/#os-context) payload.
360+
3. `device.brand`: The brand of the device. Maps to `brand` in the [Contexts](/sdk/data-model/event-payloads/contexts/#device-context) payload.
361+
4. `device.model`: The model of the device. Maps to `model` in the [Contexts](/sdk/data-model/event-payloads/contexts/#device-context) payload.
362+
5. `device.family`: The family of the device. Maps to `family` in the [Contexts](/sdk/data-model/event-payloads/contexts/#device-context) payload.
363+
364+
```json
365+
{
366+
"os.name": "iOS",
367+
"os.version": "17.0",
368+
"device.brand": "Apple",
369+
"device.model": "iPhone 15 Pro Max",
370+
"device.family": "iPhone"
371+
}
372+
```
373+
374+
#### Future Default Attributes
375+
376+
The SDKs should aim to minimize the number of default attributes attached to a log. Logs are intended to be lightweight, and we want to try to keep the average byte size of a log as small as possible as users will be charged per byte size of logs sent.
377+
378+
We are trying to settle on a balance of debuggability vs. smaller byte size for logs which is why new default attributes should only be added after significant feedback from users and discussion internally with the SDK and ingest teams. There is no hard rule about what exact attributes are allowed, every proposed new attribute will be evaluated on a case-by-case basis.
307379

308380
### Data Category and Rate Limiting
309381

0 commit comments

Comments
 (0)