feat: add server name field

This commit is contained in:
franklin 2021-09-06 22:09:29 +02:00
parent 45e7d058e4
commit f50d266e1f
2 changed files with 12 additions and 1 deletions

View File

@ -5,6 +5,9 @@ import (
)
const (
// HTTPServerNameKey represents the name of the service handling the request
HTTPServerNameKey = "http_server_name"
// HTTPMethodKey represents the HTTP request method.
HTTPMethodKey = "http_method"
@ -44,6 +47,10 @@ const (
HTTPSessionIDKey = "http_session_id"
)
func FHTTPServerName(id string) zap.Field {
return zap.String(HTTPServerNameKey, id)
}
func FHTTPRequestID(id string) zap.Field {
return zap.String(HTTPRequestIDKey, id)
}

View File

@ -17,11 +17,15 @@ func WithError(l *zap.Logger, err error) *zap.Logger {
return l.With(FError(err))
}
func WithHTTPServerName(l *zap.Logger, name string) *zap.Logger {
return l.With(FHTTPServerName(name))
}
func WithServiceName(l *zap.Logger, name string) *zap.Logger {
return l.With(FServiceName(name))
}
func WithTraceID(l *zap.Logger, ctx context.Context) *zap.Logger { //nolint:revive
func WithTraceID(l *zap.Logger, ctx context.Context) *zap.Logger {
if spanCtx := trace.SpanContextFromContext(ctx); spanCtx.IsValid() {
l = l.With(FTraceID(spanCtx.TraceID().String()))
}