@@ -10,11 +10,13 @@ import (
1010 "errors"
1111 "fmt"
1212 "github.com/grafana/go-cache-plugin/lib/otel"
13+ "github.com/grafana/go-cache-plugin/lib/toolexec"
1314 "io"
1415 "log"
1516 "net"
1617 "net/http"
1718 "os"
19+ "os/exec"
1820 "os/signal"
1921 "strconv"
2022 "strings"
@@ -78,7 +80,12 @@ var serveFlags struct {
7880 SumDB string `flag:"sumdb,default=$GOCACHE_SUMDB,SumDB servers to proxy for (comma-separated)"`
7981}
8082
81- var logger * log.Logger
83+ var toolexecFlags struct {
84+ LogFile string `flag:"log-file,default=trace.log,File used for logs"`
85+ TracingEnabled bool `flag:"tracing,default=false,Enable tracing (optional)"`
86+ TracingContext string `flag:"context,default=runId:runAttempt:jobName:stepName:stepNumber,Tracing params"`
87+ OtelCollectorAddress string `flag:"otel-collector,default,OTEL collector address (optional)"`
88+ }
8289
8390func noopClose (context.Context ) error { return nil }
8491
@@ -189,7 +196,9 @@ func runConnect(env *command.Env, plugin string) error {
189196
190197 ctx := env .Context ()
191198 shutdownTracer , reportSpan , err := initTracing (ctx )
192-
199+ if err != nil {
200+ return err
201+ }
193202 addr := plugin
194203 // If the caller has not specified a host/port, then likely this is an older usage which only specifies port
195204 if ! strings .Contains (plugin , ":" ) {
@@ -224,6 +233,27 @@ func runConnect(env *command.Env, plugin string) error {
224233 return nil
225234}
226235
236+ func runToolexec (env * command.Env ) error {
237+ ctx := env .Context ()
238+ shutdownTracer , tracingContext , err := initModTracing (ctx )
239+ if err != nil {
240+ return err
241+ }
242+ defer shutdownTracer (ctx )
243+
244+ tool := os .Args [1 ]
245+ args := os .Args [2 :]
246+
247+ pkg := toolexec .GetPackage (os .Args )
248+
249+ _ , span := tracingContext .SpanWithContext (ctx , fmt .Sprintf ("%s: %s" , toolexec .GetTool (tool ), pkg ))
250+ defer span .End ()
251+ cmd := exec .Command (tool , args ... )
252+ cmd .Stdout = os .Stdout
253+ cmd .Stderr = os .Stderr
254+ return cmd .Run ()
255+ }
256+
227257func initTracing (ctx context.Context ) (func (context.Context ) error , func ([]byte ), error ) {
228258 if ! flags .TracingEnabled {
229259 return func (context.Context ) error { return nil }, func ([]byte ) {}, nil
0 commit comments