Skip to content

Commit

Permalink
feat: update otel
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Apr 29, 2023
1 parent 007023a commit f45fa21
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ require (
github.com/stretchr/testify v1.8.2
github.com/uber-go/tally v3.4.3+incompatible
go.etcd.io/bbolt v1.3.7
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/metric v0.37.0
go.opentelemetry.io/otel/trace v1.14.0
go.opentelemetry.io/otel v1.15.0
go.opentelemetry.io/otel/metric v0.38.0
go.opentelemetry.io/otel/trace v1.15.0
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.24.0
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ github.com/go-faster/xor v0.3.0/go.mod h1:x5CaDY9UKErKzqfRfFZdfu+OSTfoZny3w5Ak7U
github.com/go-faster/xor v1.0.0 h1:2o8vTOgErSGHP3/7XwA5ib1FTtUsNtwCoLLBjl31X38=
github.com/go-faster/xor v1.0.0/go.mod h1:x5CaDY9UKErKzqfRfFZdfu+OSTfoZny3w5Ak7UxcipQ=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
Expand Down Expand Up @@ -370,12 +372,12 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
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.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.opentelemetry.io/otel v1.15.0 h1:NIl24d4eiLJPM0vKn4HjLYM+UZf6gSfi9Z+NmCxkWbk=
go.opentelemetry.io/otel v1.15.0/go.mod h1:qfwLEbWhLPk5gyWrne4XnF0lC8wtywbuJbgfAE3zbek=
go.opentelemetry.io/otel/metric v0.38.0 h1:vv/Nv/44S3GzMMmeUhaesBKsAenE6xLkTVWL+zuv30w=
go.opentelemetry.io/otel/metric v0.38.0/go.mod h1:uAtxN5hl8aXh5irD8afBtSwQU5Zjg64WWSz6KheZxBg=
go.opentelemetry.io/otel/trace v1.15.0 h1:5Fwje4O2ooOxkfyqI/kJwxWotggDLix4BSAvpE1wlpo=
go.opentelemetry.io/otel/trace v1.15.0/go.mod h1:CUsmE2Ht1CRkvE8OsMESvraoZrrcgD1J2W8GV1ev0Y4=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
Expand Down
6 changes: 3 additions & 3 deletions oteltg/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func (m Middleware) Handle(next tg.Invoker) telegram.InvokeFunc {

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

// Call actual method.
err := next.Invoke(ctx, input, output)

// Observe.
m.duration.Record(ctx, time.Since(start).Seconds(), attrs...)
m.duration.Record(ctx, time.Since(start).Seconds(), metric.WithAttributes(attrs...))
if err != nil {
var errAttrs []attribute.KeyValue
if rpcErr, ok := tgerr.As(err); ok {
Expand All @@ -66,7 +66,7 @@ func (m Middleware) Handle(next tg.Invoker) telegram.InvokeFunc {
}
span.RecordError(err, trace.WithAttributes(errAttrs...))
attrs = append(attrs, errAttrs...)
m.failures.Add(ctx, 1, attrs...)
m.failures.Add(ctx, 1, metric.WithAttributes(attrs...))
} else {
span.SetStatus(codes.Ok, "")
}
Expand Down
4 changes: 2 additions & 2 deletions oteltg/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
"go.opentelemetry.io/otel/trace"

"github.com/gotd/td/bin"
Expand All @@ -20,7 +20,7 @@ func (i invoker) Invoke(ctx context.Context, input bin.Encoder, output bin.Decod
}

func TestMiddleware_Handle(t *testing.T) {
m, err := New(metric.NewNoopMeterProvider(), trace.NewNoopTracerProvider())
m, err := New(noop.NewMeterProvider(), trace.NewNoopTracerProvider())
require.NoError(t, err)

okInvoker := invoker(func(ctx context.Context, input bin.Encoder, output bin.Decoder) error {
Expand Down

0 comments on commit f45fa21

Please sign in to comment.