-
Notifications
You must be signed in to change notification settings - Fork 47
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
refactor: switch to subsystem loggers for HTTP logging #739
Conversation
// This is the initial env var for HTTP logging for backwards | ||
// compatibility. We could now introduce service-specific | ||
// variables, if desired, for more granular control of logging | ||
HTTPLoggingEnvVar = "TF_LOG" |
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.
Using TF_LOG
to control the log level for all of the new subsystem loggers replicates prior behavior but may not be desirable. Now that we have these loggers in place, we could add support for one or more of TF_LOG_PROVIDER_EQUINIX
(to specify log level for the whole provider) or TF_LOG_EQUINIX_<service>
(to allow more granular configuration of provider logging).
The log format for HTTP logs is different with the new loggers. Previously we would see logs like this:
But the new loggers produce messages like this:
|
Another alternative would be to remove the HTTP logging transport entirely and update the Go SDK(s) to enable debug mode in the presence of specific environment variables instead. |
// Subsystems for API client logging | ||
packetClientSubsystem = "Equinix Metal (packngo)" | ||
equinixClientSubsystem = "Equinix" | ||
metalClientSubsystem = "Equinix Metal (metal-go)" |
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.
Looks like we missed a spot in the SDK conversion. This could either be (equinix-sdk-go)
to reflect the previous convention of tagging with the SDK name or it could be (metalv1)
to align with the fabricClientSubsystem
format, in which case perhaps we could remove packetClientSubsystem
, since the logs would already include User-Agent to see which requests came from which SDK.
metalClientSubsystem = "Equinix Metal (metal-go)" | |
metalClientSubsystem = "Equinix Metal (equinix-sdk-go)" |
bd289d0
to
a523401
Compare
|
||
func (t *HTTPLoggingTransport) RoundTrip(r *http.Request) (*http.Response, error) { | ||
ctx := tflog.NewSubsystem(r.Context(), t.subsystem, tflog.WithLevel(t.level)) | ||
ctx = tflog.SubsystemMaskFieldValuesWithFieldKeys(ctx, t.subsystem, t.sensitiveFields...) |
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.
The new subsystem loggers add support for masking sensitive values, which is nice.
a523401
to
4536a17
Compare
This addresses a linting issue that was bypassed in #736 to constrain the scope of that PR. The logging transport we were previously using for HTTP clients is deprecated, but the new Terraform logging plugin is more context-aware and requires--or at least enables--specifying separate subsystems for each provider component that will write logs.
This adds a new
HTTPLoggingTransport
type that encapsulates the logic of creating a subsystem HTTP logging transport, ensuring the necessary subsystem exists in any relevant HTTP request context, and masking any sensitive values in the request.The
Config
type is updated to create a separateHTTPLoggingTransport
for each API client. For now, the log level for all of the new transports is wired up to theTF_LOG
environment variable. This matches the previous behavior of the deprecated HTTP logging transport.