otelslog currently treats errors fields ordinary fields
That makes exception/error data inconsistent with the OpenTelemetry log semantic conventions and harder to recognize as exception/error information.
The proposal is to change
|
func (h *Handler) convertRecord(r slog.Record) log.Record { |
|
var record log.Record |
|
record.SetTimestamp(r.Time) |
|
record.SetBody(log.StringValue(r.Message)) |
|
|
|
const sevOffset = slog.Level(log.SeverityDebug) - slog.LevelDebug |
|
record.SetSeverity(log.Severity(r.Level + sevOffset)) |
|
record.SetSeverityText(r.Level.String()) |
|
|
|
if h.source { |
|
fs := runtime.CallersFrames([]uintptr{r.PC}) |
|
f, _ := fs.Next() |
|
record.AddAttributes( |
|
log.String(string(semconv.CodeFilePathKey), f.File), |
|
log.String(string(semconv.CodeFunctionNameKey), f.Function), |
|
log.Int(string(semconv.CodeLineNumberKey), f.Line), |
|
) |
|
} |
|
|
|
if h.attrs.Len() > 0 { |
|
record.AddAttributes(h.attrs.KeyValues()...) |
|
} |
|
|
|
n := r.NumAttrs() |
|
if h.group != nil { |
|
if n > 0 { |
|
buf := newKVBuffer(n) |
|
r.Attrs(buf.AddAttr) |
|
record.AddAttributes(h.group.KeyValue(buf.KeyValues()...)) |
|
} else { |
|
// A Handler should not output groups if there are no attributes. |
|
g := h.group.NextNonEmpty() |
|
if g != nil { |
|
record.AddAttributes(g.KeyValue()) |
|
} |
|
} |
|
} else if n > 0 { |
|
buf := newKVBuffer(n) |
|
r.Attrs(buf.AddAttr) |
|
record.AddAttributes(buf.KeyValues()...) |
|
} |
|
|
|
return record |
|
} |
So that error is set as a field on the record instead of attributes.
otelslogcurrently treats errors fields ordinary fieldsThat makes exception/error data inconsistent with the OpenTelemetry log semantic conventions and harder to recognize as exception/error information.
The proposal is to change
opentelemetry-go-contrib/bridges/otelslog/handler.go
Lines 198 to 241 in 2c2127d
So that error is set as a field on the record instead of attributes.