Skip to content

Commit

Permalink
feat: update otel
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Mar 13, 2023
1 parent 7b858f0 commit b1e1f96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/uber-go/tally v3.4.3+incompatible
go.etcd.io/bbolt v1.3.6
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/metric v0.31.0
go.opentelemetry.io/otel/metric v0.37.0
go.opentelemetry.io/otel/trace v1.14.0
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
go.opentelemetry.io/otel/metric v0.31.0 h1:6SiklT+gfWAwWUR0meEMxQBtihpiEs4c+vL9spDTqUs=
go.opentelemetry.io/otel/metric v0.31.0/go.mod h1:ohmwj9KTSIeBnDBm/ZwH2PSZxZzoOaG2xZeekTRzL5A=
go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs=
go.opentelemetry.io/otel/metric v0.37.0/go.mod h1:DmdaHfGt54iV6UKxsV9slj2bBRJcKC1B1uvDLIioc1s=
go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M=
go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
Expand Down
19 changes: 9 additions & 10 deletions oteltg/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument/asyncint64"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/trace"

"github.com/gotd/td/bin"
Expand All @@ -22,9 +21,9 @@ import (

// Middleware is prometheus metrics middleware for Telegram.
type Middleware struct {
count asyncint64.Counter
failures asyncint64.Counter
duration syncfloat64.Histogram
count instrument.Int64Counter
failures instrument.Int64Counter
duration instrument.Float64Histogram
tracer trace.Tracer
}

Expand All @@ -43,7 +42,7 @@ func (m Middleware) Handle(next tg.Invoker) telegram.InvokeFunc {

ctx, span := m.tracer.Start(ctx, spanName, trace.WithAttributes(attrs...))
defer span.End()
m.count.Observe(ctx, 1, attrs...)
m.count.Add(ctx, 1, attrs...)
start := time.Now()

// Call actual method.
Expand All @@ -67,7 +66,7 @@ func (m Middleware) Handle(next tg.Invoker) telegram.InvokeFunc {
}
span.RecordError(err, trace.WithAttributes(errAttrs...))
attrs = append(attrs, errAttrs...)
m.failures.Observe(ctx, 1, attrs...)
m.failures.Add(ctx, 1, attrs...)
} else {
span.SetStatus(codes.Ok, "")
}
Expand Down Expand Up @@ -99,13 +98,13 @@ func New(meterProvider metric.MeterProvider, tracerProvider trace.TracerProvider
tracer: tracerProvider.Tracer(name),
}
var err error
if m.count, err = meter.AsyncInt64().Counter("tg.rpc.count"); err != nil {
if m.count, err = meter.Int64Counter("tg.rpc.count"); err != nil {
return nil, err
}
if m.failures, err = meter.AsyncInt64().Counter("tg.rpc.failures"); err != nil {
if m.failures, err = meter.Int64Counter("tg.rpc.failures"); err != nil {
return nil, err
}
if m.duration, err = meter.SyncFloat64().Histogram("tg.rpc.duration"); err != nil {
if m.duration, err = meter.Float64Histogram("tg.rpc.duration"); err != nil {
return nil, err
}
return m, nil
Expand Down

0 comments on commit b1e1f96

Please sign in to comment.