Skip to content

Commit

Permalink
add bucket boundaries acc to seconds instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Apr 16, 2024
1 parent d1c4690 commit bab137f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions otelcourier/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ import (
"fmt"
"time"

prom "github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/otel/metric"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
)

var metricFlowNames = map[tracePath]string{
tracePublisher: "publish",
traceSubscriber: "subscribe",
traceUnsubscriber: "unsubscribe",
traceCallback: "subscribe.callback",
var metricFlows = map[tracePath]struct {
name string
boundaries []float64
}{
tracePublisher: {name: "publish", boundaries: prom.ExponentialBucketsRange(0.0001, 1, 10)},
traceSubscriber: {name: "subscribe", boundaries: prom.ExponentialBucketsRange(0.001, 1, 7)},
traceUnsubscriber: {name: "unsubscribe", boundaries: prom.ExponentialBucketsRange(0.001, 1, 7)},
traceCallback: {name: "subscribe.callback", boundaries: prom.ExponentialBucketsRange(0.001, 10, 15)},
}

func (t *OTel) initRecorders() {
for path, flow := range metricFlowNames {
for path, flow := range metricFlows {
if !t.tracePaths.match(path) {
continue
}

t.rc[path] = t.newRecorder(flow)
t.rc[path] = t.newRecorder(flow.name, flow.boundaries)
}

if t.infoHandler != nil {
Expand All @@ -43,7 +47,7 @@ func (t *OTel) initInfoHandler() {

type recordersOp func(*recorders) error

func (t *OTel) newRecorder(flow string) *recorders {
func (t *OTel) newRecorder(flow string, boundaries []float64) *recorders {
var rs recorders

for _, op := range []recordersOp{
Expand All @@ -70,6 +74,7 @@ func (t *OTel) newRecorder(flow string) *recorders {
fmt.Sprintf("courier.%s.latency", flow),
metric.WithDescription(fmt.Sprintf("Latency of %s calls", flow)),
metric.WithUnit("s"),
metric.WithExplicitBucketBoundaries(boundaries...),
)
r.latency = lt

Expand Down
2 changes: 1 addition & 1 deletion otelcourier/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ func Test_recorderOpsWithoutInitialization(t *testing.T) {
func Test_recorderPanicsWithInvalidFlowName(t *testing.T) {
ot := &OTel{meter: metric.NewMeterProvider().Meter(tracerName)}

assert.Panics(t, func() { _ = ot.newRecorder("invalid%flow") })
assert.Panics(t, func() { _ = ot.newRecorder("invalid%flow", nil) })
}

0 comments on commit bab137f

Please sign in to comment.