From 15324e418c2630b42fd2e20b93d3ef0fd5a2d174 Mon Sep 17 00:00:00 2001 From: bufdev <4228796+bufdev@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:21:40 -0400 Subject: [PATCH] Remove appext.TracerContainer (#3372) --- private/buf/bufcli/controller.go | 2 +- private/buf/buflsp/buflsp.go | 2 +- private/buf/bufwkt/cmd/wkt-go-data/main.go | 4 +-- .../cmd/buf/command/alpha/protoc/protoc.go | 2 +- private/buf/cmd/buf/command/beta/lsp/lsp.go | 2 +- .../buf/cmd/buf/command/breaking/breaking.go | 2 +- .../config/configmigrate/configmigrate.go | 2 +- .../buf/command/config/internal/internal.go | 2 +- .../buf/cmd/buf/command/convert/convert.go | 2 +- private/buf/cmd/buf/command/curl/curl.go | 2 +- .../buf/cmd/buf/command/generate/generate.go | 2 +- private/buf/cmd/buf/command/lint/lint.go | 2 +- .../cmd/buf/command/mod/internal/internal.go | 2 +- .../cmd/protoc-gen-buf-breaking/breaking.go | 2 +- private/buf/cmd/protoc-gen-buf-lint/lint.go | 2 +- .../bufmoduletesting/cmd/buf-digest/digest.go | 2 +- private/pkg/app/appext/appext.go | 12 ------- private/pkg/app/appext/container.go | 2 -- private/pkg/app/appext/tracer_container.go | 34 ------------------- private/pkg/tracing/tracing.go | 6 ++++ 20 files changed, 23 insertions(+), 65 deletions(-) delete mode 100644 private/pkg/app/appext/tracer_container.go diff --git a/private/buf/bufcli/controller.go b/private/buf/bufcli/controller.go index 836d0123f2..0fb1910efb 100644 --- a/private/buf/bufcli/controller.go +++ b/private/buf/bufcli/controller.go @@ -52,7 +52,7 @@ func NewController( } return bufctl.NewController( container.Logger(), - tracing.NewTracer(container.Tracer()), + tracing.NewTracerForName(container.AppName()), container, newGraphProvider(container, clientProvider), bufmoduleapi.NewModuleKeyProvider(container.Logger(), clientProvider), diff --git a/private/buf/buflsp/buflsp.go b/private/buf/buflsp/buflsp.go index 06c3cc51e9..7e19895d8f 100644 --- a/private/buf/buflsp/buflsp.go +++ b/private/buf/buflsp/buflsp.go @@ -65,7 +65,7 @@ func Serve( zap.NewNop(), // The logging from protocol itself isn't very good, we've replaced it with connAdapter here. ), logger: container.Logger(), - tracer: tracing.NewTracer(container.Tracer()), + tracer: tracing.NewTracerForName(container.AppName()), controller: controller, checkClient: checkClient, rootBucket: bucket, diff --git a/private/buf/bufwkt/cmd/wkt-go-data/main.go b/private/buf/bufwkt/cmd/wkt-go-data/main.go index 47f377e083..8c133a7268 100644 --- a/private/buf/bufwkt/cmd/wkt-go-data/main.go +++ b/private/buf/bufwkt/cmd/wkt-go-data/main.go @@ -181,7 +181,7 @@ func getProtosourceFiles( ) ([]bufprotosource.File, error) { moduleSet, err := bufmodule.NewModuleSetBuilder( ctx, - tracing.NewTracer(container.Tracer()), + tracing.NewTracerForName(container.AppName()), bufmodule.NopModuleDataProvider, bufmodule.NopCommitProvider, ).AddLocalModule( @@ -195,7 +195,7 @@ func getProtosourceFiles( module := bufmodule.ModuleSetToModuleReadBucketWithOnlyProtoFiles(moduleSet) image, err := bufimage.BuildImage( ctx, - tracing.NewTracer(container.Tracer()), + tracing.NewTracerForName(container.AppName()), module, bufimage.WithExcludeSourceCodeInfo(), ) diff --git a/private/buf/cmd/buf/command/alpha/protoc/protoc.go b/private/buf/cmd/buf/command/alpha/protoc/protoc.go index 7d959049d6..22c8624676 100644 --- a/private/buf/cmd/buf/command/alpha/protoc/protoc.go +++ b/private/buf/cmd/buf/command/alpha/protoc/protoc.go @@ -90,7 +90,7 @@ func run( ) (retErr error) { runner := command.NewRunner() logger := container.Logger() - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) ctx, span := tracer.Start(ctx, tracing.WithErr(&retErr)) defer span.End() diff --git a/private/buf/cmd/buf/command/beta/lsp/lsp.go b/private/buf/cmd/buf/command/beta/lsp/lsp.go index 7ff61d8c5e..e6c1776ea4 100644 --- a/private/buf/cmd/buf/command/beta/lsp/lsp.go +++ b/private/buf/cmd/buf/command/beta/lsp/lsp.go @@ -108,7 +108,7 @@ func run( }() checkClient, err := bufcheck.NewClient( container.Logger(), - tracing.NewTracer(container.Tracer()), + tracing.NewTracerForName(container.AppName()), bufcheck.NewRunnerProvider(command.NewRunner(), wasmRuntime), bufcheck.ClientWithStderr(container.Stderr()), ) diff --git a/private/buf/cmd/buf/command/breaking/breaking.go b/private/buf/cmd/buf/command/breaking/breaking.go index 38e042005a..65d1d1aad9 100644 --- a/private/buf/cmd/buf/command/breaking/breaking.go +++ b/private/buf/cmd/buf/command/breaking/breaking.go @@ -219,7 +219,7 @@ func run( defer func() { retErr = multierr.Append(retErr, wasmRuntime.Close(ctx)) }() - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) var allFileAnnotations []bufanalysis.FileAnnotation for i, imageWithConfig := range imageWithConfigs { client, err := bufcheck.NewClient( diff --git a/private/buf/cmd/buf/command/config/configmigrate/configmigrate.go b/private/buf/cmd/buf/command/config/configmigrate/configmigrate.go index 0a85492772..a0366a7704 100644 --- a/private/buf/cmd/buf/command/config/configmigrate/configmigrate.go +++ b/private/buf/cmd/buf/command/config/configmigrate/configmigrate.go @@ -128,7 +128,7 @@ func run( } migrator := bufmigrate.NewMigrator( container.Logger(), - tracing.NewTracer(container.Tracer()), + tracing.NewTracerForName(container.AppName()), runner, moduleKeyProvider, commitProvider, diff --git a/private/buf/cmd/buf/command/config/internal/internal.go b/private/buf/cmd/buf/command/config/internal/internal.go index 897440f3ac..7bbc80ce72 100644 --- a/private/buf/cmd/buf/command/config/internal/internal.go +++ b/private/buf/cmd/buf/command/config/internal/internal.go @@ -197,7 +197,7 @@ func lsRun( defer func() { retErr = multierr.Append(retErr, wasmRuntime.Close(ctx)) }() - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) client, err := bufcheck.NewClient( container.Logger(), tracer, diff --git a/private/buf/cmd/buf/command/convert/convert.go b/private/buf/cmd/buf/command/convert/convert.go index 00d27366dd..6c0c471893 100644 --- a/private/buf/cmd/buf/command/convert/convert.go +++ b/private/buf/cmd/buf/command/convert/convert.go @@ -196,7 +196,7 @@ func run( var wktErr error schemaImage, wktErr = wellKnownTypeImage( ctx, - tracing.NewTracer(container.Tracer()), + tracing.NewTracerForName(container.AppName()), flags.Type, ) if wktErr != nil { diff --git a/private/buf/cmd/buf/command/curl/curl.go b/private/buf/cmd/buf/command/curl/curl.go index bdb1a31770..7e247c484c 100644 --- a/private/buf/cmd/buf/command/curl/curl.go +++ b/private/buf/cmd/buf/command/curl/curl.go @@ -1013,7 +1013,7 @@ func run(ctx context.Context, container appext.Container, f *flags) (err error) } // Add a WKT resolver to the end of the end of the list. This is used // for printing a WKT encoded in a "google.protobuf.Any" type as JSON. - wktResolver, err := bufcurl.NewWKTResolver(ctx, tracing.NewTracer(container.Tracer())) + wktResolver, err := bufcurl.NewWKTResolver(ctx, tracing.NewTracerForName(container.AppName())) if err != nil { return err } diff --git a/private/buf/cmd/buf/command/generate/generate.go b/private/buf/cmd/buf/command/generate/generate.go index 970dd26f02..c8bd35b5c9 100644 --- a/private/buf/cmd/buf/command/generate/generate.go +++ b/private/buf/cmd/buf/command/generate/generate.go @@ -542,7 +542,7 @@ func run( } return bufgen.NewGenerator( logger, - tracing.NewTracer(container.Tracer()), + tracing.NewTracerForName(container.AppName()), storageosProvider, command.NewRunner(), clientConfig, diff --git a/private/buf/cmd/buf/command/lint/lint.go b/private/buf/cmd/buf/command/lint/lint.go index 371b6e43de..cfaee9c7f5 100644 --- a/private/buf/cmd/buf/command/lint/lint.go +++ b/private/buf/cmd/buf/command/lint/lint.go @@ -144,7 +144,7 @@ func run( defer func() { retErr = multierr.Append(retErr, wasmRuntime.Close(ctx)) }() - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) var allFileAnnotations []bufanalysis.FileAnnotation for _, imageWithConfig := range imageWithConfigs { client, err := bufcheck.NewClient( diff --git a/private/buf/cmd/buf/command/mod/internal/internal.go b/private/buf/cmd/buf/command/mod/internal/internal.go index 1247554d19..43564a42a4 100644 --- a/private/buf/cmd/buf/command/mod/internal/internal.go +++ b/private/buf/cmd/buf/command/mod/internal/internal.go @@ -175,7 +175,7 @@ func lsRun( return fmt.Errorf(`"buf mod %s" does not work for v2 buf.yaml files, use "buf config %s" instead`, commandName, commandName) } // BufYAMLFiles <=v1 never had plugins. - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) client, err := bufcheck.NewClient( container.Logger(), tracer, diff --git a/private/buf/cmd/protoc-gen-buf-breaking/breaking.go b/private/buf/cmd/protoc-gen-buf-breaking/breaking.go index 522274a1a5..7f9de1188c 100644 --- a/private/buf/cmd/protoc-gen-buf-breaking/breaking.go +++ b/private/buf/cmd/protoc-gen-buf-breaking/breaking.go @@ -125,7 +125,7 @@ func handle( return err } // The protoc plugins do not support custom lint/breaking change plugins for now. - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) client, err := bufcheck.NewClient( container.Logger(), tracer, diff --git a/private/buf/cmd/protoc-gen-buf-lint/lint.go b/private/buf/cmd/protoc-gen-buf-lint/lint.go index b61a13edf2..706b86a071 100644 --- a/private/buf/cmd/protoc-gen-buf-lint/lint.go +++ b/private/buf/cmd/protoc-gen-buf-lint/lint.go @@ -100,7 +100,7 @@ func handle( return err } // The protoc plugins do not support custom lint/breaking change plugins for now. - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) client, err := bufcheck.NewClient( container.Logger(), tracer, diff --git a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-digest/digest.go b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-digest/digest.go index c940d78141..b13ac79690 100644 --- a/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-digest/digest.go +++ b/private/bufpkg/bufmodule/bufmoduletesting/cmd/buf-digest/digest.go @@ -101,7 +101,7 @@ func run( if len(dirPaths) == 0 { dirPaths = []string{"."} } - tracer := tracing.NewTracer(container.Tracer()) + tracer := tracing.NewTracerForName(container.AppName()) moduleSetBuilder := bufmodule.NewModuleSetBuilder(ctx, tracer, bufmodule.NopModuleDataProvider, bufmodule.NopCommitProvider) storageosProvider := storageos.NewProvider() for _, dirPath := range dirPaths { diff --git a/private/pkg/app/appext/appext.go b/private/pkg/app/appext/appext.go index e75082a4ad..cd04ca7911 100644 --- a/private/pkg/app/appext/appext.go +++ b/private/pkg/app/appext/appext.go @@ -28,7 +28,6 @@ import ( "github.com/bufbuild/buf/private/pkg/encoding" "github.com/bufbuild/buf/private/pkg/verbose" "github.com/spf13/pflag" - "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -91,16 +90,6 @@ func NewLoggerContainer(logger *zap.Logger) LoggerContainer { return newLoggerContainer(logger) } -// TracerContainer provides a trace.Tracer based on the application name. -type TracerContainer interface { - Tracer() trace.Tracer -} - -// NewTracerContainer returns a new TracerContainer for the application name. -func NewTracerContainer(appName string) TracerContainer { - return newTracerContainer(appName) -} - // VerboseContainer provides a verbose.Printer. type VerboseContainer interface { // VerboseEnabled returns true if verbose mode is enabled. @@ -119,7 +108,6 @@ type Container interface { app.Container NameContainer LoggerContainer - TracerContainer VerboseContainer } diff --git a/private/pkg/app/appext/container.go b/private/pkg/app/appext/container.go index 556a4f5ac6..838b5859e1 100644 --- a/private/pkg/app/appext/container.go +++ b/private/pkg/app/appext/container.go @@ -24,7 +24,6 @@ type container struct { app.Container NameContainer LoggerContainer - TracerContainer VerboseContainer } @@ -42,7 +41,6 @@ func newContainer( Container: baseContainer, NameContainer: nameContainer, LoggerContainer: newLoggerContainer(logger), - TracerContainer: newTracerContainer(appName), VerboseContainer: newVerboseContainer(verbosePrinter), }, nil } diff --git a/private/pkg/app/appext/tracer_container.go b/private/pkg/app/appext/tracer_container.go deleted file mode 100644 index d7f1833bd1..0000000000 --- a/private/pkg/app/appext/tracer_container.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020-2024 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package appext - -import ( - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/trace" -) - -type tracerContainer struct { - appName string -} - -func newTracerContainer(appName string) *tracerContainer { - return &tracerContainer{ - appName: appName, - } -} - -func (c *tracerContainer) Tracer() trace.Tracer { - return otel.GetTracerProvider().Tracer(c.appName) -} diff --git a/private/pkg/tracing/tracing.go b/private/pkg/tracing/tracing.go index 175cf62323..cf9dad0932 100644 --- a/private/pkg/tracing/tracing.go +++ b/private/pkg/tracing/tracing.go @@ -18,6 +18,7 @@ import ( "context" "runtime" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" @@ -38,6 +39,11 @@ func NewTracer(otelTracer trace.Tracer) Tracer { return newTracer(otelTracer) } +// NewTracerForName returns a new Tracer using otel.Tracer(name). +func NewTracerForName(name string) Tracer { + return newTracer(otel.Tracer(name)) +} + // StartOption is an option for Start. type StartOption func(*startOptions)