Skip to content

Commit

Permalink
Use context logger for http endpoint logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Greenleaf authored and jacobgreenleaf committed Sep 6, 2018
1 parent eed7630 commit ad19f7b
Show file tree
Hide file tree
Showing 47 changed files with 220 additions and 190 deletions.
10 changes: 5 additions & 5 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions codegen/templates/endpoint.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (h *{{$handlerName}}) HandleRequest(
{{end}}

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -143,7 +143,7 @@ func (h *{{$handlerName}}) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := {{$workflowPkg}}.New{{$workflowInterface}}(h.Dependencies)
Expand All @@ -161,7 +161,7 @@ func (h *{{$handlerName}}) HandleRequest(
response, cliRespHeaders, err := w.Handle(ctx, req.Header, &requestBody)

// log downstream response to endpoint
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -178,7 +178,7 @@ func (h *{{$handlerName}}) HandleRequest(
if traceKey, ok := req.Header.Get("{{$traceKey}}"); ok {
zfields = append(zfields, zap.String("{{$traceKey}}", traceKey))
}
req.Logger.Debug("downstream service response", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "downstream service response", zfields...)
}

{{end -}}
Expand Down
4 changes: 2 additions & 2 deletions codegen/test_data/endpoints/bar_bar_method_argnotstruct.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (h *BarArgNotStructHandler) HandleRequest(
}

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -87,7 +87,7 @@ func (h *BarArgNotStructHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarArgNotStructWorkflow(h.Dependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (h *BarArgWithHeadersHandler) HandleRequest(
}

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -97,7 +97,7 @@ func (h *BarArgWithHeadersHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarArgWithHeadersWorkflow(h.Dependencies)
Expand All @@ -108,7 +108,7 @@ func (h *BarArgWithHeadersHandler) HandleRequest(
response, cliRespHeaders, err := w.Handle(ctx, req.Header, &requestBody)

// log downstream response to endpoint
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -123,7 +123,7 @@ func (h *BarArgWithHeadersHandler) HandleRequest(
if traceKey, ok := req.Header.Get("trace-key"); ok {
zfields = append(zfields, zap.String("trace-key", traceKey))
}
req.Logger.Debug("downstream service response", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "downstream service response", zfields...)
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (h *BarArgWithManyQueryParamsHandler) HandleRequest(
}

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -330,7 +330,7 @@ func (h *BarArgWithManyQueryParamsHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarArgWithManyQueryParamsWorkflow(h.Dependencies)
Expand All @@ -341,7 +341,7 @@ func (h *BarArgWithManyQueryParamsHandler) HandleRequest(
response, cliRespHeaders, err := w.Handle(ctx, req.Header, &requestBody)

// log downstream response to endpoint
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -356,7 +356,7 @@ func (h *BarArgWithManyQueryParamsHandler) HandleRequest(
if traceKey, ok := req.Header.Get("trace-key"); ok {
zfields = append(zfields, zap.String("trace-key", traceKey))
}
req.Logger.Debug("downstream service response", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "downstream service response", zfields...)
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (h *BarArgWithNestedQueryParamsHandler) HandleRequest(
}

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -173,7 +173,7 @@ func (h *BarArgWithNestedQueryParamsHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarArgWithNestedQueryParamsWorkflow(h.Dependencies)
Expand All @@ -184,7 +184,7 @@ func (h *BarArgWithNestedQueryParamsHandler) HandleRequest(
response, cliRespHeaders, err := w.Handle(ctx, req.Header, &requestBody)

// log downstream response to endpoint
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -199,7 +199,7 @@ func (h *BarArgWithNestedQueryParamsHandler) HandleRequest(
if traceKey, ok := req.Header.Get("trace-key"); ok {
zfields = append(zfields, zap.String("trace-key", traceKey))
}
req.Logger.Debug("downstream service response", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "downstream service response", zfields...)
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (h *BarArgWithParamsHandler) HandleRequest(
requestBody.Params.UserUUID = req.Params.ByName("user-uuid")

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -94,7 +94,7 @@ func (h *BarArgWithParamsHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarArgWithParamsWorkflow(h.Dependencies)
Expand All @@ -105,7 +105,7 @@ func (h *BarArgWithParamsHandler) HandleRequest(
response, cliRespHeaders, err := w.Handle(ctx, req.Header, &requestBody)

// log downstream response to endpoint
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -120,7 +120,7 @@ func (h *BarArgWithParamsHandler) HandleRequest(
if traceKey, ok := req.Header.Get("trace-key"); ok {
zfields = append(zfields, zap.String("trace-key", traceKey))
}
req.Logger.Debug("downstream service response", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "downstream service response", zfields...)
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (h *BarArgWithQueryHeaderHandler) HandleRequest(
}

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -91,7 +91,7 @@ func (h *BarArgWithQueryHeaderHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarArgWithQueryHeaderWorkflow(h.Dependencies)
Expand All @@ -102,7 +102,7 @@ func (h *BarArgWithQueryHeaderHandler) HandleRequest(
response, cliRespHeaders, err := w.Handle(ctx, req.Header, &requestBody)

// log downstream response to endpoint
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -117,7 +117,7 @@ func (h *BarArgWithQueryHeaderHandler) HandleRequest(
if traceKey, ok := req.Header.Get("trace-key"); ok {
zfields = append(zfields, zap.String("trace-key", traceKey))
}
req.Logger.Debug("downstream service response", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "downstream service response", zfields...)
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (h *BarArgWithQueryParamsHandler) HandleRequest(
requestBody.Bar = barQuery

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -124,7 +124,7 @@ func (h *BarArgWithQueryParamsHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarArgWithQueryParamsWorkflow(h.Dependencies)
Expand All @@ -135,7 +135,7 @@ func (h *BarArgWithQueryParamsHandler) HandleRequest(
response, cliRespHeaders, err := w.Handle(ctx, req.Header, &requestBody)

// log downstream response to endpoint
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -150,7 +150,7 @@ func (h *BarArgWithQueryParamsHandler) HandleRequest(
if traceKey, ok := req.Header.Get("trace-key"); ok {
zfields = append(zfields, zap.String("trace-key", traceKey))
}
req.Logger.Debug("downstream service response", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "downstream service response", zfields...)
}

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions codegen/test_data/endpoints/bar_bar_method_helloworld.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (h *BarHelloWorldHandler) HandleRequest(
) {

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -83,7 +83,7 @@ func (h *BarHelloWorldHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarHelloWorldWorkflow(h.Dependencies)
Expand Down
4 changes: 2 additions & 2 deletions codegen/test_data/endpoints/bar_bar_method_missingarg.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (h *BarMissingArgHandler) HandleRequest(
) {

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -81,7 +81,7 @@ func (h *BarMissingArgHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarMissingArgWorkflow(h.Dependencies)
Expand Down
4 changes: 2 additions & 2 deletions codegen/test_data/endpoints/bar_bar_method_norequest.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (h *BarNoRequestHandler) HandleRequest(
) {

// log endpoint request to downstream services
if ce := req.Logger.Check(zapcore.DebugLevel, "stub"); ce != nil {
if ce := h.Dependencies.Default.ContextLogger.Check(zapcore.DebugLevel, "stub"); ce != nil {
zfields := []zapcore.Field{
zap.String("endpoint", h.endpoint.EndpointName),
}
Expand All @@ -81,7 +81,7 @@ func (h *BarNoRequestHandler) HandleRequest(
zfields = append(zfields, zap.String(k, val))
}
}
req.Logger.Debug("endpoint request to downstream", zfields...)
h.Dependencies.Default.ContextLogger.Debug(ctx, "endpoint request to downstream", zfields...)
}

w := workflow.NewBarNoRequestWorkflow(h.Dependencies)
Expand Down
Loading

0 comments on commit ad19f7b

Please sign in to comment.