Skip to content

Commit

Permalink
fix: update logging imports in helpers file
Browse files Browse the repository at this point in the history
Fixes bug where some imports are missing if only rest or only grpc
transport is specified.
  • Loading branch information
codyoss committed Dec 9, 2024
1 parent 1875166 commit 28196b0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/gengapic/gengapic.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func (g *generator) genAndCommitHelpers(scopes []string) error {
g.reset()
g.imports[pbinfo.ImportSpec{Path: "context"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/option"}] = true
g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/internallog"}] = true

p("const serviceName = %q", g.serviceConfig.GetName())
p("")
Expand Down Expand Up @@ -267,6 +266,7 @@ func (g *generator) genAndCommitHelpers(scopes []string) error {
g.imports[pbinfo.ImportSpec{Path: "log/slog"}] = true
g.imports[pbinfo.ImportSpec{Path: "net/http"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/api/googleapi"}] = true
g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/internallog"}] = true

p("func executeHTTPRequest(ctx context.Context, client *http.Client, req *http.Request, logger *slog.Logger, body []byte, rpc string) ([]byte, error) {")
p(` logger.DebugContext(ctx, "api request", "serviceName", serviceName, "rpcName", rpc, "request", internallog.HTTPRequest(req, body))`)
Expand Down Expand Up @@ -303,6 +303,7 @@ func (g *generator) genAndCommitHelpers(scopes []string) error {
}

if containsTransport(g.opts.transports, grpc) {
g.imports[pbinfo.ImportSpec{Path: "log/slog"}] = true
g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/internallog/grpclog"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc"}] = true
g.imports[pbinfo.ImportSpec{Path: "google.golang.org/protobuf/proto"}] = true
Expand Down

0 comments on commit 28196b0

Please sign in to comment.