Skip to content

Commit

Permalink
Upgrade OTEL to v1.20.0 (#2579)
Browse files Browse the repository at this point in the history
The latest version of OTEL requires embedding the
embedded.TracerProvider interface going forward in any implementations.
Instead of implementing/extending TracerProvider, instead return a
separate Closer.
  • Loading branch information
pkwarren authored Nov 13, 2023
1 parent fb220df commit 92ef372
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/tetratelabs/wazero v1.5.0
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/sdk v1.19.0
go.opentelemetry.io/otel/trace v1.19.0
go.opentelemetry.io/otel v1.20.0
go.opentelemetry.io/otel/sdk v1.20.0
go.opentelemetry.io/otel/trace v1.20.0
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
Expand Down Expand Up @@ -75,7 +75,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.20.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinC
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o=
go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A=
go.opentelemetry.io/otel v1.20.0 h1:vsb/ggIY+hUjD/zCAQHpzTmndPqv/ml2ArbsbfBYTAc=
go.opentelemetry.io/otel v1.20.0/go.mod h1:oUIGj3D77RwJdM6PPZImDpSZGDvkD9fhesHny69JFrs=
go.opentelemetry.io/otel/metric v1.20.0 h1:ZlrO8Hu9+GAhnepmRGhSU7/VkpjrNowxRN9GyKR4wzA=
go.opentelemetry.io/otel/metric v1.20.0/go.mod h1:90DRw3nfK4D7Sm/75yQ00gTJxtkBxX+wu6YaNymbpVM=
go.opentelemetry.io/otel/sdk v1.20.0 h1:5Jf6imeFZlZtKv9Qbo6qt2ZkmWtdWx/wzcCbNUlAWGM=
go.opentelemetry.io/otel/sdk v1.20.0/go.mod h1:rmkSx1cZCm/tn16iWDn1GQbLtsW/LvsdEEFzCSRM6V0=
go.opentelemetry.io/otel/sdk/metric v1.19.0 h1:EJoTO5qysMsYCa+w4UghwFV/ptQgqSL/8Ni+hx+8i1k=
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
go.opentelemetry.io/otel/trace v1.20.0 h1:+yxVAPZPbQhbC3OfAkeIVTky6iTFpcr4SiY9om7mXSQ=
go.opentelemetry.io/otel/trace v1.20.0/go.mod h1:HJSK7F/hA5RlzpZ0zKDCHCDHm556LCDtKaAo6JmBFUU=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
Expand Down
5 changes: 2 additions & 3 deletions private/pkg/app/appflag/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/bufbuild/buf/private/pkg/observabilityzap"
"github.com/pkg/profile"
"github.com/spf13/pflag"
"go.opentelemetry.io/otel"
"go.uber.org/multierr"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -128,11 +127,11 @@ func (b *builder) run(
}

if b.tracing {
closer := observabilityzap.Start(logger)
tracerProvider, closer := observabilityzap.Start(logger)
defer func() {
retErr = multierr.Append(retErr, closer.Close())
}()
_, span := otel.GetTracerProvider().Tracer("bufbuild/buf").Start(ctx, "command")
_, span := tracerProvider.Tracer("bufbuild/buf").Start(ctx, "command")
defer span.End()
}
if !b.profile {
Expand Down
12 changes: 3 additions & 9 deletions private/pkg/observabilityzap/observabilityzap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,16 @@ import (
"go.uber.org/zap"
)

// TracerProviderCloser is used to wrap a trace.TracerProvider with an io.Closer to use on shutdown.
type TracerProviderCloser interface {
trace.TracerProvider
io.Closer
}

// Start creates a Zap logging exporter for Opentelemetry traces and returns
// the exporter. The exporter implements io.Closer for clean-up.
func Start(logger *zap.Logger) TracerProviderCloser {
func Start(logger *zap.Logger) (trace.TracerProvider, io.Closer) {
exporter := newZapExporter(logger)
tracerProviderOptions := []sdktrace.TracerProviderOption{
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithSpanProcessor(sdktrace.NewBatchSpanProcessor(exporter)),
}
tracerProvider := newTracerProviderCloser(sdktrace.NewTracerProvider(tracerProviderOptions...))
tracerProvider := sdktrace.NewTracerProvider(tracerProviderOptions...)
otel.SetTracerProvider(tracerProvider)
otel.SetTextMapPropagator(propagation.TraceContext{})
return tracerProvider
return tracerProvider, newTracerProviderCloser(tracerProvider)
}
6 changes: 0 additions & 6 deletions private/pkg/observabilityzap/tracer_provider_closer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import (
"io"

sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)

var _ trace.TracerProvider = &tracerProviderCloser{}
var _ io.Closer = &tracerProviderCloser{}

type tracerProviderCloser struct {
Expand All @@ -35,10 +33,6 @@ func newTracerProviderCloser(tracerProvider *sdktrace.TracerProvider) *tracerPro
}
}

func (t *tracerProviderCloser) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
return t.tracerProvider.Tracer(name, opts...)
}

func (t *tracerProviderCloser) Close() error {
return t.tracerProvider.Shutdown(context.Background())
}

0 comments on commit 92ef372

Please sign in to comment.