Skip to content

Commit 1d75e3e

Browse files
committed
feat(influx): provide means to provide trace debug ids to httpc client
1 parent 11364f9 commit 1d75e3e

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

cmd/influx/main.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ func newHTTPClient() (*httpc.Client, error) {
5757
version, runtime.GOOS, commit, date,
5858
)
5959

60-
c, err := http.NewHTTPClient(
61-
flags.Host,
62-
flags.Token,
63-
flags.skipVerify,
60+
opts := []httpc.ClientOptFn{
6461
httpc.WithUserAgentHeader(userAgent),
65-
)
62+
}
63+
// This is useful for forcing tracing on a given endpoint.
64+
if flags.traceDebugID != "" {
65+
opts = append(opts, httpc.WithHeader("jaeger-debug-id", flags.traceDebugID))
66+
}
67+
68+
c, err := http.NewHTTPClient(flags.Host, flags.Token, flags.skipVerify, opts...)
6669
if err != nil {
6770
return nil, err
6871
}
@@ -146,8 +149,9 @@ func runEMiddlware(mw cobraRunEMiddleware) genericCLIOptFn {
146149

147150
type globalFlags struct {
148151
config.Config
149-
local bool
150-
skipVerify bool
152+
local bool
153+
skipVerify bool
154+
traceDebugID string
151155
}
152156

153157
var flags globalFlags
@@ -203,6 +207,12 @@ func (b *cmdInfluxBuilder) cmd(childCmdFns ...func(f *globalFlags, opt genericCL
203207
Desc: "HTTP address of Influx",
204208
Persistent: true,
205209
},
210+
{
211+
DestP: &flags.traceDebugID,
212+
Flag: "trace-debug-id",
213+
Hidden: true,
214+
Persistent: true,
215+
},
206216
}
207217
fOpts.mustRegister(cmd)
208218

kit/cli/viper.go

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Opt struct {
1616

1717
EnvVar string
1818
Flag string
19+
Hidden bool
1920
Persistent bool
2021
Required bool
2122
Short rune // using rune b/c it guarantees correctness. a short must always be a string of length 1
@@ -178,6 +179,12 @@ func BindOptions(cmd *cobra.Command, opts []Opt) {
178179
// anyway, go ahead and make a PR and add another type.
179180
panic(fmt.Errorf("unknown destination type %t", o.DestP))
180181
}
182+
183+
// so weirdness with the flagset her, the flag must be set before marking it
184+
// hidden. This is in contrast to the MarkRequired, which can be set before...
185+
if o.Hidden {
186+
flagset.MarkHidden(o.Flag)
187+
}
181188
}
182189
}
183190

0 commit comments

Comments
 (0)