diff --git a/api/client.gen.go b/api/client.gen.go index 9aa3213..35a7464 100644 --- a/api/client.gen.go +++ b/api/client.gen.go @@ -245,6 +245,13 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { } log.Printf("\n%s\n", string(dump)) } + if resp.Header.Get("trace-sampled") == "true" { + tracePrefix := "trace-id: " + if prefix, found := os.LookupEnv("INFLUX_CLI_TRACE_PRINT_PREFIX"); found { + tracePrefix = prefix + } + fmt.Fprintf(os.Stderr, "%s%s\n", tracePrefix, resp.Header.Get("trace-id")) + } return resp, err } diff --git a/api/configuration_default.go b/api/configuration_default.go index 65462f4..9c0beb1 100644 --- a/api/configuration_default.go +++ b/api/configuration_default.go @@ -37,6 +37,7 @@ func NewAPIConfig(params ConfigParams) *Configuration { // use codegen'd logic to set the header on every HTTP request. Early versions of the CLI // used that technique, and we found it to be error-prone and easy to forget during testing. apiConfig.DefaultHeader["Zap-Trace-Span"] = *params.TraceId + apiConfig.DefaultHeader["influx-debug-id"] = *params.TraceId } apiConfig.Debug = params.Debug diff --git a/api/templates/client.mustache b/api/templates/client.mustache index 255e6f6..73f22ec 100644 --- a/api/templates/client.mustache +++ b/api/templates/client.mustache @@ -191,6 +191,13 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { } log.Printf("\n%s\n", string(dump)) } + if resp.Header.Get("trace-sampled") == "true" { + tracePrefix := "trace-id: " + if prefix, found := os.LookupEnv("INFLUX_CLI_TRACE_PRINT_PREFIX"); found { + tracePrefix = prefix + } + fmt.Fprintf(os.Stderr, "%s%s\n", tracePrefix, resp.Header.Get("trace-id")) + } return resp, err } @@ -354,7 +361,7 @@ func (c *APIClient) prepareRequest( reader = strings.NewReader(body.String()) } - // Define default values for region and service to maintain backward compatibility + // Define default values for region and service to maintain backward compatibility region := auth.Region if region == "" { region = "eu-west-2"