From 7fbf9095f562dc692368108e374303e14232ca9f Mon Sep 17 00:00:00 2001 From: Marek Goc Date: Thu, 14 Nov 2024 12:00:44 +0100 Subject: [PATCH] add tag name --- pkg/exporters/gelf_exporter/config.go | 12 ++++++++++++ pkg/exporters/gelf_exporter/gelf.go | 3 +++ pkg/exporters/gelf_exporter/trace.go | 2 ++ 3 files changed, 17 insertions(+) diff --git a/pkg/exporters/gelf_exporter/config.go b/pkg/exporters/gelf_exporter/config.go index e9315d2..7de43cf 100644 --- a/pkg/exporters/gelf_exporter/config.go +++ b/pkg/exporters/gelf_exporter/config.go @@ -3,6 +3,7 @@ package gelfexporter type config struct { GelfUrl string AppName string + Tag string } // newConfig creates a validated Config configured with options. @@ -40,3 +41,14 @@ func (o appName) apply(cfg config) config { cfg.AppName = string(o) return cfg } + +func WithTag(tagStr string) Option { + return tag(tagStr) +} + +type tag string + +func (o tag) apply(cfg config) config { + cfg.Tag = string(o) + return cfg +} diff --git a/pkg/exporters/gelf_exporter/gelf.go b/pkg/exporters/gelf_exporter/gelf.go index d12cc5e..17f2143 100644 --- a/pkg/exporters/gelf_exporter/gelf.go +++ b/pkg/exporters/gelf_exporter/gelf.go @@ -23,6 +23,8 @@ type GELFMessage struct { // All additional field names must start with an underline. ExtraFields map[string]interface{} `json:"extrafields,omitempty"` + + Tag string `json:"tag,omitempty"` } func Log(writer *gelf.UDPWriter, msg GELFMessage) { @@ -38,6 +40,7 @@ func Log(writer *gelf.UDPWriter, msg GELFMessage) { func (g GELFMessage) GELFFormat() *gelf.Message { prefixedExtras := make(map[string]interface{}, len(g.ExtraFields)) + prefixedExtras["tag"] = g.Tag for k, v := range g.ExtraFields { prefixedExtras["_"+k] = v } diff --git a/pkg/exporters/gelf_exporter/trace.go b/pkg/exporters/gelf_exporter/trace.go index 873655c..77a59b3 100644 --- a/pkg/exporters/gelf_exporter/trace.go +++ b/pkg/exporters/gelf_exporter/trace.go @@ -30,6 +30,7 @@ func New(options ...Option) (*Exporter, error) { return &Exporter{ gelfWriter: writer, appName: cfg.AppName, + tag: cfg.Tag, }, nil } @@ -37,6 +38,7 @@ func New(options ...Option) (*Exporter, error) { type Exporter struct { gelfWriter *gelf.UDPWriter appName string + tag string stoppedMu sync.RWMutex stopped bool }