From 98ba4307b007252b2349aebfc5cd3f47e146c5a1 Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Thu, 12 Dec 2024 12:40:37 -0800 Subject: [PATCH] Use logger for request context, incl. request id --- cmd/tlserver/main.go | 4 +++- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cmd/tlserver/main.go b/cmd/tlserver/main.go index 6e1bc5d5..4cc113ff 100644 --- a/cmd/tlserver/main.go +++ b/cmd/tlserver/main.go @@ -200,7 +200,9 @@ func (cmd *ServerCommand) Run() error { root.Use(usercheck.AdminDefaultMiddleware("admin")) // Add logging middleware - must be after auth - root.Use(log.LoggingMiddleware(cmd.LongQueryDuration, func(ctx context.Context) string { + root.Use(log.RequestIDMiddleware) + root.Use(log.RequestIDLoggingMiddleware) + root.Use(log.DurationLoggingMiddleware(cmd.LongQueryDuration, func(ctx context.Context) string { if user := authn.ForContext(ctx); user != nil { return user.Name() } diff --git a/go.mod b/go.mod index c033c1a7..9a430f63 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,11 @@ require ( github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 github.com/graph-gophers/dataloader/v7 v7.1.0 github.com/hypirion/go-filecache v0.0.0-20160810125507-e3e6ef6981f0 - github.com/interline-io/log v0.0.0-20240613202707-4e3adcc06d2d - github.com/interline-io/transitland-dbutil v0.0.0-20241211003846-754ca2a37d9d - github.com/interline-io/transitland-jobs v0.0.0-20241211004034-cf0f5587b01d - github.com/interline-io/transitland-lib v1.0.0-rc3.0.20241212015927-9ee6e945325d - github.com/interline-io/transitland-mw v0.0.0-20241211003943-b546af52d409 + github.com/interline-io/log v0.0.0-20241212203449-4bcff214cd71 + github.com/interline-io/transitland-dbutil v0.0.0-20241212203507-15a69a52c1c4 + github.com/interline-io/transitland-jobs v0.0.0-20241212203627-25dc585dcf7e + github.com/interline-io/transitland-lib v1.0.0-rc3.0.20241212203529-97599f3e6ac2 + github.com/interline-io/transitland-mw v0.0.0-20241212203557-2e0c0fea3d26 github.com/jmoiron/sqlx v1.4.0 github.com/rs/zerolog v1.33.0 github.com/spf13/cobra v1.8.1 diff --git a/go.sum b/go.sum index 824f5fa0..793f0f63 100644 --- a/go.sum +++ b/go.sum @@ -150,16 +150,16 @@ github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6 github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/interline-io/log v0.0.0-20240613202707-4e3adcc06d2d h1:XToGkREjPhy6Ha6yUfKP7P4O2vRKc4xNGUFeo8nshjA= -github.com/interline-io/log v0.0.0-20240613202707-4e3adcc06d2d/go.mod h1:chJaM8SKcHI6ivoeFuZ8M8axTjSV4TPmuQ+sAyAHa34= -github.com/interline-io/transitland-dbutil v0.0.0-20241211003846-754ca2a37d9d h1:W9IWIKh6R+m5ueRol8J0mnw3WtuUnxU0J+2qlu+Dd0k= -github.com/interline-io/transitland-dbutil v0.0.0-20241211003846-754ca2a37d9d/go.mod h1:gcuaCPdtpzopTWKJyRWMDTDFQ59bvX0OUWSccoLCcoQ= -github.com/interline-io/transitland-jobs v0.0.0-20241211004034-cf0f5587b01d h1:OovUOl7eM8qrukLwkx+WTSaFz2FaExIGYDlmSZ6iWeo= -github.com/interline-io/transitland-jobs v0.0.0-20241211004034-cf0f5587b01d/go.mod h1:lR+WSE0BqU2notk69Ei0WR+WHUpUHWraIhcQgIh10+A= -github.com/interline-io/transitland-lib v1.0.0-rc3.0.20241212015927-9ee6e945325d h1:5WA97lN4pEj/umJZZUUv4XeMvnt8rpOz54CWas11S0c= -github.com/interline-io/transitland-lib v1.0.0-rc3.0.20241212015927-9ee6e945325d/go.mod h1:x8NJexNljTnw12YWtUUiVmQIrMQFurs8lIkR6VzHUeI= -github.com/interline-io/transitland-mw v0.0.0-20241211003943-b546af52d409 h1:pQV47Wwmw6zQZvzGKlIVgqkgmKe99js0h03kLonN+g8= -github.com/interline-io/transitland-mw v0.0.0-20241211003943-b546af52d409/go.mod h1:yS3MZZfO3w6cR28KMMcrHBcLGM2sWem5IQicdKbw4zw= +github.com/interline-io/log v0.0.0-20241212203449-4bcff214cd71 h1:RI4mfj5B0VPK3XznLKTRPzFScySmRDYYp6tACSqZfoE= +github.com/interline-io/log v0.0.0-20241212203449-4bcff214cd71/go.mod h1:chJaM8SKcHI6ivoeFuZ8M8axTjSV4TPmuQ+sAyAHa34= +github.com/interline-io/transitland-dbutil v0.0.0-20241212203507-15a69a52c1c4 h1:25yHjhbhKqJI5Gt/16WVQ2m9HtsymVm46UdAm50i/wg= +github.com/interline-io/transitland-dbutil v0.0.0-20241212203507-15a69a52c1c4/go.mod h1:aPEEJCvUPJoxyzA6sP4/PF4thA+hpafYpUcFBgoKK50= +github.com/interline-io/transitland-jobs v0.0.0-20241212203627-25dc585dcf7e h1:1yYXM017Sm6qAPqwKT+SQ+WBbpGpVSGqyNbtcPHS+EU= +github.com/interline-io/transitland-jobs v0.0.0-20241212203627-25dc585dcf7e/go.mod h1:+lu9T9vafIPrucNWn21+UIrmd3MYeAbV3bEWkpT5Oxo= +github.com/interline-io/transitland-lib v1.0.0-rc3.0.20241212203529-97599f3e6ac2 h1:c/1LraxxyIWE+gY53hhZY8zn87MgxMoX2RKjCp+CJq8= +github.com/interline-io/transitland-lib v1.0.0-rc3.0.20241212203529-97599f3e6ac2/go.mod h1:RBqVLgH11BpAv4KU+hllViwAjtcRUEAJ3tTWxXaNuJU= +github.com/interline-io/transitland-mw v0.0.0-20241212203557-2e0c0fea3d26 h1:YNFsJU00rvfQyoTbKmgIAZJscdEZYn75rTR2d4aHfFs= +github.com/interline-io/transitland-mw v0.0.0-20241212203557-2e0c0fea3d26/go.mod h1:zPjgFce6JY8gHrm35Jdp59PKSQrpNfUSHN8B5I8cXSU= github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso= github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA= github.com/irees/kin-openapi v0.0.0-20240827112008-5f0d6c653b17 h1:8r3a8+gGbNCrB+sF5BhzOUU5N7vo7vbwz1MGmYoq5TI=