Skip to content

Commit

Permalink
fix: use custom error logger for stackdriver exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Feb 8, 2023
1 parent aa72ee5 commit 965b6a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 8 additions & 1 deletion cmd/plugin-registry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"cloud.google.com/go/firestore"
"contrib.go.opencensus.io/exporter/stackdriver"
"github.com/go-semantic-release/plugin-registry/internal/config"
"github.com/go-semantic-release/plugin-registry/internal/metrics"
"github.com/go-semantic-release/plugin-registry/internal/plugin"
Expand Down Expand Up @@ -54,7 +55,13 @@ func run(log *logrus.Logger) error {
}

log.Info("setting up metrics exporter...")
exporter, err := metrics.NewExporter(cfg)
exporter, err := metrics.NewExporter(stackdriver.Options{
ProjectID: cfg.ProjectID,
MetricPrefix: "plugin-registry",
OnError: func(err error) {
log.Warnf("exporter error: %v", err)
},
})
if err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metrics

import (
"contrib.go.opencensus.io/exporter/stackdriver"
"github.com/go-semantic-release/plugin-registry/internal/config"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
Expand Down Expand Up @@ -42,15 +41,12 @@ var views = []*view.View{
},
}

func NewExporter(cfg *config.ServerConfig) (*stackdriver.Exporter, error) {
func NewExporter(opt stackdriver.Options) (*stackdriver.Exporter, error) {
err := view.Register(views...)
if err != nil {
return nil, err
}
exporter, err := stackdriver.NewExporter(stackdriver.Options{
ProjectID: cfg.ProjectID,
MetricPrefix: "plugin-registry",
})
exporter, err := stackdriver.NewExporter(opt)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 965b6a0

Please sign in to comment.