cloudapi: propagate operation/external id

Signed-off-by: Lukas Zapletal <lzap+git@redhat.com>
This commit is contained in:
Lukas Zapletal 2024-04-04 09:01:52 +02:00 committed by Achilleas Koutsou
parent f3c0daebbf
commit 5ce8f65a58
8 changed files with 169 additions and 41 deletions

View file

@ -0,0 +1,33 @@
package common
import (
"github.com/sirupsen/logrus"
)
type ContextHook struct{}
func (h *ContextHook) Levels() []logrus.Level {
return []logrus.Level{
logrus.DebugLevel,
logrus.InfoLevel,
logrus.WarnLevel,
logrus.ErrorLevel,
logrus.FatalLevel,
logrus.PanicLevel,
}
}
func (h *ContextHook) Fire(e *logrus.Entry) error {
if e.Context == nil {
return nil
}
if val := e.Context.Value(operationIDKeyCtx); val != nil {
e.Data["operation_id"] = val
}
if val := e.Context.Value(externalIDKeyCtx); val != nil {
e.Data["external_id"] = val
}
return nil
}