Skip to content

Lack of Feedback about Unpaired Structured Key-Values #31

@bflad

Description

@bflad

terraform-plugin-log version

v0.2.1

Relevant provider source code

tflog.Trace(ctx, "message with %d string format parameter", 1)

Plus other logging functions in tflog and tfsdklog. Also affects With() functions.

Expected Behavior

The potentially expected behavior here is that the logging functions such as Debug and friends act like f suffix string formatting functions since they accept a final ...interface{} variadic argument. The package was written to encourage structured logging with key-value pairs instead. Since ...interface{} does not enforce the key-value pair intention, the expected behavior here is then that the coding issue should be caught at compile-time or other feedback options are provided (e.g. static analysis tooling to report unpaired key-values issues).

Actual Behavior

The logger will still log the message, but the raw formatting parameter shows up in the message and the unpaired key should show in the EXTRA_VALUE_AT_END field.

Proposal

We should consider switching the variadic parameter to ...map[string]interface{} to enforce the key-value pairing, while still allowing simple logging messages. In the case of multiple maps, overwrite any previously defined keys.

Another, less preferable option, would be to offer a go/analysis based static analysis package and installable command, so downstream implementations can catch this coding issue (e.g. during CI).

A non-preferable option would be to leave the existing functions and offer f suffix functions, e.g. Debugf(), that do act similar to other formatter functions. This goes against the package's encouragement of structured logging.

References

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions