Skip to content

Commit 201a204

Browse files
committed
add telemetry error
1 parent 6d8f645 commit 201a204

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

cmd/dockersync/cmd/mergeYaml.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
var yamlFiles []string
1313

14-
// mergeYamlCmd represents the mergeYaml command
1514
var mergeYamlCmd = &cobra.Command{
1615
Use: "mergeYaml",
1716
Short: "Merge two yaml files",

internal/sync/images.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package sync
22

33
import (
4+
"context"
5+
6+
"github.com/Altinity/docker-sync/internal/telemetry"
47
"github.com/Altinity/docker-sync/structs"
58
"github.com/rs/zerolog/log"
9+
"go.opentelemetry.io/otel/attribute"
10+
"go.opentelemetry.io/otel/metric"
611
"go.uber.org/multierr"
712
)
813

9-
func SyncImage(image *structs.Image) error {
14+
func SyncImage(ctx context.Context, image *structs.Image) error {
1015
var merr error
1116

1217
tags, err := image.GetTags()
@@ -18,6 +23,18 @@ func SyncImage(image *structs.Image) error {
1823
if serr := SyncTag(image, tag); serr != nil {
1924
errs := multierr.Errors(serr)
2025
if len(errs) > 0 {
26+
telemetry.Errors.Add(ctx, int64(len(errs)),
27+
metric.WithAttributes(
28+
attribute.KeyValue{
29+
Key: "image",
30+
Value: attribute.StringValue(image.Source),
31+
},
32+
attribute.KeyValue{
33+
Key: "tag",
34+
Value: attribute.StringValue(tag),
35+
},
36+
),
37+
)
2138
log.Error().
2239
Errs("errors", errs).
2340
Msg("Failed to sync tag")

internal/telemetry/metrics.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ import (
77

88
var meter = otel.Meter("docker-sync")
99

10-
// ReceivedBytes track the total number of bytes received.
11-
var ReceivedBytes = must(meter.Int64Counter("received_bytes",
12-
metric.WithDescription("The total number of bytes received"),
13-
metric.WithUnit("By"),
14-
))
15-
16-
// SentBytes track the total number of bytes sent.
17-
var SentBytes = must(meter.Int64Counter("sent_bytes",
18-
metric.WithDescription("The total number of bytes sent"),
19-
metric.WithUnit("By"),
10+
var Errors = must(meter.Int64Counter("errors",
11+
metric.WithDescription("The total number of errors"),
2012
))

internal/telemetry/otel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Start(ctx context.Context) error {
2828
resource.WithContainer(),
2929
resource.WithHost(),
3030
resource.WithAttributes(
31-
attribute.String("service", "docker-sync"),
31+
attribute.String("service", "dockersync"),
3232
),
3333
)
3434
if err != nil {

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func Run(ctx context.Context) error {
3434
default:
3535
image := images[k]
3636

37-
if err := sync.SyncImage(image); err != nil {
37+
if err := sync.SyncImage(ctx, image); err != nil {
3838
log.Error().
3939
Err(err).
4040
Str("source", image.Source).

0 commit comments

Comments
 (0)