fix: message formatting errors in GELF exporter

The library used to transport GELF messages did not prefix extra fields
with `_` as was previously assumed and the application name was not
passed correctly from configuration to the exporter. Now fixed.

Related: 
This commit is contained in:
Natalia Goc 2024-09-25 11:23:06 +02:00
parent 0f866a0ded
commit a37354cb18
2 changed files with 9 additions and 1 deletions
pkg/exporters/gelf_exporter

View File

@ -31,10 +31,17 @@ func Log(writer *gelf.UDPWriter, msg GELFMessage) {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
} else {
log.Fatalln("gelf.UDPWriter is not set!")
} }
} }
func (g GELFMessage) GELFFormat() *gelf.Message { func (g GELFMessage) GELFFormat() *gelf.Message {
prefixedExtras := make(map[string]interface{}, len(g.ExtraFields))
for k, v := range g.ExtraFields {
prefixedExtras["_"+k] = v
}
return &gelf.Message{ return &gelf.Message{
Version: "1.1", Version: "1.1",
Host: g.Host, Host: g.Host,
@ -42,6 +49,6 @@ func (g GELFMessage) GELFFormat() *gelf.Message {
Full: g.LongMessage, Full: g.LongMessage,
TimeUnix: float64(g.Timestamp.Unix()), TimeUnix: float64(g.Timestamp.Unix()),
Level: int32(g.Level), Level: int32(g.Level),
Extra: g.ExtraFields, Extra: prefixedExtras,
} }
} }

View File

@ -29,6 +29,7 @@ func New(options ...Option) (*Exporter, error) {
return &Exporter{ return &Exporter{
gelfWriter: writer, gelfWriter: writer,
appName: cfg.AppName,
}, nil }, nil
} }