diff --git a/api/api.go b/api/api.go index 79dd9eae37f2a584f2f9f4cadaa4574adefa7fc2..5fcf8ca2a6d8c390533fe8dcd143726efa6d9c30 100644 --- a/api/api.go +++ b/api/api.go @@ -18,6 +18,10 @@ import ( "gitlab.com/uafrica/go-utils/service" ) +//LEGACY: global variable is set only for backward compatibility +//When handlers are changed to accept context, they should get this from the context +var CurrentRequestID *string + //New creates the API with the specified routes keys on [path][method] //value could be any of the handler function signatures supported by the api.Router //requestIDHeaderKey is defined in the response header to match the requestID from the request diff --git a/api/lambda.go b/api/lambda.go index ec476a322cb87ead528a7df272f9c55ae4fd01d8..5f4836ebf9e6f1376a2a52256cdfdf11fda8fed9 100644 --- a/api/lambda.go +++ b/api/lambda.go @@ -113,6 +113,10 @@ func (api Api) Handler(baseCtx context.Context, apiGatewayProxyReq events.APIGat rand.Seed(time.Now().Unix()) + //LEGACY: delete this as soon as all handlers accepts context + //this does not support concurrent execution! + CurrentRequestID = &ctx.Request.RequestContext.RequestID + ctx.Debugf("HTTP %s %s ...\n", apiGatewayProxyReq.HTTPMethod, apiGatewayProxyReq.Resource) ctx.WithFields(map[string]interface{}{ "http_method": ctx.Request.HTTPMethod,