We can create logrus with context like this
log := logrus.WithContext(ctx)
Added logrus hooks to fire and attach trace_id to the log.
func (hook *ContextHook) Fire(entry *log.Entry) error {
if entry.Context != nil {
entry.Data[trace_id] = entry.Context.Value(trace_id)
}
return nil
}
and now log.Info(“testing…”) logs with trace_id like this.
{"level":"info","msg":"testing...","time":"2023-04-05T17:08:43+05:30","trace_id":"bce6b1d6-06e1-4636-9267-4e640c01ea0c"}
How achieve the same using temporal workflow context ?
I’ve added context propagator to pass values from context.Context to workflow.Context during wokflow execution.