Add trace id to user agent to correlate API calls for the same command execution

This commit is contained in:
Shreyas Goenka 2024-10-04 14:03:32 +02:00
parent a8cff48c0b
commit c92f7bdf39
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
1 changed files with 6 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"strings"
"github.com/databricks/databricks-sdk-go/useragent"
"github.com/google/uuid"
"github.com/spf13/cobra"
)
@ -33,5 +34,9 @@ func commandString(cmd *cobra.Command) string {
}
func withCommandInUserAgent(ctx context.Context, cmd *cobra.Command) context.Context {
return useragent.InContext(ctx, "cmd", commandString(cmd))
// We add a uuid to the command context to trace multiple API requests made
// by the same command invocation.
newCtx := useragent.InContext(ctx, "cmd-trace-id", uuid.New().String())
return useragent.InContext(newCtx, "cmd", commandString(cmd))
}