Skip to content

Commit

Permalink
Remove appext.TracerContainer (#3372)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev authored Oct 5, 2024
1 parent 529f629 commit 15324e4
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 65 deletions.
2 changes: 1 addition & 1 deletion private/buf/bufcli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion private/buf/buflsp/buflsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions private/buf/bufwkt/cmd/wkt-go-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(),
)
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/alpha/protoc/protoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/beta/lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
)
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func run(
}
migrator := bufmigrate.NewMigrator(
container.Logger(),
tracing.NewTracer(container.Tracer()),
tracing.NewTracerForName(container.AppName()),
runner,
moduleKeyProvider,
commitProvider,
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/config/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/curl/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func run(
}
return bufgen.NewGenerator(
logger,
tracing.NewTracer(container.Tracer()),
tracing.NewTracerForName(container.AppName()),
storageosProvider,
command.NewRunner(),
clientConfig,
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/buf/command/mod/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/protoc-gen-buf-breaking/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion private/buf/cmd/protoc-gen-buf-lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions private/pkg/app/appext/appext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.
Expand All @@ -119,7 +108,6 @@ type Container interface {
app.Container
NameContainer
LoggerContainer
TracerContainer
VerboseContainer
}

Expand Down
2 changes: 0 additions & 2 deletions private/pkg/app/appext/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type container struct {
app.Container
NameContainer
LoggerContainer
TracerContainer
VerboseContainer
}

Expand All @@ -42,7 +41,6 @@ func newContainer(
Container: baseContainer,
NameContainer: nameContainer,
LoggerContainer: newLoggerContainer(logger),
TracerContainer: newTracerContainer(appName),
VerboseContainer: newVerboseContainer(verbosePrinter),
}, nil
}
34 changes: 0 additions & 34 deletions private/pkg/app/appext/tracer_container.go

This file was deleted.

6 changes: 6 additions & 0 deletions private/pkg/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand Down

0 comments on commit 15324e4

Please sign in to comment.