Skip to content

Commit 47048e5

Browse files
Refactor SDK logs default attributes to modular, reusable platform includes
Co-authored-by: aprasad <[email protected]>
1 parent 7136f13 commit 47048e5

File tree

26 files changed

+236
-404
lines changed

26 files changed

+236
-404
lines changed

SDK_LOGS_DEFAULT_ATTRIBUTES_UPDATE.md

Lines changed: 103 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,53 @@ This document summarizes the changes made to update all SDK documentation files
66

77
## Changes Made
88

9-
### 1. Created Default Attributes Platform Includes
10-
11-
Created a new directory `platform-includes/logs/default-attributes/` with specific files for each SDK:
12-
13-
- **JavaScript SDK** (`javascript.mdx`):
14-
- Core attributes: `sentry.environment`, `sentry.release`, `sentry.trace.parent_span_id`, `sentry.sdk.name`, `sentry.sdk.version`
15-
- Message template attributes: `sentry.message.template`, `sentry.message.parameter.X`
16-
- User attributes: `user.id`, `user.name`, `user.email`
17-
- **Browser-specific**: `browser.name`, `browser.version`
18-
- **Server-specific**: `server.address`
19-
20-
- **Python SDK** (`python.mdx`):
21-
- Core attributes: Standard SDK attributes
22-
- Message template attributes: For `{attribute_name}` placeholder syntax
23-
- User attributes: Standard user attributes
24-
- **Server-specific**: `server.address`
25-
26-
- **PHP SDK** (`php.mdx`):
27-
- Core attributes: Standard SDK attributes
28-
- Message template attributes: For format specifiers like `%s`
29-
- User attributes: Standard user attributes
30-
- **Server-specific**: `server.address`
31-
32-
- **Java SDK** (`java.mdx`):
33-
- Core attributes: Standard SDK attributes
34-
- Message template attributes: For format specifiers like `%s`
35-
- User attributes: Standard user attributes
36-
- **Server-specific**: `server.address`
37-
38-
- **Ruby SDK** (`ruby.mdx`):
39-
- Core attributes: Standard SDK attributes
40-
- Message template attributes: For format specifiers like `%s`
41-
- User attributes: Standard user attributes
42-
- **Server-specific**: `server.address`
43-
44-
- **Android SDK** (`android.mdx`):
45-
- Core attributes: Standard SDK attributes with `sentry.java.android` as sdk name
46-
- Message template attributes: For format specifiers
47-
- User attributes: Standard user attributes
48-
- **Mobile-specific**: `os.name`, `os.version`, `device.brand`, `device.model`, `device.family`
49-
50-
- **React Native SDK** (`react-native.mdx`):
51-
- Core attributes: Standard SDK attributes with `sentry.javascript.react-native` as sdk name
52-
- Message template attributes: For `logger.fmt` or format strings
53-
- User attributes: Standard user attributes
54-
- **Mobile-specific**: `os.name`, `os.version`, `device.brand`, `device.model`, `device.family`
55-
56-
- **Dart SDK** (`dart.mdx`):
57-
- Core attributes: Standard SDK attributes with `sentry.dart` or `sentry.dart.flutter` as sdk name
58-
- Message template attributes: For format specifiers
59-
- User attributes: Standard user attributes
60-
- **Mobile-specific** (Flutter): `os.name`, `os.version`, `device.brand`, `device.model`, `device.family`
61-
62-
- **Rust SDK** (`rust.mdx`):
63-
- Core attributes: Standard SDK attributes with `sentry.rust` as sdk name
64-
- Message template attributes: For format specifiers
65-
- User attributes: Standard user attributes
66-
- **Server-specific**: `server.address`
9+
### 1. Created Modular Default Attributes Platform Includes
10+
11+
Created a new modular structure in `platform-includes/logs/default-attributes/` with separate files for different types of attributes:
12+
13+
#### Core Shared Attributes
14+
- **`core.mdx`**: Core attributes common to all SDKs
15+
- `sentry.environment`, `sentry.release`, `sentry.trace.parent_span_id`, `sentry.sdk.name`, `sentry.sdk.version`
16+
17+
- **`user.mdx`**: User attributes common to all SDKs
18+
- `user.id`, `user.name`, `user.email`
19+
20+
- **`browser.mdx`**: Browser-specific attributes
21+
- `browser.name`, `browser.version`
22+
23+
- **`server.mdx`**: Server-specific attributes
24+
- `server.address`
25+
26+
- **`mobile.mdx`**: Mobile device-specific attributes
27+
- `os.name`, `os.version`, `device.brand`, `device.model`, `device.family`
28+
29+
#### Message Template Attributes (SDK-specific)
30+
- **`message-template/javascript.mdx`**: For `logger.fmt` or format strings
31+
- **`message-template/python.mdx`**: For `{attribute_name}` placeholder syntax
32+
- **`message-template/php.mdx`**: For format specifiers like `%s`
33+
- **`message-template/java.mdx`**: For format specifiers like `%s`
34+
- **`message-template/ruby.mdx`**: For format specifiers like `%s`
35+
- **`message-template/android.mdx`**: For format specifiers
36+
- **`message-template/dart.mdx`**: For format specifiers
37+
- **`message-template/rust.mdx`**: For format specifiers
38+
- **`message-template/go.mdx`**: For format specifiers like `%v`
39+
40+
#### SDK-Specific Composition Files
41+
Each SDK has its own composition file that includes the relevant modular components:
42+
43+
- **`javascript.mdx`**: Includes core + javascript message template + user + browser + server
44+
- **`python.mdx`**: Includes core + python message template + user + server
45+
- **`php.mdx`**: Includes core + php message template + user + server
46+
- **`java.mdx`**: Includes core + java message template + user + server
47+
- **`ruby.mdx`**: Includes core + ruby message template + user + server
48+
- **`android.mdx`**: Includes core + android message template + user + mobile
49+
- **`react-native.mdx`**: Includes core + javascript message template + user + mobile
50+
- **`dart.mdx`**: Includes core + dart message template + user + mobile
51+
- **`rust.mdx`**: Includes core + rust message template + user + server
6752

