@@ -34,6 +34,7 @@ type traceOptions struct {
3434 ref string
3535 containerName string
3636 addr string
37+ compare string
3738}
3839
3940func loadTrace (ctx context.Context , ref string , nodes []builder.Node ) (string , []byte , error ) {
@@ -175,39 +176,48 @@ func runTrace(ctx context.Context, dockerCli command.Cli, opts traceOptions) err
175176 }
176177 }
177178
178- traceid , data , err := loadTrace (ctx , opts .ref , nodes )
179+ traceID , data , err := loadTrace (ctx , opts .ref , nodes )
179180 if err != nil {
180181 return err
181182 }
183+ srv := jaegerui .NewServer (jaegerui.Config {})
184+ if err := srv .AddTrace (traceID , bytes .NewReader (data )); err != nil {
185+ return err
186+ }
187+ url := "/trace/" + traceID
188+
189+ if opts .compare != "" {
190+ traceIDcomp , data , err := loadTrace (ctx , opts .compare , nodes )
191+ if err != nil {
192+ return errors .Wrapf (err , "failed to load trace for %s" , opts .compare )
193+ }
194+ if err := srv .AddTrace (traceIDcomp , bytes .NewReader (data )); err != nil {
195+ return err
196+ }
197+ url = "/trace/" + traceIDcomp + "..." + traceID
198+ }
182199
183200 var term bool
184201 if _ , err := console .ConsoleFromFile (os .Stdout ); err == nil {
185202 term = true
186203 }
187204
188- if ! term {
205+ if ! term && opts . compare == "" {
189206 fmt .Fprintln (dockerCli .Out (), string (data ))
190207 return nil
191208 }
192209
193- srv := jaegerui .NewServer (jaegerui.Config {})
194-
195- if err := srv .AddTrace (traceid , bytes .NewReader (data )); err != nil {
196- return err
197- }
198-
199210 ln , err := net .Listen ("tcp" , opts .addr )
200211 if err != nil {
201212 return err
202213 }
203214
204- url := "http://" + ln .Addr ().String () + "/trace/" + traceid
205-
206215 go func () {
207216 time .Sleep (100 * time .Millisecond )
208217 browser .OpenURL (url )
209218 }()
210219
220+ url = "http://" + ln .Addr ().String () + url
211221 fmt .Fprintf (dockerCli .Err (), "Trace available at %s\n " , url )
212222
213223 go func () {
@@ -246,6 +256,7 @@ func traceCmd(dockerCli command.Cli, rootOpts RootOptions) *cobra.Command {
246256 flags := cmd .Flags ()
247257 flags .StringVar (& options .containerName , "container" , "" , "Container name" )
248258 flags .StringVar (& options .addr , "addr" , "127.0.0.1:0" , "Address to bind the UI server" )
259+ flags .StringVar (& options .compare , "compare" , "" , "Compare with another build reference" )
249260
250261 return cmd
251262}
0 commit comments