Skip to content

Commit cf417ae

Browse files
committed
This fixes open-telemetry#33300 by making sure that each structured data block
is built up as its own array (rather than as one single array as it was done before). String builder (strings.Builder) was used to buffer the final string that is built up.
1 parent c3b0227 commit cf417ae

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

exporter/syslogexporter/rfc5424_formatter.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package syslogexporter // import "github.com/open-telemetry/opentelemetry-collec
66
import (
77
"fmt"
88
"strconv"
9+
"strings"
910
"time"
1011

1112
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -78,9 +79,9 @@ func (f *rfc5424Formatter) formatStructuredData(logRecord plog.LogRecord) string
7879
return emptyValue
7980
}
8081

81-
sdElements := []string{}
82+
var sdBuilder strings.Builder
8283
for key, val := range structuredDataAttributeValue.Map().AsRaw() {
83-
sdElements = append(sdElements, key)
84+
sdElements := []string{key}
8485
vval, ok := val.(map[string]any)
8586
if !ok {
8687
continue
@@ -92,8 +93,9 @@ func (f *rfc5424Formatter) formatStructuredData(logRecord plog.LogRecord) string
9293
}
9394
sdElements = append(sdElements, fmt.Sprintf("%s=\"%s\"", k, vv))
9495
}
96+
sdBuilder.WriteString(fmt.Sprint(sdElements))
9597
}
96-
return fmt.Sprint(sdElements)
98+
return sdBuilder.String()
9799
}
98100

99101
func (f *rfc5424Formatter) formatMessage(logRecord plog.LogRecord) string {

0 commit comments

Comments
 (0)