6853
### 2. Updated SDK Documentation Files
6954

70-
Updated the following SDK documentation files to include the new "Default Attributes" section:
55+
Updated all SDK documentation files to include the new "Default Attributes" section:
7156

7257
#### Files Using Platform Includes:
7358
- `docs/platforms/python/logs/index.mdx`
@@ -79,9 +64,29 @@ Updated the following SDK documentation files to include the new "Default Attrib
7964
- `docs/platforms/react-native/logs/index.mdx`
8065
- `docs/platforms/dart/guides/flutter/logs/index.mdx`
8166

82-
#### Files with Explicit Content:
83-
- `docs/platforms/go/common/logs/index.mdx` - Added detailed default attributes section
84-
- `docs/platforms/rust/common/logs/index.mdx` - Added detailed default attributes section
67+
#### Files Updated to Use Modular Includes:
68+
- `docs/platforms/go/common/logs/index.mdx` - Updated to use modular includes
69+
- `docs/platforms/rust/common/logs/index.mdx` - Updated to use modular includes
70+
71+
## Benefits of Modular Structure
72+
73+
### 1. **Maintainability**
74+
- Each type of attribute is defined in one place
75+
- Changes to core attributes affect all SDKs automatically
76+
- No duplication of common content
77+
78+
### 2. **Consistency**
79+
- All SDKs use the same definitions for shared attributes
80+
- Consistent formatting and explanations across all platforms
81+
82+
### 3. **Flexibility**
83+
- Easy to add new attribute types
84+
- Simple to customize message template explanations per SDK
85+
- Easy to compose different attribute sets for different SDK types
86+
87+
### 4. **Reusability**
88+
- Common attributes can be reused across multiple SDKs
89+
- Easy to add new SDKs by composing existing modules
8590

8691
## Default Attributes by SDK Type
8792

@@ -115,58 +120,45 @@ Updated the following SDK documentation files to include the new "Default Attrib
115120
- `device.model`: Model of the device
116121
- `device.family`: Family of the device
117122

123+
## File Structure
124+
125+
```
126+
platform-includes/logs/default-attributes/
127+
├── core.mdx # Core attributes (all SDKs)
128+
├── user.mdx # User attributes (all SDKs)
129+
├── browser.mdx # Browser attributes (browser SDKs)
130+
├── server.mdx # Server attributes (backend SDKs)
131+
├── mobile.mdx # Mobile attributes (mobile SDKs)
132+
├── message-template/ # Message template attributes (SDK-specific)
133+
│ ├── javascript.mdx # logger.fmt syntax
134+
│ ├── python.mdx # {attribute_name} syntax
135+
│ ├── php.mdx # %s format specifiers
136+
│ ├── java.mdx # %s format specifiers
137+
│ ├── ruby.mdx # %s format specifiers
138+
│ ├── android.mdx # format specifiers
139+
│ ├── dart.mdx # format specifiers
140+
│ ├── rust.mdx # format specifiers
141+
│ └── go.mdx # %v format specifiers
142+
├── javascript.mdx # Composition for JavaScript SDK
143+
├── python.mdx # Composition for Python SDK
144+
├── php.mdx # Composition for PHP SDK
145+
├── java.mdx # Composition for Java SDK
146+
├── ruby.mdx # Composition for Ruby SDK
147+
├── android.mdx # Composition for Android SDK
148+
├── react-native.mdx # Composition for React Native SDK
149+
├── dart.mdx # Composition for Dart SDK
150+
└── rust.mdx # Composition for Rust SDK
151+
```
152+
118153
## Implementation Details
119154

