diff --git a/logging/logrus/hook.go b/logging/logrus/hook.go index f34c36d..22d882f 100644 --- a/logging/logrus/hook.go +++ b/logging/logrus/hook.go @@ -18,7 +18,6 @@ import ( "errors" "github.com/sirupsen/logrus" - "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" ) @@ -28,12 +27,6 @@ const ( traceIDKey = "trace_id" spanIDKey = "span_id" traceFlagsKey = "trace_flags" - logEventKey = "log" -) - -var ( - logSeverityTextKey = attribute.Key("otel.log.severity.text") - logMessageKey = attribute.Key("otel.log.message") ) var _ logrus.Hook = (*TraceHook)(nil) @@ -78,16 +71,9 @@ func (h *TraceHook) Fire(entry *logrus.Entry) error { return nil } - // attach log to span event attributes - attrs := []attribute.KeyValue{ - logMessageKey.String(entry.Message), - logSeverityTextKey.String(OtelSeverityText(entry.Level)), - } - span.AddEvent(logEventKey, trace.WithAttributes(attrs...)) - // set span status if entry.Level <= h.cfg.errorSpanLevel { - span.SetStatus(codes.Error, entry.Message) + span.SetStatus(codes.Error, "") span.RecordError(errors.New(entry.Message), trace.WithStackTrace(h.cfg.recordStackTraceInSpan)) } diff --git a/logging/zap/logger.go b/logging/zap/logger.go index bd02006..bdafeda 100644 --- a/logging/zap/logger.go +++ b/logging/zap/logger.go @@ -20,7 +20,6 @@ import ( "github.com/cloudwego/hertz/pkg/common/hlog" hertzzap "github.com/hertz-contrib/logger/zap" - "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" @@ -37,14 +36,9 @@ const ( traceIDKey = "trace_id" spanIDKey = "span_id" traceFlagsKey = "trace_flags" - logEventKey = "log" ) -var ( - logSeverityTextKey = attribute.Key("otel.log.severity.text") - logMessageKey = attribute.Key("otel.log.message") - extraKeys = []hertzzap.ExtraKey{traceIDKey, spanIDKey, traceFlagsKey} -) +var extraKeys = []hertzzap.ExtraKey{traceIDKey, spanIDKey, traceFlagsKey} func NewLogger(opts ...Option) *Logger { config := defaultConfig() @@ -96,17 +90,10 @@ func (l *Logger) CtxLogf(level hlog.Level, ctx context.Context, format string, k return } - msg := getMessage(format, kvs) - - attrs := []attribute.KeyValue{ - logMessageKey.String(msg), - logSeverityTextKey.String(OtelSeverityText(zlevel)), - } - span.AddEvent(logEventKey, trace.WithAttributes(attrs...)) - // set span status if zlevel >= l.config.traceConfig.errorSpanLevel { - span.SetStatus(codes.Error, msg) + msg := getMessage(format, kvs) + span.SetStatus(codes.Error, "") span.RecordError(errors.New(msg), trace.WithStackTrace(l.config.traceConfig.recordStackTraceInSpan)) } }