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
Receive all logs if no attributes are specified (#37721)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
I'm proposing a new convention where if the attributes field is empty,
then it indicates we want to ingest everything that is sent. This helps
users avoid having to modify which fields they want in two places. Happy
to submit a PR myself. Please check out the linked issue and let me know
if you approve or want any changes. Then I will finish implementing
whatever else is necessary (e.g docs, tests).
<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes#37720
<!--Describe what testing was performed and which tests were added.-->
#### Testing
I added a `TestEmptyAttributes()` test to verify the behavior in
`logs_test.go`
<!--Describe the documentation added.-->
#### Documentation
I documented the new behavior in the `README.md` and added a separate
config example of how it can be used
<!--Please delete paragraphs that you did not use before submitting.-->
Copy file name to clipboardExpand all lines: receiver/cloudflarereceiver/README.md
+16
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,7 @@ If the receiver will be handling TLS termination:
48
48
- This receiver was built with the Cloudflare `http_requests` dataset in mind, but should be able to support any Cloudflare dataset. If using another dataset, you will need to set the `timestamp_field` appropriately in order to have the log record be associated with the correct timestamp. the timestamp must be formatted RFC3339, as stated in the Getting Started section.
49
49
-`attributes`
50
50
- This parameter allows the receiver to be configured to set log record attributes based on fields found in the log message. The fields are not removed from the log message when set in this way. Only string, boolean, integer or float fields can be mapped using this parameter.
51
+
- When the `attributes` configuration is empty, the receiver will automatically ingest all fields from the log messages as attributes, using the original field names as attribute names.
l.logger.Warn("unable to translate field to attribute, unsupported type", zap.String("field", field), zap.Any("value", v), zap.String("type", fmt.Sprintf("%T", v)))
275
+
forfield, v:=rangelog {
276
+
attrName:=field
277
+
iflen(l.cfg.Attributes) !=0 {
278
+
// Only process fields that are in the config mapping
279
+
mappedAttr, ok:=l.cfg.Attributes[field]
280
+
if!ok {
281
+
// Skip fields not in mapping when we have a config
282
+
continue
290
283
}
284
+
attrName=mappedAttr
285
+
}
286
+
// else if l.cfg.Attributes is empty, default to processing all fields with no renaming
287
+
288
+
switchv:=v.(type) {
289
+
casestring:
290
+
attrs.PutStr(attrName, v)
291
+
caseint:
292
+
attrs.PutInt(attrName, int64(v))
293
+
caseint64:
294
+
attrs.PutInt(attrName, v)
295
+
casefloat64:
296
+
attrs.PutDouble(attrName, v)
297
+
casebool:
298
+
attrs.PutBool(attrName, v)
299
+
default:
300
+
l.logger.Warn("unable to translate field to attribute, unsupported type",
0 commit comments