120-
1. **Attribute Specificity**: Each SDK only mentions attributes relevant to its platform type. For example:
121-
- Browser attributes are only mentioned for JavaScript browser SDKs
122-
- Mobile device attributes are only mentioned for Android, React Native, and Flutter SDKs
123-
- Server attributes are only mentioned for backend SDKs
124-
125-
2. **Message Template Context**: Each SDK's default attributes documentation explains its specific message templating syntax:
126-
- JavaScript: `logger.fmt` or format strings
127-
- Python: `{attribute_name}` placeholder syntax
128-
- PHP/Java/Ruby: Format specifiers like `%s`
129-
- Go: Format specifiers like `%v`
130-
- Rust: Format syntax
131-
132-
3. **SDK Name Specificity**: Each SDK documents its specific `sentry.sdk.name` value:
133-
- JavaScript: `sentry.javascript.browser`, `sentry.javascript.node`, etc.
134-
- Python: `sentry.python`
135-
- PHP: `sentry.php`
136-
- Java: `sentry.java`
137-
- Android: `sentry.java.android`
138-
- React Native: `sentry.javascript.react-native`
139-
- Dart: `sentry.dart` or `sentry.dart.flutter`
140-
- Go: `sentry.go`
141-
- Ruby: `sentry.ruby`
142-
- Rust: `sentry.rust`
155+
1. **Modular Design**: Each attribute type is defined once and reused across relevant SDKs
156+
2. **Attribute Specificity**: Each SDK only includes attributes relevant to its platform type
157+
3. **Message Template Context**: Each SDK has its own message template explanation for its specific syntax
158+
4. **Consistent Formatting**: All shared attributes use the same formatting and descriptions
143159

144160
## SDKs Supported
145161

