Skip to content

Commit 1f31f43

Browse files
authored
Merge pull request #356 from alecmerdler/lookup-resources-request-id
Allow passing request ID
2 parents 7fc5ccd + 0b6d91c commit 1f31f43

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/99designs/keyring v1.2.2
99
github.com/AlecAivazis/survey/v2 v2.3.7
1010
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2
11-
github.com/authzed/authzed-go v0.10.2-0.20240313203343-903be5541103
11+
github.com/authzed/authzed-go v0.11.2-0.20240320204618-9622b72a72c6
1212
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b
1313
github.com/authzed/spicedb v1.29.5
1414
github.com/brianvoe/gofakeit/v6 v6.28.0
@@ -150,8 +150,8 @@ require (
150150
github.com/muesli/termenv v0.15.2 // indirect
151151
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
152152
github.com/ngrok/sqlmw v0.0.0-20220520173518-97c9c04efc79 // indirect
153-
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
154-
github.com/onsi/gomega v1.28.1 // indirect
153+
github.com/onsi/ginkgo/v2 v2.15.0 // indirect
154+
github.com/onsi/gomega v1.31.1 // indirect
155155
github.com/outcaste-io/ristretto v0.2.3 // indirect
156156
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
157157
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
@@ -164,6 +164,7 @@ require (
164164
github.com/prometheus/procfs v0.12.0 // indirect
165165
github.com/prometheus/statsd_exporter v0.22.7 // indirect
166166
github.com/rivo/uniseg v0.4.7 // indirect
167+
github.com/rogpeppe/go-internal v1.12.0 // indirect
167168
github.com/rs/cors v1.10.1 // indirect
168169
github.com/sagikazarmark/locafero v0.4.0 // indirect
169170
github.com/sagikazarmark/slog-shim v0.1.0 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5
7979
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
8080
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 h1:goHVqTbFX3AIo0tzGr14pgfAW2ZfPChKO21Z9MGf/gk=
8181
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
82-
github.com/authzed/authzed-go v0.10.2-0.20240313203343-903be5541103 h1:7LvqvFL9z+zyo7wlkH7rBKDD6SgJ7jbP1nvAJWi1Oug=
83-
github.com/authzed/authzed-go v0.10.2-0.20240313203343-903be5541103/go.mod h1:2cnND+OBSxz1DpVfaQBKtdobTiaX2qAlj7k9eNr/pM4=
82+
github.com/authzed/authzed-go v0.11.2-0.20240320204618-9622b72a72c6 h1:zpdDybjx+3fyTf7UU2F6y/rkZuiylhUcNhkvewqn2Gs=
83+
github.com/authzed/authzed-go v0.11.2-0.20240320204618-9622b72a72c6/go.mod h1:w3Q8IbTR2raCDGIWCj2UHXxhQuhmpRPYNRutZjgUkXM=
8484
github.com/authzed/cel-go v0.17.5 h1:lfpkNrR99B5QRHg5qdG9oLu/kguVlZC68VJuMk8tH9Y=
8585
github.com/authzed/cel-go v0.17.5/go.mod h1:XL/zEq5hKGVF8aOdMbG7w+BQPihLjY2W8N+UIygDA2I=
8686
github.com/authzed/consistent v0.1.0 h1:tlh1wvKoRbjRhMm2P+X5WQQyR54SRoS4MyjLOg17Mp8=
@@ -476,10 +476,10 @@ github.com/ngrok/sqlmw v0.0.0-20220520173518-97c9c04efc79/go.mod h1:E26fwEtRNigB
476476
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
477477
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
478478
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
479-
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
480-
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
481-
github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA=
482-
github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
479+
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
480+
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
481+
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
482+
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
483483
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
484484
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
485485
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
@@ -548,8 +548,8 @@ github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
548548
github.com/rodaine/table v1.1.1 h1:zBliy3b4Oj6JRmncse2Z85WmoQvDrXOYuy0JXCt8Qz8=
549549
github.com/rodaine/table v1.1.1/go.mod h1:iqTRptjn+EVcrVBYtNMlJ2wrJZa3MpULUmcXFpfcziA=
550550
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
551-
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
552-
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
551+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
552+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
553553
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
554554
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
555555
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
@@ -892,8 +892,8 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc
892892
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
893893
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
894894
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
895-
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
896-
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
895+
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
896+
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
897897
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
898898
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
899899
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func Run() {
3131
PersistentPreRunE: cobrautil.CommandStack(
3232
zl.RunE(),
3333
SyncFlagsCmdFunc,
34+
commands.InjectRequestID,
3435
),
3536
SilenceErrors: true,
3637
SilenceUsage: true,
@@ -52,6 +53,7 @@ func Run() {
5253
rootCmd.PersistentFlags().Bool("skip-version-check", false, "if true, no version check is performed against the server")
5354
rootCmd.PersistentFlags().Bool("no-verify-ca", false, "do not attempt to verify the server's certificate chain and host name")
5455
rootCmd.PersistentFlags().Bool("debug", false, "enable debug logging")
56+
rootCmd.PersistentFlags().String("request-id", "", "optional id to send along with SpiceDB requests for tracing")
5557
_ = rootCmd.PersistentFlags().MarkHidden("debug") // This cannot return its error.
5658

5759
versionCmd := &cobra.Command{

internal/commands/util.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/TylerBrock/colorjson"
9+
"github.com/authzed/authzed-go/pkg/requestmeta"
910
"github.com/jzelinskie/cobrautil/v2"
1011
"github.com/jzelinskie/stringz"
1112
"github.com/spf13/cobra"
@@ -82,3 +83,15 @@ func PrettyProto(m proto.Message) ([]byte, error) {
8283

8384
return pretty, nil
8485
}
86+
87+
// InjectRequestID adds the value of the --request-id flag to the
88+
// context of the given command.
89+
func InjectRequestID(cmd *cobra.Command, _ []string) error {
90+
ctx := cmd.Context()
91+
requestID := cobrautil.MustGetString(cmd, "request-id")
92+
if ctx != nil && requestID != "" {
93+
cmd.SetContext(requestmeta.WithRequestID(ctx, requestID))
94+
}
95+
96+
return nil
97+
}

0 commit comments

Comments
 (0)