Skip to content

Commit

Permalink
[chore] adapt message sent by the syslog data sender to fit rfc5424 f…
Browse files Browse the repository at this point in the history
…ormat (open-telemetry#35201)

**Description:** This PR adapts the syslog data sender to generate valid
messages adhering to the RFC5424 format. Previously, the data sender
generated invalid messages causing the syslog message parser to fail
(due to empty attribute values, a missing version number and SDID

**Link to tracking Issue:** -

**Testing:** -

**Documentation:** -

---------

Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl authored Sep 17, 2024
1 parent c1e2df6 commit 624b368
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions testbed/datasenders/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,20 @@ func (f *SyslogWriter) GenConfigYAMLStr() string {
func (f *SyslogWriter) Send(lr plog.LogRecord) error {
ts := time.Unix(int64(lr.Timestamp()/1_000_000_000), int64(lr.Timestamp()%1_000_000_000)).Format(time.RFC3339Nano)
sdid := strings.Builder{}
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "trace_id", lr.TraceID()))
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "span_id", lr.SpanID()))
if lr.TraceID().String() != "" {
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "trace_id", lr.TraceID()))
}
if lr.SpanID().String() != "" {
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", "span_id", lr.SpanID()))
}
sdid.WriteString(fmt.Sprintf("%s=\"%d\" ", "trace_flags", lr.Flags()))
lr.Attributes().Range(func(k string, v pcommon.Value) bool {
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", k, v.Str()))
if v.Str() != "" {
sdid.WriteString(fmt.Sprintf("%s=\"%s\" ", k, v.Str()))
}
return true
})
msg := fmt.Sprintf("<166> %s 127.0.0.1 - - - [%s] %s\n", ts, sdid.String(), lr.Body().Str())
msg := fmt.Sprintf("<166>1 %s 127.0.0.1 - - - [test@12345 %s] %s\n", ts, strings.TrimSpace(sdid.String()), lr.Body().Str())

f.buf = append(f.buf, msg)
return f.SendCheck()
Expand Down

0 comments on commit 624b368

Please sign in to comment.