From 547b5d2c87edf8c3f2b167429b2d155bf151cd18 Mon Sep 17 00:00:00 2001 From: Jeff Schnitter Date: Thu, 12 Nov 2026 09:35:21 -0800 Subject: [PATCH 1/2] feat: embed solution name in CLI user-agent for Datadog telemetry Include the solution name in the User-Agent header when running cortex solutions install (e.g. cortexapps-cli/1.52.0 (solutions/workday)), so solution usage is visible in Datadog by solution and by tenant. Also emit a lightweight API call at the start of install so setup-script-only solutions (which make no backup import requests) always produce a log entry. Co-Authored-By: Claude Sonnet 4.6 --- cortexapps_cli/commands/solutions.py | 58 ++++++++++++++++++++++++++-- cortexapps_cli/cortex_client.py | 6 ++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/cortexapps_cli/commands/solutions.py b/cortexapps_cli/commands/solutions.py index 8a9ac2b1..544dcef5 100644 --- a/cortexapps_cli/commands/solutions.py +++ b/cortexapps_cli/commands/solutions.py @@ -272,7 +272,7 @@ def _get_ui_url(ctx: typer.Context) -> str: return api_url.replace("://api.", "://app.") -def _build_client(ctx: typer.Context) -> CortexClient: +def _build_client(ctx: typer.Context, solution: str | None = None) -> CortexClient: """Build a CortexClient from auth params stored by global_callback.""" params = ctx.obj.get("_auth_params", {}) api_key = params.get("api_key") @@ -316,7 +316,8 @@ def _build_client(ctx: typer.Context) -> CortexClient: url = url.strip("\"' /") numeric_level = getattr(logging, log_level_str.upper(), logging.WARNING) - return CortexClient(api_key, tenant, numeric_level, url, rate_limit) + command = f"solutions/{solution}" if solution else "solutions" + return CortexClient(api_key, tenant, numeric_level, url, rate_limit, command=command) def _read_catalog_tag(content: str) -> str | None: @@ -763,7 +764,13 @@ def install( typer.echo(f"Error: Solution '{solution}' not found. Available: {avail}") raise typer.Exit(1) - ctx.obj["client"] = _build_client(ctx) + ctx.obj["client"] = _build_client(ctx, solution=solution) + # Emit one API call so this install is always recorded in Datadog, even for + # setup-script-only solutions that make no backup import requests. + try: + ctx.obj["client"].get("api/v1/catalog/definitions", params={"pageSize": 1}) + except Exception: + pass import cortexapps_cli.commands.backup as backup @@ -859,6 +866,51 @@ def post_install( ctx.obj["client"] = _build_client(ctx) _run_post_install_script(solution, solutions_dir=solutions_dir, ctx=ctx, no_prompt=no_prompt) + if not no_prompt: + readme = _get_readme(solution, solutions_dir) + if readme: + entity_tags: set[str] = set() + ui_url = _get_ui_url(ctx) + resources: dict[str, list[str]] = {} + try: + root = files("cortexapps_cli.solutions") + if solutions_dir: + resources = _collect_solution_resources(Path(solutions_dir) / solution) + else: + with as_file(root / solution) as sp: + resources = _collect_solution_resources(sp) + entity_tags = set(resources.get("catalog", [])) + if solutions_dir: + entity_tags |= _extract_tf_entity_tags(Path(solutions_dir) / solution) + else: + with as_file(root / solution) as sp: + entity_tags |= _extract_tf_entity_tags(sp) + except Exception: + pass + # Build a synthetic import report from the solution's known resources + kind_labels = { + "entity-types": "Entity type", + "entity-relationship-types": "Entity relationship type", + "catalog": "Entity", + "scorecards": "Scorecard", + "workflows": "Workflow", + "plugins": "Plugin", + "catalogs": "Catalog", + } + report_lines: list[str] = [] + for kind, tags in resources.items(): + label = kind_labels.get(kind, kind) + for tag in tags: + report_lines.append(f" {label}: {tag}") + import_report = "\n".join(report_lines) if report_lines else "" + _post_install_menu( + readme, + import_report=import_report, + entity_tags=entity_tags, + ui_url=ui_url, + solution_tag=solution, + ) + @app.command() def uninstall( diff --git a/cortexapps_cli/cortex_client.py b/cortexapps_cli/cortex_client.py index 42b5e18c..ce26a2b7 100644 --- a/cortexapps_cli/cortex_client.py +++ b/cortexapps_cli/cortex_client.py @@ -83,7 +83,7 @@ def acquire(self, tokens=1): class CortexClient: - def __init__(self, api_key, tenant, numeric_level, base_url='https://api.getcortexapp.com', rate_limit=None): + def __init__(self, api_key, tenant, numeric_level, base_url='https://api.getcortexapp.com', rate_limit=None, command=None): self.api_key = api_key self.tenant = tenant self.base_url = base_url @@ -93,6 +93,8 @@ def __init__(self, api_key, tenant, numeric_level, base_url='https://api.getcort except importlib.metadata.PackageNotFoundError: self.version = 'unknown' + self.command = command + logging.basicConfig(level=numeric_level) self.logger = logging.getLogger(__name__) @@ -132,7 +134,7 @@ def request(self, method, endpoint, params={}, headers={}, data=None, raw_body=F req_headers = { 'Authorization': f'Bearer {self.api_key}', 'Content-Type': content_type, - 'User-Agent': f'cortexapps-cli/{self.version}', + 'User-Agent': f'cortexapps-cli/{self.version} ({self.command})' if self.command else f'cortexapps-cli/{self.version}', **headers } url = '/'.join([self.base_url.rstrip('/'), endpoint.lstrip('/')]) From 93f2010fede336172d69f74adc9240ba4b869e60 Mon Sep 17 00:00:00 2001 From: Jeff Schnitter Date: Thu, 12 Nov 2026 10:15:31 -0800 Subject: [PATCH 2/2] fix: mock _post_install_menu in post-install no-setup test _post_install_menu calls Prompt.ask() which hangs in non-TTY test environments. The test is verifying the no-setup-script path, not the interactive menu, so mocking it is correct. Co-Authored-By: Claude Sonnet 4.6 --- tests/test_solutions_postinstall.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_solutions_postinstall.py b/tests/test_solutions_postinstall.py index 8c9bc11a..262cf052 100644 --- a/tests/test_solutions_postinstall.py +++ b/tests/test_solutions_postinstall.py @@ -7,7 +7,8 @@ def test_post_install_no_setup_for_ai_agents(): - result = runner.invoke(app, ["solutions", "post-install", "-s", "ai-agents"]) + with patch("cortexapps_cli.commands.solutions._post_install_menu"): + result = runner.invoke(app, ["solutions", "post-install", "-s", "ai-agents"]) assert result.exit_code == 0 assert "No post-install setup available" in result.output