From 1d0a63ca993ba98c9cdb2b9edbedb9674f3e1685 Mon Sep 17 00:00:00 2001 From: Reed Allman Date: Thu, 7 Sep 2017 18:18:32 -0700 Subject: [PATCH] add id to all call invocation logs --- api/agent/agent.go | 4 ++-- api/agent/call.go | 5 +++++ api/server/runner.go | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/agent/agent.go b/api/agent/agent.go index ecd7227e8..a525219f6 100644 --- a/api/agent/agent.go +++ b/api/agent/agent.go @@ -180,6 +180,7 @@ func (a *agent) Submit(callI Call) error { call := callI.(*call) ctx := call.req.Context() + span, ctx := opentracing.StartSpanFromContext(ctx, "agent_submit") defer span.Finish() @@ -485,8 +486,7 @@ func (s *hotSlot) exec(ctx context.Context, call *call) error { } // link the container id and id in the logs [for us!] - // TODO go is broke idk why logrus.Fields doesn't work - common.Logger(ctx).WithField("container_id", s.container.id).WithField("id", call.ID).Info("starting call") + common.Logger(ctx).WithField("container_id", s.container.id).Info("starting call") // swap in the new id and the new stderr logger s.container.swap(stderr) diff --git a/api/agent/call.go b/api/agent/call.go index 1d4179b31..e0ede3e03 100644 --- a/api/agent/call.go +++ b/api/agent/call.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/fnproject/fn/api/common" "github.com/fnproject/fn/api/id" "github.com/fnproject/fn/api/models" "github.com/go-openapi/strfmt" @@ -250,6 +251,10 @@ func (a *agent) GetCall(opts ...CallOpt) (Call, error) { c.ds = a.ds c.mq = a.mq + ctx, _ := common.LoggerWithFields(c.req.Context(), + logrus.Fields{"id": c.ID, "app": c.AppName, "route": c.Path}) + c.req = c.req.WithContext(ctx) + return &c, nil } diff --git a/api/server/runner.go b/api/server/runner.go index 11223b45c..142a95eec 100644 --- a/api/server/runner.go +++ b/api/server/runner.go @@ -10,8 +10,10 @@ import ( "github.com/fnproject/fn/api" "github.com/fnproject/fn/api/agent" + "github.com/fnproject/fn/api/common" "github.com/fnproject/fn/api/models" "github.com/gin-gonic/gin" + "github.com/sirupsen/logrus" ) type runnerResponse struct { @@ -60,6 +62,10 @@ func (s *Server) serve(c *gin.Context, appName, path string) { // TODO we could add FireBeforeDispatch right here with Call in hand model := call.Model() + { // scope this, to disallow ctx use outside of this scope. add id for handleErrorResponse logger + ctx, _ := common.LoggerWithFields(c.Request.Context(), logrus.Fields{"id": model.ID}) + c.Request = c.Request.WithContext(ctx) + } if model.Type == "async" { // TODO we should push this into GetCall somehow (CallOpt maybe) or maybe agent.Queue(Call) ?