Skip to content

Commit

Permalink
fix(sumologicexporter): don't send empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Świątek committed Jun 22, 2023
1 parent 178d930 commit 2a14716
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- chore(sumologicexporter): remove deprecation error messages [#1167]
- chore: update OT core to v0.80.0 [#1169]

### Fixed

- fix(sumologicexporter): don't send empty attributes [#1174]

[#1167]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1167
[#1169]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1169
[#1174]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1174

[unreleased]: https://github.com/SumoLogic/sumologic-otel-collector/compare/v0.79.0-sumo-0...main

Expand Down
19 changes: 14 additions & 5 deletions pkg/exporter/sumologicexporter/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,20 @@ func addJSONTimestamp(attrs pcommon.Map, timestampKey string, pt pcommon.Timesta
}

func isEmptyAttributeValue(att pcommon.Value) bool {
t := att.Type()
return !(t == pcommon.ValueTypeStr && len(att.Str()) > 0 ||
t == pcommon.ValueTypeSlice && att.Slice().Len() > 0 ||
t == pcommon.ValueTypeMap && att.Map().Len() > 0 ||
t == pcommon.ValueTypeBytes && att.Bytes().Len() > 0)
switch att.Type() {
case pcommon.ValueTypeEmpty:
return true
case pcommon.ValueTypeStr:
return len(att.Str()) == 0
case pcommon.ValueTypeSlice:
return att.Slice().Len() == 0
case pcommon.ValueTypeMap:
return att.Map().Len() == 0
case pcommon.ValueTypeBytes:
return att.Bytes().Len() == 0
}

return false
}

// sendNonOTLPLogs sends log records from the logBuffer formatted according
Expand Down
25 changes: 25 additions & 0 deletions pkg/exporter/sumologicexporter/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,31 @@ func TestSendLogsJsonConfig(t *testing.T) {
`{"key1":"value1","key2":"value2","log":"Another example log","timestamp":\d{13}}`,
logsFunc: twoLogsFunc,
},
{
name: "empty body",
configOpts: []func(*Config){
func(c *Config) {
c.JSONLogs = JSONLogs{
LogKey: DefaultLogKey,
AddTimestamp: DefaultAddTimestamp,
TimestampKey: DefaultTimestampKey,
FlattenBody: DefaultFlattenBody,
}
},
},
bodyRegex: `{"key1":"value1","key2":"value2","timestamp":\d{13}}`,

logsFunc: func() plog.ResourceLogs {
rls := plog.NewResourceLogs()
slgs := rls.ScopeLogs().AppendEmpty()
log := slgs.LogRecords().AppendEmpty()

log.Attributes().PutStr("key1", "value1")
log.Attributes().PutStr("key2", "value2")

return rls
},
},
{
name: "disabled add timestamp",
configOpts: []func(*Config){
Expand Down

0 comments on commit 2a14716

Please sign in to comment.