From 1aff19d6c693343787664599be2789817212b8c9 Mon Sep 17 00:00:00 2001 From: Sven Walter Date: Mon, 12 Aug 2024 13:32:39 +0200 Subject: [PATCH] PF-3547 slugify log keys --- go.mod | 2 ++ go.sum | 4 ++++ pkg/logutil/context.go | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 270c944..5cf29f4 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/goreleaser/nfpm/v2 v2.35.3 github.com/gorilla/securecookie v1.1.2 github.com/gorilla/sessions v1.2.2 + github.com/gosimple/slug v1.14.0 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/vault/api v1.12.0 github.com/mitchellh/mapstructure v1.5.0 @@ -106,6 +107,7 @@ require ( github.com/google/rpmpack v0.5.0 // indirect github.com/goreleaser/chglog v0.5.0 // indirect github.com/goreleaser/fileglob v1.3.0 // indirect + github.com/gosimple/unidecode v1.0.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect diff --git a/go.sum b/go.sum index a0c4a6b..376ce93 100644 --- a/go.sum +++ b/go.sum @@ -220,6 +220,10 @@ github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kX github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY= github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ= +github.com/gosimple/slug v1.14.0 h1:RtTL/71mJNDfpUbCOmnf/XFkzKRtD6wL6Uy+3akm4Es= +github.com/gosimple/slug v1.14.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ= +github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o= +github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/pkg/logutil/context.go b/pkg/logutil/context.go index dbd1524..4353629 100644 --- a/pkg/logutil/context.go +++ b/pkg/logutil/context.go @@ -7,6 +7,7 @@ import ( "path" "strings" + "github.com/gosimple/slug" "github.com/mitchellh/mapstructure" "github.com/sirupsen/logrus" ) @@ -77,7 +78,7 @@ func Start(ctx context.Context, subsystem string, opts ...ContextOption) context ids := []string{} for _, t := range m.path { - name := fmt.Sprintf("trace-id-%s", t.subsystem) + name := fmt.Sprintf("trace-id-%s", slug.Make(t.subsystem)) m.log = m.log.WithField(name, t.id) ids = append(ids, t.id) }