@@ -69,9 +69,15 @@ func (s *Source) Init(ctx context.Context, name string, jobId sources.JobID, sou
6969 s .verify = verify
7070 s .concurrency = concurrency
7171
72+ jobIDStr := fmt .Sprint (s .jobId )
73+
7274 // Reset metrics for this source at initialization time.
73- dockerImagesScanned .WithLabelValues (s .name ).Set (0 )
74- dockerLayersScanned .WithLabelValues (s .name ).Set (0 )
75+ dockerImagesScanned .WithLabelValues (s .name , jobIDStr ).Set (0 )
76+ dockerLayersScanned .WithLabelValues (s .name , jobIDStr ).Set (0 )
77+ dockerLayersEnumerated .WithLabelValues (s .name , jobIDStr ).Set (0 )
78+ dockerHistoryEntriesEnumerated .WithLabelValues (s .name , jobIDStr ).Set (0 )
79+ dockerImagesEnumerated .WithLabelValues (s .name , jobIDStr ).Set (0 )
80+ dockerHistoryEntriesScanned .WithLabelValues (s .name , jobIDStr ).Set (0 )
7581
7682 if err := anypb .UnmarshalTo (connection , & s .conn , proto.UnmarshalOptions {}); err != nil {
7783 return fmt .Errorf ("error unmarshalling connection: %w" , err )
@@ -115,6 +121,7 @@ type layerInfo struct {
115121// Chunks emits data over a channel that is decoded and scanned for secrets.
116122func (s * Source ) Chunks (ctx context.Context , chunksChan chan * sources.Chunk , _ ... sources.ChunkingTarget ) error {
117123 ctx = context .WithValues (ctx , "source_type" , s .Type (), "source_name" , s .name )
124+ jobIDStr := fmt .Sprint (s .jobId )
118125
119126 workers := new (errgroup.Group )
120127 workers .SetLimit (s .concurrency )
@@ -153,21 +160,23 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
153160 imageCtx .Logger ().Error (err , "error getting image layers" )
154161 continue
155162 }
163+ dockerLayersEnumerated .WithLabelValues (s .name , jobIDStr ).Add (float64 (len (layers )))
156164
157165 // Get history entries and associate them with layers
158166 historyEntries , err := getHistoryEntries (imageCtx , imgInfo , layers )
159167 if err != nil {
160168 imageCtx .Logger ().Error (err , "error getting image history entries" )
161169 continue
162170 }
171+ dockerHistoryEntriesEnumerated .WithLabelValues (s .name , jobIDStr ).Add (float64 (len (historyEntries )))
163172
164173 // Scan each history entry for secrets in build commands
165174 for _ , historyEntry := range historyEntries {
166175 if err := s .processHistoryEntry (imageCtx , historyEntry , chunksChan ); err != nil {
167176 imageCtx .Logger ().Error (err , "error processing history entry" )
168177 continue
169178 }
170- dockerHistoryEntriesScanned .WithLabelValues (s .name ).Inc ()
179+ dockerHistoryEntriesScanned .WithLabelValues (s .name , jobIDStr ).Inc ()
171180 }
172181
173182 imageCtx .Logger ().V (2 ).Info ("scanning image layers" )
@@ -179,7 +188,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
179188 imageCtx .Logger ().Error (err , "error processing layer" )
180189 return nil
181190 }
182- dockerLayersScanned .WithLabelValues (s .name ).Inc ()
191+ dockerLayersScanned .WithLabelValues (s .name , jobIDStr ).Inc ()
183192
184193 return nil
185194 })
@@ -190,7 +199,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
190199 continue
191200 }
192201
193- dockerImagesScanned .WithLabelValues (s .name ).Inc ()
202+ dockerImagesScanned .WithLabelValues (s .name , jobIDStr ).Inc ()
194203 }
195204
196205 return nil
@@ -502,7 +511,7 @@ func (s *Source) remoteOpts() ([]remote.Option, error) {
502511 }
503512
504513 var opts []remote.Option
505- opts = append (opts , remote .WithTransport (defaultTransport ))
514+ opts = append (opts , remote .WithTransport (common . NewInstrumentedTransport ( common . NewCustomTransport ( defaultTransport )) ))
506515
507516 // Configure authentication based on credential type
508517 switch s .conn .GetCredential ().(type ) {
0 commit comments