From 0b19aafa6073eab6a4388528a37ee9f662ae5782 Mon Sep 17 00:00:00 2001 From: Kanishk Date: Mon, 4 May 2026 16:10:27 +0530 Subject: [PATCH 1/2] RTECO-1017 - enrich User-Agent with agent/CI context and reuse Cursor trace ID for API calls --- go.mod | 2 +- go.sum | 6 ++---- main.go | 39 ++++++++++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 78e4089af..948c93902 100644 --- a/go.mod +++ b/go.mod @@ -252,7 +252,7 @@ require ( // replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.13.1-0.20260428071432-1e9d9a1991ad -// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/agrasth/jfrog-cli-core/v2 v2.0.0-20260428093456-2bc01db3b153 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260504103316-aaa4fda381f7 //replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.54.2-0.20251007084958-5eeaa42c31a6 diff --git a/go.sum b/go.sum index a227a9f55..1d04eec4d 100644 --- a/go.sum +++ b/go.sum @@ -420,10 +420,8 @@ github.com/jfrog/jfrog-cli-application v1.0.2-0.20260405065840-c930d515ef34 h1:q github.com/jfrog/jfrog-cli-application v1.0.2-0.20260405065840-c930d515ef34/go.mod h1:xum2HquWO5uExa/A7MQs3TgJJVEeoqTR+6Z4mfBr1Xw= github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260429074430-a5871f2898b5 h1:+52DDmdSZFP1dxgeu0pkB1sQuoHa0PWbW7HVdFOqK3A= github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260429074430-a5871f2898b5/go.mod h1:BV+aCTQsaZeFec2WjgmQjqlxecju4CkkM9NqfiFyjo0= -github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260430091103-6242ecf15d29 h1:J5+08rOpv/avgt53jNFZ+j5gU8mllcj7Dcfja5Ewodw= -github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260430091103-6242ecf15d29/go.mod h1:bjAkVD8c2W+jg4whqy10bSXDC/c+Se8/ll/GPp5F/+0= -github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260430125911-ad12ac6f1316 h1:xAl5D+SjLeRH1gCsSHFPpXJeQQBv2HDGqDTDkFOKJ2s= -github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260430125911-ad12ac6f1316/go.mod h1:bjAkVD8c2W+jg4whqy10bSXDC/c+Se8/ll/GPp5F/+0= +github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260504103316-aaa4fda381f7 h1:ZQJGuIkQyZUNpyb7H0PCq88Rw/1KCXUjOruuY6kPhWo= +github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260504103316-aaa4fda381f7/go.mod h1:bjAkVD8c2W+jg4whqy10bSXDC/c+Se8/ll/GPp5F/+0= github.com/jfrog/jfrog-cli-evidence v0.9.2 h1:huiBzQSI9z3OF3l2RphthdXl1aH9zBsvAt+zLsApORI= github.com/jfrog/jfrog-cli-evidence v0.9.2/go.mod h1:R9faPfyQESBmKrdZCmHvlpmYSHmffswjNnFeT3RMq8I= github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20260430094150-ce7d9b371c6f h1:M1cesbKYSznwPA76dNctjCELxGx34TSSjwoYnJm9/6Y= diff --git a/main.go b/main.go index 2aa107b0c..2816e094e 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( appTrustCLI "github.com/jfrog/jfrog-cli-application/cli" artifactoryCLI "github.com/jfrog/jfrog-cli-artifactory/cli" corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common" + corecommands "github.com/jfrog/jfrog-cli-core/v2/common/commands" "github.com/jfrog/jfrog-cli-core/v2/plugins/components" coreconfig "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" @@ -89,8 +90,8 @@ func execMain() error { return err } - // Set JFrog CLI's user-agent on the jfrog-client-go. - clientutils.SetUserAgent(coreutils.GetCliUserAgent()) + // Set JFrog CLI's user-agent on the jfrog-client-go, enriched with invoker info. + clientutils.SetUserAgent(buildEnrichedUserAgent(corecommands.DetectExecutionContext())) app := cli.NewApp() app.Name = jfrogAppName @@ -165,19 +166,43 @@ func displaySurveyLinkIfNeeded() { fmt.Fprintln(os.Stderr, "\n💬 Help us improve JFrog CLI! \033]8;;https://www.surveymonkey.com/r/JFCLICLI\033\\https://www.surveymonkey.com/r/JFCLICLI\033]8;;\033\\") } -// This command generates and sets an Uber Trace ID token which will be attached as a header to every request. +// This command sets an Uber Trace ID token which will be attached as a header to every request. +// If the parent agent (e.g. Cursor) propagates a trace ID via env, reuse it so server-side logs +// correlate end-to-end with the agent's trace. Otherwise generate a fresh one. // This allows users to easily identify which logs on the server side are related to the command executed by the CLI. func setUberTraceIdToken() error { - var err error - traceID, err = generateTraceIdToken() - if err != nil { - return err + if propagated := corecommands.DetectExecutionContext().TraceID; propagated != "" { + traceID = propagated + } else { + generated, err := generateTraceIdToken() + if err != nil { + return err + } + traceID = generated } httpclient.SetUberTraceIdToken(traceID) clientlog.Debug(traceIdLogMsg, traceID) return nil } +// buildEnrichedUserAgent appends invoker context (agent / ci) to the base CLI user-agent. +// Examples: "jfrog-cli-go/2.x (claude)", "jfrog-cli-go/2.x (ci=github_actions)", +// "jfrog-cli-go/2.x (cursor; ci=github_actions)". +func buildEnrichedUserAgent(ec corecommands.ExecutionContext) string { + base := coreutils.GetCliUserAgent() + parts := []string{} + if ec.Agent != "" { + parts = append(parts, ec.Agent) + } + if ec.CISystem != "" { + parts = append(parts, "ci="+ec.CISystem) + } + if len(parts) == 0 { + return base + } + return fmt.Sprintf("%s (%s)", base, strings.Join(parts, "; ")) +} + // Generates a 16 chars hexadecimal string to be used as a Trace ID token. func generateTraceIdToken() (string, error) { // Generate 8 random bytes. From 34604fb21e0e1f699f04be47b5f165a9bec234c7 Mon Sep 17 00:00:00 2001 From: Kanishk Date: Thu, 7 May 2026 17:06:28 +0530 Subject: [PATCH 2/2] Update go.mod and go.sum for jfrog-cli-core to v2.60.1-0.20260507113422-89ba093adf6b and refactor User-Agent setting in main.go --- go.mod | 2 +- go.sum | 4 ++-- main.go | 20 +------------------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 948c93902..65137689e 100644 --- a/go.mod +++ b/go.mod @@ -252,7 +252,7 @@ require ( // replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.13.1-0.20260428071432-1e9d9a1991ad -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260504103316-aaa4fda381f7 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260507113422-89ba093adf6b //replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.54.2-0.20251007084958-5eeaa42c31a6 diff --git a/go.sum b/go.sum index 1d04eec4d..419892b2b 100644 --- a/go.sum +++ b/go.sum @@ -420,8 +420,8 @@ github.com/jfrog/jfrog-cli-application v1.0.2-0.20260405065840-c930d515ef34 h1:q github.com/jfrog/jfrog-cli-application v1.0.2-0.20260405065840-c930d515ef34/go.mod h1:xum2HquWO5uExa/A7MQs3TgJJVEeoqTR+6Z4mfBr1Xw= github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260429074430-a5871f2898b5 h1:+52DDmdSZFP1dxgeu0pkB1sQuoHa0PWbW7HVdFOqK3A= github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260429074430-a5871f2898b5/go.mod h1:BV+aCTQsaZeFec2WjgmQjqlxecju4CkkM9NqfiFyjo0= -github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260504103316-aaa4fda381f7 h1:ZQJGuIkQyZUNpyb7H0PCq88Rw/1KCXUjOruuY6kPhWo= -github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260504103316-aaa4fda381f7/go.mod h1:bjAkVD8c2W+jg4whqy10bSXDC/c+Se8/ll/GPp5F/+0= +github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260507113422-89ba093adf6b h1:TG/3jjqb3M+1CHf4Qn0y93yOKdEPoxSv/ZyBE4MKjxM= +github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260507113422-89ba093adf6b/go.mod h1:bjAkVD8c2W+jg4whqy10bSXDC/c+Se8/ll/GPp5F/+0= github.com/jfrog/jfrog-cli-evidence v0.9.2 h1:huiBzQSI9z3OF3l2RphthdXl1aH9zBsvAt+zLsApORI= github.com/jfrog/jfrog-cli-evidence v0.9.2/go.mod h1:R9faPfyQESBmKrdZCmHvlpmYSHmffswjNnFeT3RMq8I= github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20260430094150-ce7d9b371c6f h1:M1cesbKYSznwPA76dNctjCELxGx34TSSjwoYnJm9/6Y= diff --git a/main.go b/main.go index 2816e094e..a56d3bf22 100644 --- a/main.go +++ b/main.go @@ -91,7 +91,7 @@ func execMain() error { } // Set JFrog CLI's user-agent on the jfrog-client-go, enriched with invoker info. - clientutils.SetUserAgent(buildEnrichedUserAgent(corecommands.DetectExecutionContext())) + clientutils.SetUserAgent(corecommands.EnrichUserAgent(coreutils.GetCliUserAgent())) app := cli.NewApp() app.Name = jfrogAppName @@ -185,24 +185,6 @@ func setUberTraceIdToken() error { return nil } -// buildEnrichedUserAgent appends invoker context (agent / ci) to the base CLI user-agent. -// Examples: "jfrog-cli-go/2.x (claude)", "jfrog-cli-go/2.x (ci=github_actions)", -// "jfrog-cli-go/2.x (cursor; ci=github_actions)". -func buildEnrichedUserAgent(ec corecommands.ExecutionContext) string { - base := coreutils.GetCliUserAgent() - parts := []string{} - if ec.Agent != "" { - parts = append(parts, ec.Agent) - } - if ec.CISystem != "" { - parts = append(parts, "ci="+ec.CISystem) - } - if len(parts) == 0 { - return base - } - return fmt.Sprintf("%s (%s)", base, strings.Join(parts, "; ")) -} - // Generates a 16 chars hexadecimal string to be used as a Trace ID token. func generateTraceIdToken() (string, error) { // Generate 8 random bytes.