Skip to content

Commit

Permalink
Merge pull request #45 from krzko/feature/fix-servic-name-upgrade-pkg
Browse files Browse the repository at this point in the history
Fix service.name propagation in metrics
  • Loading branch information
krzko authored Oct 16, 2022
2 parents 7776697 + 048dd22 commit 134e0b0
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/cli/metrics_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func generateMetricsCounterAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics_counter_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func generateMetricsCounterObserverAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics_counter_observer_advanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func generateMetricsCounterObserverAdvancedAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics_counter_with_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func generateMetricsCounterWithLabelsAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics_gauge_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func generateMetricsGaugeObserverAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func generateMetricsHistogramAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics_up_down_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func generateMetricsUpDownCounterAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/metrics_up_down_counter_observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func generateMetricsUpDownCounterObserverAction(c *cli.Context) error {
ctx := context.Background()
logger.Info("Starting metrics generation")

var meter = global.MeterProvider().Meter(c.String("service-name"))
var meter = global.MeterProvider().Meter(metricsCfg.ServiceName)

if _, err := metrics.Run(ctx, exp, meter, metricsCfg, logger); err != nil {
logger.Error("failed to stop the exporter", zap.Error(err))
Expand Down
3 changes: 3 additions & 0 deletions internal/metrics/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
"go.uber.org/zap"
"golang.org/x/time/rate"
)
Expand Down Expand Up @@ -68,6 +70,7 @@ func Run(ctx context.Context, exp *otlpmetric.Exporter, m metric.Meter, c *Confi
),
controller.WithExporter(exp),
controller.WithCollectPeriod(time.Duration(c.Rate)*time.Second),
controller.WithResource(resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceNameKey.String(c.ServiceName))),
)

global.SetMeterProvider(pusher)
Expand Down

0 comments on commit 134e0b0

Please sign in to comment.