-
Notifications
You must be signed in to change notification settings - Fork 16
Enable API consumer tracking #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
161bb5e
b417cec
30c00d3
3a4afa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,13 @@ export EDITOR=nano | |
|
|
||
| # Force setup wizard to run even if already completed | ||
| export DATAROBOT_CLI_FORCE_INTERACTIVE=true | ||
|
|
||
| # API consumer tracking (default: true) | ||
| # Set to false to disable the X-DataRobot-Api-Consumer-Trace header on API requests. | ||
| # Matches the Python SDK's DATAROBOT_API_CONSUMER_TRACKING_ENABLED behavior. | ||
| # When enabled, the header value identifies the command being run using dot-notation: | ||
| # datarobot.cli.<command>.<subcommand> (e.g. datarobot.cli.templates.setup) | ||
| export DATAROBOT_API_CONSUMER_TRACKING_ENABLED=false | ||
|
Comment on lines
+138
to
+144
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we add in the rest of telemetry we should probably explain this further. |
||
| ``` | ||
|
|
||
| ### Advanced flags | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,46 @@ func GetUserAgentHeader() string { | |
| return version.GetAppNameVersionText() | ||
| } | ||
|
|
||
| // apiConsumerTrace holds the dot-notation command path set at startup. | ||
| // Example: "datarobot.cli.templates.setup" | ||
| var apiConsumerTrace string | ||
|
|
||
| // SetAPIConsumerTrace stores the dot-notation trace value for the running command. | ||
| // Called once during PersistentPreRunE with the result of CommandPathToTrace. | ||
| func SetAPIConsumerTrace(trace string) { | ||
| apiConsumerTrace = trace | ||
| } | ||
|
|
||
| // GetAPIConsumerTrace returns the dot-notation trace value for the running command. | ||
| // Falls back to "datarobot.cli" if SetAPIConsumerTrace has not been called. | ||
| func GetAPIConsumerTrace() string { | ||
| if apiConsumerTrace == "" { | ||
| return "datarobot.cli" | ||
| } | ||
|
|
||
| return apiConsumerTrace | ||
| } | ||
|
|
||
| // CommandPathToTrace converts a cobra command path (e.g. "dr templates setup") | ||
| // to the canonical dot-notation trace format (e.g. "datarobot.cli.templates.setup"). | ||
| func CommandPathToTrace(commandPath string) string { | ||
| parts := strings.Fields(commandPath) | ||
| if len(parts) == 0 { | ||
| return "datarobot.cli" | ||
| } | ||
|
|
||
| parts[0] = "datarobot.cli" | ||
|
|
||
| return strings.Join(parts, ".") | ||
| } | ||
|
Comment on lines
+92
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking a few things here -- Cobra doesn't appear to allow dots or periods in Also, I wonder how this works with command aliases, like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, not sure what to say here ... need to check that.. let's do that on next steps |
||
|
|
||
| // IsAPIConsumerTrackingEnabled returns true if the X-DataRobot-Api-Consumer-Trace | ||
| // header should be sent with API requests. Controlled by the | ||
| // DATAROBOT_API_CONSUMER_TRACKING_ENABLED environment variable (default: true). | ||
| func IsAPIConsumerTrackingEnabled() bool { | ||
| return viper.GetBool(APIConsumerTrackingEnabled) | ||
| } | ||
|
|
||
| func RedactedReqInfo(req *http.Request) string { | ||
| // Dump the request to a byte slice after cloning and removing Auth header | ||
| dumpReq := req.Clone(req.Context()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like that cmd.CommandPath() is a thing.