146-
All SDKs listed on the [Logs Getting Started page](https://docs.sentry.io/product/explore/logs/getting-started/) now have default attributes documentation:
147-
148-
### JavaScript (all variants)
149-
- Browser JavaScript, Angular, Astro, AWS Lambda, Azure Functions, Bun, Cloudflare, Connect, Electron, Ember, Express, Fastify, Gatsby, Google Cloud Functions, Hapi, Hono, Koa, Nest.js, Node.js, Next.js, Nuxt, React, React Router, Remix, Solid, SolidStart, Svelte, SvelteKit, TanStack Start, Vue, Wasm
150-
151-
### Java
152-
- Java, Spring, Spring Boot
153-
154-
### Mobile
155-
- Android, Flutter, React Native
156-
157-
### PHP
158-
- PHP, Laravel
159-
160-
### Python
161-
- Python
162-
163-
### Ruby
164-
- Ruby
165-
166-
### Go
167-
- Go
168-
169-
### Rust
170-
- Rust
162+
All SDKs listed on the [Logs Getting Started page](https://docs.sentry.io/product/explore/logs/getting-started/) now have modular default attributes documentation that provides consistent, maintainable information about what attributes will be automatically attached to their log entries.
171163

172-
This ensures that developers using any of these SDKs can now understand exactly what default attributes will be automatically attached to their log entries, helping them make better use of Sentry's structured logging capabilities.
164+
This modular approach makes it easy to maintain consistency across all SDK documentation while allowing for platform-specific customizations where needed.

docs/platforms/go/common/logs/index.mdx

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -132,34 +132,13 @@ We're actively working on adding more integration support for Logs. Currently, w
132132

133133
The Go SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
134134

135-
### Core Attributes
135+
<Include name="logs/default-attributes/core.mdx" />
136136

137-
- `sentry.environment`: The environment set in the SDK if defined
138-
- `sentry.release`: The release set in the SDK if defined
139-
- `sentry.trace.parent_span_id`: The span ID of the span that was active when the log was collected (only set if there was an active span)
140-
- `sentry.sdk.name`: The name of the SDK that sent the log (`sentry.go`)
141-
- `sentry.sdk.version`: The version of the SDK that sent the log
137+
<Include name="logs/default-attributes/message-template/go.mdx" />
142138

143-
### Message Template Attributes
139+
<Include name="logs/default-attributes/user.mdx" />
144140

145-
If the log was parameterized using format specifiers (like `%v`), the SDK will also set:
146-
147-
- `sentry.message.template`: The parameterized template string
148-
- `sentry.message.parameter.X`: The parameters to the template string, where X is the parameter's position
149-
150-
### User Attributes
151-
152-
If user information is available in the current scope:
153-
154-
- `user.id`: The user ID
155-
- `user.name`: The username
156-
- `user.email`: The email address
157-
158-
### Server Attributes
159-
160-
For backend applications:
161-
162-
- `server.address`: The address of the server that sent the log (equivalent to server_name attached to errors and transactions)
141+
<Include name="logs/default-attributes/server.mdx" />
163142

164143
## Options
165144

docs/platforms/rust/common/logs/index.mdx

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,34 +208,13 @@ If you'd like to see support for additional logging libraries, please open a [ne
208208

209209
The Rust SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
210210

211-
### Core Attributes
211+
<Include name="logs/default-attributes/core.mdx" />
212212

213-
- `sentry.environment`: The environment set in the SDK if defined
214-
- `sentry.release`: The release set in the SDK if defined
215-
- `sentry.trace.parent_span_id`: The span ID of the span that was active when the log was collected (only set if there was an active span)
216-
- `sentry.sdk.name`: The name of the SDK that sent the log (`sentry.rust`)
217-
- `sentry.sdk.version`: The version of the SDK that sent the log
213+
<Include name="logs/default-attributes/message-template/rust.mdx" />
218214

219-
### Message Template Attributes
215+
<Include name="logs/default-attributes/user.mdx" />
220216

221-
If the log was parameterized using format specifiers, the SDK will also set:
222-
223-
- `sentry.message.template`: The parameterized template string
224-
- `sentry.message.parameter.X`: The parameters to the template string, where X is the parameter's position
225-
226-
### User Attributes
227-
228-
If user information is available in the current scope:
229-
230-
- `user.id`: The user ID
231-
- `user.name`: The username
232-
- `user.email`: The email address
233-
234-
### Server Attributes
235-
236-
For backend applications:
237-
238-
- `server.address`: The address of the server that sent the log (equivalent to server_name attached to errors and transactions)
217+
<Include name="logs/default-attributes/server.mdx" />
239218

240219
## Options
241220

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
11
The Android SDK automatically sets several default attributes on all log entries to provide context and improve debugging:
22

3-
### Core Attributes
3+
<Include name="logs/default-attributes/core.mdx" />
44

5-
- `sentry.environment`: The environment set in the SDK if defined
6-
- `sentry.release`: The release set in the SDK if defined
7-
- `sentry.trace.parent_span_id`: The span ID of the span that was active when the log was collected (only set if there was an active span)
8-
- `sentry.sdk.name`: The name of the SDK that sent the log (`sentry.java.android`)
9-
- `sentry.sdk.version`: The version of the SDK that sent the log
5+
<Include name="logs/default-attributes/message-template/android.mdx" />
106

11-
### Message Template Attributes
7+
<Include name="logs/default-attributes/user.mdx" />
128

13-
If the log was parameterized using format specifiers, the SDK will also set:
14-
15-
- `sentry.message.template`: The parameterized template string
16-
- `sentry.message.parameter.X`: The parameters to the template string, where X is the parameter's position
17-
18-
### User Attributes
19-
20-
If user information is available in the current scope:
21-
22-
- `user.id`: The user ID
23-
- `user.name`: The username
24-
- `user.email`: The email address
25-
26-
### Mobile Device Attributes
27-
28-
For mobile applications:
29-
30-
- `os.name`: The name of the operating system (`Android`)
31-
- `os.version`: The version of the operating system
32-
- `device.brand`: The brand of the device (e.g., `Samsung`, `Google`)
33-
- `device.model`: The model of the device (e.g., `SM-G973F`, `Pixel 5`)
34-
- `device.family`: The family of the device
9+
<Include name="logs/default-attributes/mobile.mdx" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Browser Attributes
2+
3+
For browser-based applications:
4+
5+
- `browser.name`: Display name of the browser application
6+
- `browser.version`: Version string of the browser
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Core Attributes
2+
3+
- `sentry.environment`: The environment set in the SDK if defined
4+
- `sentry.release`: The release set in the SDK if defined
5+
- `sentry.trace.parent_span_id`: The span ID of the span that was active when the log was collected (only set if there was an active span)
6+
- `sentry.sdk.name`: The name of the SDK that sent the log
7+
- `sentry.sdk.version`: The version of the SDK that sent the log

0 commit comments

Comments
 (0)