Skip to content

Commit

Permalink
tidy up some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
voidlock committed Oct 20, 2023
1 parent b32724a commit 583acfb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
30 changes: 15 additions & 15 deletions cmdutil/metrics/otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import (

"github.com/sirupsen/logrus"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"

"github.com/heroku/x/go-kit/metrics"
otel "github.com/heroku/x/go-kit/metrics/provider/otel"
)
Expand All @@ -23,22 +20,29 @@ func MustProvider(ctx context.Context, logger logrus.FieldLogger, cfg Config, se
logger.Fatal("provider collectorURL cannot be nil")
}

attrs := []attribute.KeyValue{}
// configure some optional resource attributes
attrs := otel.MetricsDestinations(cfg.MetricsDestinations)
if cfg.Honeycomb.MetricsDataset != "" {
attrs = append(attrs, attribute.String("dataset", cfg.Honeycomb.MetricsDataset))
}
for _, md := range cfg.MetricsDestinations {
attrs = append(attrs, attribute.String(md, "true"))
attrs = append(attrs, otel.HoneycombDataset(cfg.Honeycomb.MetricsDataset))
}

res := resource.NewSchemaless(attrs...)

allOpts := []otel.Option{
// ensure we have service.id, service.namespace, and service.instance.id attributes
otel.WithOpenTelemetryStandardService(service, serviceNamespace, serviceInstanceID),

// ensure we have _service and component attributes
otel.WithServiceStandard(service),

// ensure we have stage and _subcomponent attributes
otel.WithEnvironmentStandard(stage),
otel.WithResource(res),

// if set, ensure we have honeycomb dataset and metrics destination attributes set
otel.WithAttributes(attrs...),

// exponential histograms are generally easier to use than explicit
otel.WithExponentialHistograms(),

// ensure we use the http exporter
otel.WithHTTPEndpointExporter(cfg.CollectorURL.String()),
}
allOpts = append(allOpts, opts...)
Expand All @@ -48,9 +52,5 @@ func MustProvider(ctx context.Context, logger logrus.FieldLogger, cfg Config, se
logger.Fatal(err)
}

if err := otelProvider.(*otel.Provider).Start(); err != nil {
logger.WithError(err).Fatal("failed to start metrics provider")
}

return otelProvider
}
2 changes: 1 addition & 1 deletion go-kit/metrics/provider/otel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func New(ctx context.Context, serviceName string, opts ...Option) (xmetrics.Prov
defaultOpts := []Option{
WithServiceStandard(serviceName),
DefaultAggregationSelector(),
WithDefaultEndpointExporter(),
DefaultEndpointExporter(),
}

opts = append(defaultOpts, opts...)
Expand Down
2 changes: 1 addition & 1 deletion go-kit/metrics/provider/otel/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func HoneycombDataset(val string) attribute.KeyValue {
return HoneycombDatasetKey.String(val)
}

func MetricDestinations(destinations []string) []attribute.KeyValue {
func MetricsDestinations(destinations []string) []attribute.KeyValue {
attrs := []attribute.KeyValue{}

for _, md := range destinations {
Expand Down
9 changes: 3 additions & 6 deletions go-kit/metrics/provider/otel/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ func (p *Provider) newCounter(name string, labelValues ...string) metrics.Counte
m := p.meterProvider.Meter(name)

if _, ok := p.counters[k]; !ok {
c, err := m.Float64Counter(name)
if err != nil {
// TODO how to service this error
}
c, _ := m.Float64Counter(name)

p.counters[k] = &Counter{
Float64Counter: c,
Expand Down Expand Up @@ -96,7 +93,7 @@ func (p *Provider) newGauge(name string, labelValues ...string) metrics.Gauge {
if _, ok := p.gauges[k]; !ok {
gg := generic.NewGauge(name)

callback := func(ctx context.Context, result metric.Float64Observer) error {
callback := func(_ context.Context, result metric.Float64Observer) error {
result.Observe(gg.Value(), metric.WithAttributeSet(attributes))

return nil
Expand Down Expand Up @@ -197,7 +194,7 @@ func (h *Histogram) With(labelValues ...string) metrics.Histogram {

// Observe implements metrics.Histogram.
func (h *Histogram) Observe(value float64) {
h.Float64Histogram.Record(h.p.cfg.ctx, value, metric.WithAttributeSet(h.attributes))
h.Record(h.p.cfg.ctx, value, metric.WithAttributeSet(h.attributes))
}

// NewCardinalityCounter implements metrics.Provider.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
github.com/urfave/cli v1.21.0
go.opencensus.io v0.22.1
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.42.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.42.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.42.0
go.opentelemetry.io/otel/metric v1.19.0
Expand Down

0 comments on commit 583acfb

Please sign in to comment.