Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Tag traces with log level. (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baliedge authored Aug 12, 2022
1 parent f5b40ae commit 1803ac2
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ gubernator.egg-info/
googleapis/
coverage.out
coverage.html
/gubernator
/gubernator-cli
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
VERSION=$(shell cat version)
LDFLAGS="-X main.Version=$(VERSION)"

.PHONY: lint
lint:
go vet ./...

.PHONY: test
test:
(go test -v -race -p=1 -count=1 -coverprofile coverage.out ./...; ret=$$?; \
Expand Down
8 changes: 4 additions & 4 deletions algorithms.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// Implements token bucket algorithm for rate limiting. https://en.wikipedia.org/wiki/Token_bucket
func tokenBucket(ctx context.Context, s Store, c Cache, r *RateLimitReq) (resp *RateLimitResp, err error) {
ctx = tracing.StartScope(ctx)
ctx = tracing.StartScopeDebug(ctx)
defer func() {
tracing.EndScope(ctx, err)
}()
Expand Down Expand Up @@ -213,7 +213,7 @@ func tokenBucket(ctx context.Context, s Store, c Cache, r *RateLimitReq) (resp *

// Called by tokenBucket() when adding a new item in the store.
func tokenBucketNewItem(ctx context.Context, s Store, c Cache, r *RateLimitReq) (resp *RateLimitResp, err error) {
ctx = tracing.StartScope(ctx)
ctx = tracing.StartScopeDebug(ctx)
defer func() {
tracing.EndScope(ctx, err)
}()
Expand Down Expand Up @@ -273,7 +273,7 @@ func tokenBucketNewItem(ctx context.Context, s Store, c Cache, r *RateLimitReq)

// Implements leaky bucket algorithm for rate limiting https://en.wikipedia.org/wiki/Leaky_bucket
func leakyBucket(ctx context.Context, s Store, c Cache, r *RateLimitReq) (resp *RateLimitResp, err error) {
ctx = tracing.StartScope(ctx)
ctx = tracing.StartScopeDebug(ctx)
defer func() {
tracing.EndScope(ctx, err)
}()
Expand Down Expand Up @@ -452,7 +452,7 @@ func leakyBucket(ctx context.Context, s Store, c Cache, r *RateLimitReq) (resp *

// Called by leakyBucket() when adding a new item in the store.
func leakyBucketNewItem(ctx context.Context, s Store, c Cache, r *RateLimitReq) (resp *RateLimitResp, err error) {
ctx = tracing.StartScope(ctx)
ctx = tracing.StartScopeDebug(ctx)
defer func() {
tracing.EndScope(ctx, err)
}()
Expand Down
5 changes: 2 additions & 3 deletions cmd/gubernator-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/mailgun/holster/v4/tracing"
"github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
"golang.org/x/time/rate"
)
Expand Down Expand Up @@ -71,9 +70,9 @@ func main() {
log.WithError(err).Fatal("Error in tracing.NewResource")
}
ctx := context.Background()
_, _, err = tracing.InitTracing(ctx,
err = tracing.InitTracing(ctx,
"github.com/mailgun/gubernator/v2/cmd/gubernator-cli",
sdktrace.WithResource(res),
tracing.WithResource(res),
)
if err != nil {
log.WithError(err).Warn("Error in tracing.InitTracing")
Expand Down
6 changes: 3 additions & 3 deletions cmd/gubernator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/mailgun/holster/v4/ctxutil"
"github.com/mailgun/holster/v4/tracing"
"github.com/sirupsen/logrus"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"k8s.io/klog"
)

Expand Down Expand Up @@ -60,9 +59,10 @@ func main() {
log.WithError(err).Fatal("Error in tracing.NewResource")
}

ctx, _, err := tracing.InitTracing(context.Background(),
ctx := context.Background()
err = tracing.InitTracing(ctx,
"github.com/mailgun/gubernator/v2",
sdktrace.WithResource(res),
tracing.WithResource(res),
)
if err != nil {
log.WithError(err).Warn("Error in tracing.InitTracing")
Expand Down
41 changes: 23 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ go 1.17
require (
github.com/OneOfOne/xxhash v1.2.8
github.com/davecgh/go-spew v1.1.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2
github.com/hashicorp/memberlist v0.3.1
github.com/mailgun/holster/v4 v4.3.3
github.com/mailgun/holster/v4 v4.7.0
github.com/miekg/dns v1.1.49
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_golang v1.13.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.32.1
github.com/prometheus/common v0.37.0
github.com/segmentio/fasthash v1.0.2
github.com/sirupsen/logrus v1.8.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.0
go.etcd.io/etcd/client/v3 v3.5.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.33.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.33.0
go.opentelemetry.io/otel v1.8.0
go.opentelemetry.io/otel/sdk v1.7.0
go.opentelemetry.io/otel/trace v1.8.0
golang.org/x/net v0.0.0-20220607020251-c690dde0001d
go.opentelemetry.io/otel v1.9.0
go.opentelemetry.io/otel/sdk v1.9.0
go.opentelemetry.io/otel/trace v1.9.0
golang.org/x/net v0.0.0-20220811182439-13a9a731de15
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
google.golang.org/api v0.43.0
google.golang.org/genproto v0.0.0-20220607140733-d738665f6195
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
google.golang.org/genproto v0.0.0-20220812140447-cec7f5303424
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
k8s.io/api v0.23.3
k8s.io/apimachinery v0.23.3
k8s.io/client-go v0.23.3
Expand All @@ -38,6 +38,7 @@ require (
cloud.google.com/go v0.81.0 // indirect
github.com/armon/go-metrics v0.4.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
Expand All @@ -64,23 +65,27 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.14 // indirect
github.com/uptrace/opentelemetry-go-extra/otelutil v0.1.14 // indirect
github.com/uptrace/opentelemetry-go-extra/otellogrus v0.1.15 // indirect
github.com/uptrace/opentelemetry-go-extra/otelutil v0.1.15 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.7.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.9.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20220608164250-635b8c9b7f68 // indirect
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
Expand Down
Loading

0 comments on commit 1803ac2

Please sign in to comment.