You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pipeline/outputs/stackdriver_special_fields.md
+97-92Lines changed: 97 additions & 92 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,34 +1,35 @@
1
-
# Stackdriver Special fields
1
+
# Stackdriver special fields
2
2
3
3
When the [google-logging-agent](https://cloud.google.com/logging/docs/agent) receives a structured log record, it treats [some fields](https://cloud.google.com/logging/docs/agent/configuration#special-fields) specially, allowing users to set specific fields in the LogEntry object that get written to the Logging API.
4
4
5
-
## Log Entry Fields
5
+
## LogEntry fields
6
6
7
-
Currently, we support some special fields in fluent-bit for setting fields on the LogEntry object:
8
-
| JSON log field |[LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) field | type | Description |
7
+
Fluent Bit support some special fields for setting fields on the LogEntry object:
8
+
9
+
| JSON log field |[LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) field | Type | Description |
9
10
| :--- | :--- | :--- | :--- |
10
11
|`logging.googleapis.com/logName`|`logName`|`string`| The log name to write this log to. |
11
12
|`logging.googleapis.com/labels`|`labels`|`object<string, string>`| The labels for this log. |
12
-
|`logging.googleapis.com/severity`|`severity`|[`LogSeverity`enum](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity)| The severity of this log. |
13
+
|`logging.googleapis.com/severity`|`severity`|[`LogSeverity`Enum](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity)| The severity of this log. |
13
14
|`logging.googleapis.com/monitored_resource`|`resource`|[`MonitoredResource`](https://cloud.google.com/logging/docs/reference/v2/rest/v2/MonitoredResource) (without `type`) | Resource labels for this log. |
14
15
|`logging.googleapis.com/operation`|`operation`|[`LogEntryOperation`](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntryOperation)| Additional information about a potentially long-running operation. |
15
-
|`logging.googleapis.com/insertId`|`insertId`|`string`| A unique identifier for the log entry. It is used to order logEntries. |
16
+
|`logging.googleapis.com/insertId`|`insertId`|`string`| A unique identifier for the log entry. It's used to order `logEntries`. |
16
17
|`logging.googleapis.com/sourceLocation`|`sourceLocation`|[`LogEntrySourceLocation`](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation)| Additional information about the source code location that produced the log entry. |
17
18
|`logging.googleapis.com/http_request`|`httpRequest`|[`HttpRequest`](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest)| A common proto for logging HTTP requests. |
18
19
|`logging.googleapis.com/trace`|`trace`|`string`| Resource name of the trace associated with the log entry. |
19
20
|`logging.googleapis.com/traceSampled`|`traceSampled`| boolean | The sampling decision associated with this log entry. |
20
21
|`logging.googleapis.com/spanId`|`spanId`|`string`| The ID of the trace span associated with this log entry. |
21
-
|`timestamp`|`timestamp`|`object` ([protobuf `Timestamp` object format](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp)) | An object including the seconds and nanos fields that represents the time. |
22
-
|`timestampSecond`&`timestampNanos`|`timestamp`|`int`| The seconds and nanos that represents the time. |
22
+
|`timestamp`|`timestamp`|`object` ([protobuf `Timestamp` object format](https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp)) | An object including the seconds and nanoseconds fields that represent the time. |
23
+
|`timestampSecond`and`timestampNanos`|`timestamp`|`int`| The seconds and nanoseconds that represent the time. |
|`logging.googleapis.com/projectId`| Changes the project ID that this log will be written to. Ensure that you are authenticated to write logs to this project. |
29
-
|`logging.googleapis.com/local_resource_id`| Overrides the [configured `local_resource_id`](./stackdriver.md#resource-labels). |
27
+
| JSON log field | Description |
28
+
|:---------------|:------------|
29
+
|`logging.googleapis.com/projectId`| Changes the project ID that this log will be written to. Ensure that you are authenticated to write logs to this project. |
30
+
|`logging.googleapis.com/local_resource_id`| Overrides the [configured `local_resource_id`](./stackdriver.md#resource-labels). |
30
31
31
-
## Using Special Fields
32
+
## Use special fields
32
33
33
34
To use a special field, you must add a field with the right name and value to your log. Given an example structured log (internally in MessagePack but shown in JSON for demonstration):
34
35
@@ -38,7 +39,7 @@ To use a special field, you must add a field with the right name and value to yo
38
39
}
39
40
```
40
41
41
-
To use the `logging.googleapis.com/logName` special field, you would add it to your structured log as follows:
42
+
To use the `logging.googleapis.com/logName` special field, add it to your structured log as follows:
42
43
43
44
```json
44
45
{
@@ -47,7 +48,7 @@ To use the `logging.googleapis.com/logName` special field, you would add it to y
47
48
}
48
49
```
49
50
50
-
For the special fields that map to `LogEntry` prototypes, you will need to add them as objects with field names that match the proto. For example, to use the `logging.googleapis.com/operation`:
51
+
For the special fields that map to `LogEntry` prototypes, add them as objects with field names that match the proto. For example, to use the `logging.googleapis.com/operation`:
51
52
52
53
```json
53
54
{
@@ -63,62 +64,62 @@ For the special fields that map to `LogEntry` prototypes, you will need to add t
63
64
64
65
Adding special fields to logs is best done through the [`modify` filter](https://docs.fluentbit.io/manual/pipeline/filters/modify) for simple fields, or [a Lua script using the `lua` filter](https://docs.fluentbit.io/manual/pipeline/filters/lua) for more complex fields.
65
66
66
-
## Simple Type Special Fields
67
+
## Simple type special fields
67
68
68
-
For special fields with simple types (except for the [`logging.googleapis.com/insertId` field](#insert-id)), they will follow this pattern (demonstrated with the `logging.googleapis.com/logName` field):
69
+
Special fields with simple types (except for the [`logging.googleapis.com/insertId` field](#insert-id)) will follow this pattern (demonstrated with the `logging.googleapis.com/logName` field):
69
70
70
71
1. If the special field matches the type, it will be moved to the corresponding LogEntry field. For example:
71
72
72
-
```text
73
-
{
74
-
...
75
-
"logging.googleapis.com/logName": "my_log"
76
-
...
77
-
}
78
-
```
79
-
80
-
the logEntry will be:
81
-
82
-
```text
83
-
{
84
-
"jsonPayload": {
85
-
...
86
-
}
87
-
"logName": "my_log"
88
-
...
89
-
}
90
-
```
91
-
92
-
2. If the field is non-empty but an invalid, it will be left in the jsonPayload. For example:
93
-
94
-
```text
95
-
{
96
-
...
97
-
"logging.googleapis.com/logName": 12345
98
-
...
99
-
}
100
-
```
101
-
102
-
the logEntry will be:
103
-
104
-
```text
105
-
{
106
-
"jsonPayload": {
107
-
"logging.googleapis.com/logName": 12345
108
-
...
109
-
}
110
-
}
111
-
```
73
+
```text
74
+
{
75
+
...
76
+
"logging.googleapis.com/logName": "my_log"
77
+
...
78
+
}
79
+
```
80
+
81
+
the `logEntry` will be:
82
+
83
+
```text
84
+
{
85
+
"jsonPayload": {
86
+
...
87
+
}
88
+
"logName": "my_log"
89
+
...
90
+
}
91
+
```
92
+
93
+
1. If the field is non-empty but an invalid, it will be left in the `jsonPayload`. For example:
94
+
95
+
```text
96
+
{
97
+
...
98
+
"logging.googleapis.com/logName": 12345
99
+
...
100
+
}
101
+
```
102
+
103
+
the `logEntry` will be:
104
+
105
+
```text
106
+
{
107
+
"jsonPayload": {
108
+
"logging.googleapis.com/logName": 12345
109
+
...
110
+
}
111
+
}
112
+
```
112
113
113
114
### Exceptions
114
115
115
116
#### Insert ID
116
117
117
118
If the `logging.googleapis.com/insertId` field has an invalid type, the log will be rejected by the plugin and not sent to Cloud Logging.
118
119
119
-
#### Trace Sampled
120
+
#### Trace sampled
120
121
121
-
If the[`autoformat_stackdriver_trace`plugin configuration option]()is set to `true`, the value provided in the `trace` field will be formatted into the format that Cloud Logging expects along with the detected Project ID (from the Google Metadata server, configured in the plugin, or provided via special field).
122
+
If the`autoformat_stackdriver_trace` is set to `true`, the value provided in the `trace` field will be formatted into the format that Cloud Logging expects along with the detected Project ID (from the Google Metadata server, configured in the plugin, or provided using a special field).
122
123
123
124
For example, if `autoformat_stackdriver_trace` is enabled, this:
124
125
@@ -148,11 +149,11 @@ Will become this:
148
149
149
150
The `timestampSecond` and `timestampNano` fields don't map directly to the `timestamp` field in `LogEntry` so the parsing behaviour deviates from other special fields. Read more in the [Timestamp section](#timestamp).
150
151
151
-
## Proto Special Fields
152
+
## Proto special fields
152
153
153
154
For special fields that expect the format of a prototype from the `LogEntry` (except for the `logging.googleapis.com/monitored_resource` field) will follow this pattern (demonstrated with the `logging.googleapis.com/operation` field):
154
155
155
-
If any subfields of the proto are empty or in incorrect type, the plugin will set these subfields empty. For example:
156
+
If any sub-fields of the proto are empty or in incorrect type, the plugin will set these sub-fields empty. For example:
156
157
157
158
```text
158
159
{
@@ -166,7 +167,7 @@ If any subfields of the proto are empty or in incorrect type, the plugin will se
166
167
}
167
168
```
168
169
169
-
the logEntry will be:
170
+
the `logEntry` will be:
170
171
171
172
```text
172
173
{
@@ -181,7 +182,7 @@ the logEntry will be:
181
182
}
182
183
```
183
184
184
-
If the field itself is not a map, the plugin will leave this field untouched. For example:
185
+
If the field itself isn't a map, the plugin will leave this field untouched. For example:
185
186
186
187
```text
187
188
{
@@ -191,7 +192,7 @@ If the field itself is not a map, the plugin will leave this field untouched. Fo
191
192
}
192
193
```
193
194
194
-
the logEntry will be:
195
+
the `logEntry` will be:
195
196
196
197
```text
197
198
{
@@ -203,7 +204,7 @@ the logEntry will be:
203
204
}
204
205
```
205
206
206
-
If there are extra subfields, the plugin will add the recognized fields to the corresponding field in the LogEntry, and preserve the extra subfields in jsonPayload. For example:
207
+
If there are extra sub-fields, the plugin will add the recognized fields to the corresponding field in the LogEntry, and preserve the extra sub-fields in `jsonPayload`. For example:
207
208
208
209
```text
209
210
{
@@ -221,7 +222,7 @@ If there are extra subfields, the plugin will add the recognized fields to the c
221
222
}
222
223
```
223
224
224
-
the logEntry will be:
225
+
the `logEntry will be:
225
226
226
227
```text
227
228
{
@@ -249,45 +250,48 @@ the logEntry will be:
249
250
250
251
The `logging.googleapis.com/monitored_resource` field is parsed in a special way, meaning it has some important exceptions:
251
252
252
-
The `type` field from the [`MonitoredResource` proto]() is not parsed out of the special field. It is read from the [`resource` plugin configuration option](https://docs.fluentbit.io/manual/pipeline/outputs/stackdriver#configuration-parameters). If it is supplied in the `logging.googleapis.com/monitored_resource` special field, it will not be recognized.
253
+
The `type` field from the `MonitoredResource` proto isn't parsed out of the special field. It's read from the [`resource` plugin configuration option](https://docs.fluentbit.io/manual/pipeline/outputs/stackdriver#configuration-parameters). If it's supplied in the `logging.googleapis.com/monitored_resource` special field, it won't be recognized.
253
254
254
-
The `labels` field is expected to be an `object<string, string>`. If any fields have a value that is not a string, the value is ignored and not preserved. The plugin logs an error and drops the field.
255
+
The `labels` field is expected to be an `object<string, string>`. If any fields have a value that's not a string, the value is ignored and not preserved. The plugin logs an error and drops the field.
255
256
256
257
If no valid `labels` field is found, or if all entries in the `labels` object provided are invalid, the `logging.googleapis.com/monitored_resource` field is dropped in favour of automatically setting resource labels using other available information based on the configured `resource` type.
257
258
258
259
## Timestamp
259
260
260
-
We support two formats of time-related fields:
261
+
Fluent Bit supports the following formats of time-related fields:
261
262
262
-
Format 1 - timestamp:
263
-
Log body contains a `timestamp` field that includes the seconds and nanos fields.
263
+
-`timestamp`
264
264
265
-
```text
266
-
{
267
-
"timestamp": {
268
-
"seconds": CURRENT_SECONDS,
269
-
"nanos": CURRENT_NANOS
265
+
Log body contains a `timestamp` field that includes the seconds and nanoseconds fields.
266
+
267
+
```text
268
+
{
269
+
"timestamp": {
270
+
"seconds": CURRENT_SECONDS,
271
+
"nanos": CURRENT_NANOS
272
+
}
270
273
}
271
-
}
272
-
```
274
+
```
273
275
274
-
Format 2 - timestampSeconds/timestampNanos:
275
-
Log body contains both the `timestampSeconds` and `timestampNanos` fields.
276
+
-`timestampSeconds`/`timestampNanos`
276
277
277
-
```text
278
-
{
279
-
"timestampSeconds": CURRENT_SECONDS,
280
-
"timestampNanos": CURRENT_NANOS
281
-
}
282
-
```
278
+
Log body contains both the `timestampSeconds` and `timestampNanos` fields.
279
+
280
+
```text
281
+
{
282
+
"timestampSeconds": CURRENT_SECONDS,
283
+
"timestampNanos": CURRENT_NANOS
284
+
}
285
+
```
283
286
284
287
If one of the following JSON timestamp representations is present in a structured record, the plugin collapses them into a single representation in the timestamp field in the `LogEntry` object.
285
288
286
289
Without time-related fields, the plugin will set the current time as timestamp.
287
290
288
291
### Format 1
289
292
290
-
Set the input log as followed:
293
+
Set the input log as follows:
294
+
291
295
```text
292
296
{
293
297
"timestamp": {
@@ -298,7 +302,7 @@ Set the input log as followed:
298
302
}
299
303
```
300
304
301
-
the logEntry will be:
305
+
the `logEntry` will be:
302
306
303
307
```text
304
308
{
@@ -312,7 +316,8 @@ the logEntry will be:
312
316
313
317
### Format 2
314
318
315
-
Set the input log as followed:
319
+
Set the input log as follows:
320
+
316
321
```text
317
322
{
318
323
"timestampSeconds":1596149787,
@@ -321,7 +326,7 @@ Set the input log as followed:
321
326
}
322
327
```
323
328
324
-
the logEntry will be:
329
+
the `logEntry` will be:
325
330
326
331
```text
327
332
{
@@ -333,4 +338,4 @@ the logEntry will be:
333
338
}
334
339
```
335
340
336
-
If the `timestamp` object or the `timestampSeconds` and `timestampNanos` fields end up being invalid, they will remain in the `jsonPayload` untouched.
341
+
If the `timestamp` object or the `timestampSeconds` and `timestampNanos` fields end up being invalid, they will remain in the `jsonPayload` untouched.
0 commit comments