Skip to content

Commit a1cc051

Browse files
committed
fix: improve error handling and telemetry in image sync
1 parent 2515b53 commit a1cc051

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

internal/sync/images.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
208208
return nil
209209
}
210210
if err := push(ctx, image, desc, dst, tag); err != nil {
211-
log.Error().Err(err).Msg("Failed to push tag")
211+
return err
212212
}
213-
return err
213+
214+
return nil
214215
}
215216

216217
return nil
@@ -222,6 +223,23 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
222223
Msg("Failed to sync tag")
223224

224225
telemetry.Errors.Add(ctx, 1,
226+
metric.WithAttributes(
227+
attribute.KeyValue{
228+
Key: "image",
229+
Value: attribute.StringValue(image.Source),
230+
},
231+
attribute.KeyValue{
232+
Key: "tag",
233+
Value: attribute.StringValue(tag),
234+
},
235+
attribute.KeyValue{
236+
Key: "error",
237+
Value: attribute.StringValue(err.Error()),
238+
},
239+
),
240+
)
241+
} else {
242+
telemetry.Syncs.Add(ctx, 1,
225243
metric.WithAttributes(
226244
attribute.KeyValue{
227245
Key: "image",
@@ -233,8 +251,6 @@ func SyncImage(ctx context.Context, image *structs.Image) error {
233251
},
234252
),
235253
)
236-
237-
return err
238254
}
239255
}
240256

internal/telemetry/metrics.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ var meter = otel.Meter("docker-sync")
1010
var Errors = must(meter.Int64Counter("errors",
1111
metric.WithDescription("The total number of errors"),
1212
))
13+
14+
var Syncs = must(meter.Int64Counter("syncs",
15+
metric.WithDescription("The total number of syncs"),
16+
))

0 commit comments

Comments
 (0)