Skip to content

Commit 148b167

Browse files
authored
fix: Delete invocation_id log field when streaming plugins logs (#366)
#### Summary Part of cloudquery/cloudquery#18443. Both CLI and plugins add the invocation ID field to the log. When the CLI invokes plugins it streams their logs into its own log so it all shows up in the same file. This happens here https://github.com/cloudquery/plugin-pb-go/blob/28fae3fab7dd225622fdea542ae67ee5649e8b8c/managedplugin/plugin.go#L480 We parse the log line as JSON, then log it with the CLI logger. `zerolog` doesn't remove duplicate fields (see https://github.com/rs/zerolog?tab=readme-ov-file#field-duplication ) we need to remove the duplicate ourselves (similar to `level`). Please note that the duplicates only show up when passing `--log-format json` as it seems the text format does remove duplicates (`zerolog` saves the message to be printed internally in JSON format so probably the conversion to text removes the duplicate somewhere, didn't both to check). CLI PR in cloudquery/cloudquery#18641 ---
1 parent 28fae3f commit 148b167

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

managedplugin/logging.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import "github.com/rs/zerolog"
44

55
func (c *Client) jsonToLog(l zerolog.Logger, msg map[string]any) {
66
level := msg["level"]
7+
// Delete fields already added by the CLI so that they don't appear twice in the logs when we stream it from plugins
78
delete(msg, "level")
9+
delete(msg, "invocation_id")
810
switch level {
911
case "trace":
1012
l.Trace().Fields(msg).Msg("")

0 commit comments

Comments
 (0)