Skip to content

Commit

Permalink
Make log keys configurable. (#176)
Browse files Browse the repository at this point in the history
Update example to take advantage of new log endpoint middleware.
  • Loading branch information
raphael authored Dec 30, 2022
1 parent cc422e8 commit a93902c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions example/weather/services/forecaster/cmd/forecaster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func main() {
// 5. Create service & endpoints
svc := forecaster.New(wc)
endpoints := genforecaster.NewEndpoints(svc)
endpoints.Use(log.Endpoint)

// 6. Create transport
server := gengrpc.New(endpoints, nil)
Expand Down
1 change: 1 addition & 0 deletions example/weather/services/front/cmd/front/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func main() {
// 4. Create service & endpoints
svc := front.New(fc, lc)
endpoints := genfront.NewEndpoints(svc)
endpoints.Use(log.Endpoint)

// 5. Create transport
mux := goahttp.NewMuxer()
Expand Down
1 change: 1 addition & 0 deletions example/weather/services/locator/cmd/locator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func main() {
// 5. Create service & endpoints
svc := locator.New(ipc)
endpoints := genlocator.NewEndpoints(svc)
endpoints.Use(log.Endpoint)

// 6. Create transport
server := gengrpc.New(endpoints, nil)
Expand Down
4 changes: 2 additions & 2 deletions log/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func HTTP(logCtx context.Context, opts ...HTTPLogOption) func(http.Handler) http
func Endpoint(e goa.Endpoint) goa.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
if s := ctx.Value(goa.ServiceKey); s != nil {
ctx = With(ctx, KV{K: "goa.service", V: s})
ctx = With(ctx, KV{K: GoaServiceKey, V: s})
}
if m := ctx.Value(goa.MethodKey); m != nil {
ctx = With(ctx, KV{K: "goa.method", V: m})
ctx = With(ctx, KV{K: GoaMethodKey, V: m})
}
return e(ctx, req)
}
Expand Down
2 changes: 2 additions & 0 deletions log/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ var (
GRPCCodeKey = "grpc.code"
GRPCStatusKey = "grpc.status"
GRPCDurationKey = "grpc.time_ms"
GoaServiceKey = "goa.service"
GoaMethodKey = "goa.method"
)

0 comments on commit a93902c

Please sign in to comment.