44 "context"
55 "net/http"
66 "os"
7+ "strings"
78 "time"
89
910 "github.com/docker/model-runner/pkg/distribution/types"
@@ -39,8 +40,11 @@ func NewTracker(httpClient *http.Client, log logging.Logger, userAgent string, d
3940 client .Transport = http .DefaultTransport
4041 }
4142
43+ userAgent = strings .TrimSpace (userAgent )
4244 if userAgent == "" {
4345 userAgent = "docker-model-runner"
46+ } else {
47+ userAgent = userAgent + " docker-model-runner"
4448 }
4549
4650 if os .Getenv ("DEBUG" ) == "1" {
@@ -59,24 +63,28 @@ func NewTracker(httpClient *http.Client, log logging.Logger, userAgent string, d
5963 }
6064}
6165
62- func (t * Tracker ) TrackModel (model types.Model , userAgent string ) {
66+ func (t * Tracker ) TrackModel (model types.Model , userAgent , action string ) {
6367 if t .doNotTrack {
6468 return
6569 }
6670
67- go t .trackModel (model , userAgent )
71+ go t .trackModel (model , userAgent , action )
6872}
6973
70- func (t * Tracker ) trackModel (model types.Model , userAgent string ) {
74+ func (t * Tracker ) trackModel (model types.Model , userAgent , action string ) {
7175 tags := model .Tags ()
7276 t .log .Debugln ("Tracking model:" , tags )
7377 if len (tags ) == 0 {
7478 return
7579 }
76- ua := t .userAgent
80+ parts := [] string { t .userAgent }
7781 if userAgent != "" {
78- ua += " " + userAgent
82+ parts = append ( parts , userAgent )
7983 }
84+ if action != "" {
85+ parts = append (parts , action )
86+ }
87+ ua := strings .Join (parts , " " )
8088 for _ , tag := range tags {
8189 ref , err := name .ParseReference (tag )
8290 if err != nil {
0 commit comments