-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add trace for executables #744
Changes from 5 commits
56f56dd
15a1efa
03565ec
0220eb3
e8fe38a
32fcdaa
0e8c8d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,9 @@ package cmd | |||||
import ( | ||||||
"context" | ||||||
|
||||||
"github.com/notaryproject/notation-go/log" | ||||||
"github.com/notaryproject/notation/internal/trace" | ||||||
credentialstrace "github.com/oras-project/oras-credentials-go/trace" | ||||||
"github.com/sirupsen/logrus" | ||||||
"github.com/spf13/cobra" | ||||||
"github.com/spf13/pflag" | ||||||
|
@@ -44,9 +46,27 @@ func (opts *LoggingFlagOpts) ApplyFlags(fs *pflag.FlagSet) { | |||||
// SetLoggerLevel sets up the logger based on common options. | ||||||
func (opts *LoggingFlagOpts) SetLoggerLevel(ctx context.Context) context.Context { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A question: Do we need to rename this function given that it now does more than setting logger level? 🤔 @JeyJeyGao There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed the function to |
||||||
if opts.Debug { | ||||||
return trace.WithLoggerLevel(ctx, logrus.DebugLevel) | ||||||
ctx = trace.WithLoggerLevel(ctx, logrus.DebugLevel) | ||||||
} else if opts.Verbose { | ||||||
return trace.WithLoggerLevel(ctx, logrus.InfoLevel) | ||||||
ctx = trace.WithLoggerLevel(ctx, logrus.InfoLevel) | ||||||
} | ||||||
return withExecutableTrace(ctx) | ||||||
JeyJeyGao marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
// withExecutableTrace adds tracing for credential helper executables. | ||||||
func withExecutableTrace(ctx context.Context) context.Context { | ||||||
logger := log.GetLogger(ctx) | ||||||
JeyJeyGao marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
ctx = credentialstrace.WithExecutableTrace(ctx, &credentialstrace.ExecutableTrace{ | ||||||
ExecuteStart: func(executableName, action string) { | ||||||
logger.Debugf("started executing credential helper program %s with action %s", executableName, action) | ||||||
}, | ||||||
ExecuteDone: func(executableName, action string, err error) { | ||||||
JeyJeyGao marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if err != nil { | ||||||
logger.Errorf("finished executing credential helper program %s with action %s and got error %w", executableName, action, err) | ||||||
} else { | ||||||
logger.Debugf("finished executing credential helper program %s with action %s", executableName, action) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed accordingly |
||||||
} | ||||||
}, | ||||||
}) | ||||||
return ctx | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran
go mod tidy
.