Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added _total suffix to OTEL counter metrics. #5810

Merged
merged 15 commits into from
Aug 8, 2024
Merged
9 changes: 8 additions & 1 deletion internal/metrics/otelmetrics/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}

func (f *otelFactory) Counter(opts metrics.Options) metrics.Counter {
name := f.subScope(opts.Name)
name := counterNamingConvention(f.subScope(opts.Name))

Check warning on line 35 in internal/metrics/otelmetrics/factory.go

View check run for this annotation

Codecov / codecov/patch

internal/metrics/otelmetrics/factory.go#L35

Added line #L35 was not covered by tests
counter, err := f.meter.Int64Counter(name)
if err != nil {
log.Printf("Error creating OTEL counter: %v", err)
Expand Down Expand Up @@ -131,3 +131,10 @@
}
return metric.WithAttributes(attributes...)
}

func counterNamingConvention(name string) string {
if !strings.HasSuffix(name, "_total") {
name += "_total"

Check warning on line 137 in internal/metrics/otelmetrics/factory.go

View check run for this annotation

Codecov / codecov/patch

internal/metrics/otelmetrics/factory.go#L135-L137

Added lines #L135 - L137 were not covered by tests
Wise-Wizard marked this conversation as resolved.
Show resolved Hide resolved
}
return name

Check warning on line 139 in internal/metrics/otelmetrics/factory.go

View check run for this annotation

Codecov / codecov/patch

internal/metrics/otelmetrics/factory.go#L139

Added line #L139 was not covered by tests
}
Loading