Skip to content

Commit 7154f9e

Browse files
authored
feat: Add invocation-id to all log statements (#17087)
#### Summary This change will retain the same uuid for all source/destinations in the same sync rather than a unique sync id per source example: ``` {"level":"info","module":"cli","log-id":"7871e9f8-c747-4f44-98e0-a32d216e503c","args":["config.yml"],"time":"2024-03-06T23:47:49Z","message":"Loading spec(s)"} ```
1 parent b143341 commit 7154f9e

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

cli/cmd/logging.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ func initLogging(noLogFile bool, logLevel *enum.Enum, logFormat *enum.Enum, logC
4848
}
4949
}
5050
mw := io.MultiWriter(writers...)
51-
log.Logger = zerolog.New(mw).Level(zerologLevel).With().Str("module", "cli").Timestamp().Logger()
51+
log.Logger = zerolog.New(mw).Level(zerologLevel).With().Str("module", "cli").Str("invocation-id", invocationUUID.String()).Timestamp().Logger()
5252
return logFile, nil
5353
}

cli/cmd/root.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"time"
77

8+
"github.com/google/uuid"
89
"github.com/rs/zerolog"
910

1011
"github.com/cloudquery/cloudquery/cli/internal/enum"
@@ -29,6 +30,7 @@ Find more information at:
2930
disableSentry = false
3031
analyticsClient *AnalyticsClient
3132
logFile *os.File
33+
invocationUUID uuid.UUID
3234
)
3335

3436
func NewCmdRoot() *cobra.Command {
@@ -67,6 +69,12 @@ func NewCmdRoot() *cobra.Command {
6769
// PersistentPreRunE runs after argument parsing, so errors during parsing will result in printing the help
6870
cmd.SilenceUsage = true
6971
var err error
72+
73+
invocationUUID, err = uuid.NewRandom()
74+
if err != nil {
75+
return fmt.Errorf("failed to generate invocation uuid: %w", err)
76+
}
77+
7078
if logFile, err = initLogging(noLogFile, logLevel, logFormat, logConsole, logFileName); err != nil {
7179
return err
7280
}

cli/cmd/sync.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"slices"
88
"strings"
99

10-
"github.com/google/uuid"
11-
1210
apiAuth "github.com/cloudquery/cloudquery-api-go/auth"
1311
"github.com/cloudquery/cloudquery/cli/internal/auth"
1412
"github.com/cloudquery/cloudquery/cli/internal/specs/v0"
@@ -105,10 +103,6 @@ func sync(cmd *cobra.Command, args []string) error {
105103
return fmt.Errorf("failed to load spec(s) from %s. Error: %w", strings.Join(args, ", "), err)
106104
}
107105

108-
invocationUUID, err := uuid.NewRandom()
109-
if err != nil {
110-
return fmt.Errorf("failed to generate invocation uuid: %w", err)
111-
}
112106
sources := specReader.Sources
113107
destinations := specReader.Destinations
114108
sourcePluginClients := make(managedplugin.Clients, 0)

0 commit comments

Comments
 (0)