standardize commonly used attributes
Some commonly used at maal attributes have been encoded as consts with convinience wrappers similar to those of semconv package from otel sdk. Additionally some utils that can generate mutliple attributes were added.
This commit is contained in:
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"time"
|
||||
|
||||
"git.ma-al.com/gora_filip/observer/pkg/level"
|
||||
"git.ma-al.com/gora_filip/pkg/syslog"
|
||||
"gopkg.in/Graylog2/go-gelf.v2/gelf"
|
||||
)
|
||||
|
||||
@ -20,7 +20,7 @@ type GELFMessage struct {
|
||||
// Timestamp in Unix
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
// Severity level matching Syslog standard.
|
||||
Level level.SyslogLevel `json:"level"`
|
||||
Level syslog.SyslogLevel `json:"level"`
|
||||
|
||||
// All additional field names must start with an underline.
|
||||
ExtraFields map[string]interface{} `json:"extrafields,omitempty"`
|
||||
|
@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"git.ma-al.com/gora_filip/observer/pkg/level"
|
||||
"git.ma-al.com/gora_filip/pkg/attr"
|
||||
"git.ma-al.com/gora_filip/pkg/level"
|
||||
"git.ma-al.com/gora_filip/pkg/syslog"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
@ -69,24 +71,26 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
|
||||
event := stub.Events[i]
|
||||
|
||||
var gelf GELFMessage = GELFMessage{
|
||||
Host: "salego",
|
||||
Host: e.appName,
|
||||
ShortMessage: event.Name,
|
||||
Timestamp: stub.StartTime,
|
||||
Level: level.DEBUG,
|
||||
ExtraFields: attributes,
|
||||
// Defaults to ALERT since we consider lack of the level a serious error that should be fixed ASAP.
|
||||
// Otherwise some dangerous unexpected behaviour could go unnoticed.
|
||||
Level: syslog.ALERT,
|
||||
ExtraFields: attributes,
|
||||
}
|
||||
for _, attr := range event.Attributes {
|
||||
if attr.Key == "long_message_" {
|
||||
gelf.LongMessage = attr.Value.AsString()
|
||||
for _, attrKV := range event.Attributes {
|
||||
if attrKV.Key == "long_message" {
|
||||
gelf.LongMessage = attrKV.Value.AsString()
|
||||
continue
|
||||
}
|
||||
|
||||
if attr.Key == "level_" {
|
||||
gelf.Level = level.SyslogLevel(attr.Value.AsInt64())
|
||||
if attrKV.Key == attr.SeverityLevelKey {
|
||||
gelf.Level = level.FromString(attrKV.Value.AsString()).IntoSyslogLevel()
|
||||
continue
|
||||
}
|
||||
|
||||
attributes[string(attr.Key)] = GetByType(attr.Value)
|
||||
attributes[string(attrKV.Key)] = GetByType(attrKV.Value)
|
||||
}
|
||||
|
||||
Log(e.gelfWriter, gelf)
|
||||
|
Reference in New Issue
Block a user