From 8c84ab9b31c9c09c783966a9862db37f645de8ce Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Thu, 18 May 2023 13:35:49 +0200 Subject: [PATCH] write app version to rpc log --- metric/log.go | 6 +++++- metric/metric.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/metric/log.go b/metric/log.go index 7cc34e66..edb63249 100644 --- a/metric/log.go +++ b/metric/log.go @@ -35,6 +35,10 @@ func Identity(val string) zap.Field { return zap.String("identity", val) } +func App(app string) zap.Field { + return zap.String("app", app) +} + func FileId(fileId string) zap.Field { return zap.String("fileId", fileId) } @@ -57,5 +61,5 @@ func (m *metric) RequestLog(ctx context.Context, rpc string, fields ...zap.Field if ak != nil { acc = ak.Account() } - m.rpcLog.Info("", append(fields, PeerId(peerId), Identity(acc), Method(rpc))...) + m.rpcLog.Info("", append(fields, m.appField, PeerId(peerId), Identity(acc), Method(rpc))...) } diff --git a/metric/metric.go b/metric/metric.go index fedff6bd..aeac0550 100644 --- a/metric/metric.go +++ b/metric/metric.go @@ -33,6 +33,7 @@ type metric struct { rpcLog logger.CtxLogger config Config a *app.App + appField zap.Field } func (m *metric) Init(a *app.App) (err error) { @@ -40,6 +41,7 @@ func (m *metric) Init(a *app.App) (err error) { m.registry = prometheus.NewRegistry() m.config = a.MustComponent("config").(configSource).GetMetric() m.rpcLog = logger.NewNamed("rpcLog") + m.appField = App(a.Version()) return nil }