-
Notifications
You must be signed in to change notification settings - Fork 682
Description
Problem Statement
Logs are distinct from metrics and traces in that there is no user-facing OpenTelemetry logs API. Instead, there is tooling to bridge logs from existing popular log packages (such as slog, logrus, zap, logr) into the OpenTelemetry ecosystem.
https://opentelemetry.io/docs/languages/go/instrumentation/#logs
Given the above, there is some friction when working with otelslog
(and other log bridges) and attribute.KeyValue
s.
There is often a need to log OpenTelemetry attributes using slog.Attr
. When using otelslog, it is reasonable to assume that the user would also want to use the semconv package. But the identifiers in that package are all attribute.KeyValue
or attribute.Key
. It is also common for users to find themselves with a []attribute.KeyValue
to use with metrics and traces. But such a slice cannot be easily used directly with slog
without converting to []slog.Attr
first. Having to deal with two sets of attributes (slog.Attr
and attribute.KeyValue
) is tedious.
Proposed Solution
Expose functionality in the otelslog
package that allows for conversion from attribute.KeyValue
to slog.Attr
.
I'm looking for something like the following:
func AttrsFromKeyValues(kvs ...attribute.KeyValue) []slog.Attr
and possibly also a function that converts a single attribute:
func AttrFromKeyValue(kv attribute.KeyValue) slog.Attr
Alternatives
Have users implement this conversion themselves. Though I imagine that such conversion is a common use case, and should arguably be supported in otelslog
.
Prior Art
N/A
Additional Context
While this is applicable to other log bridges, the focus of this proposal is on slog
as it is part of the standard library.