From 4bca41a700b1a2bc261995353800dd26da815ceb Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 11 May 2026 10:11:16 -0500 Subject: [PATCH] fix(insights): add info logging to AI network insight worker Info-level logs for: org count at start, observation count per org, successful persistence, and dedup. Makes the worker observable without needing database access. --- lib/towerops/workers/ai_network_insight_worker.ex | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/towerops/workers/ai_network_insight_worker.ex b/lib/towerops/workers/ai_network_insight_worker.ex index fb5915a7..16d213aa 100644 --- a/lib/towerops/workers/ai_network_insight_worker.ex +++ b/lib/towerops/workers/ai_network_insight_worker.ex @@ -37,6 +37,8 @@ defmodule Towerops.Workers.AiNetworkInsightWorker do |> select([o], o.id) |> Repo.all() + Logger.info("AI network insight: processing #{length(org_ids)} orgs") + Enum.each(org_ids, &process_organization/1) :ok @@ -50,6 +52,10 @@ defmodule Towerops.Workers.AiNetworkInsightWorker do {:ok, %{content: content, model: model} = response} -> {:ok, observations} = NetworkInsightPrompt.parse(content) + Logger.info( + "AI network insight: org #{organization_id} got #{length(observations)} observations, #{Map.get(response, :completion_tokens) || 0} tokens" + ) + Enum.each(observations, &persist_observation(organization_id, &1, model)) record_usage(organization_id, response, model) @@ -89,7 +95,11 @@ defmodule Towerops.Workers.AiNetworkInsightWorker do } case Insights.insert_insight_if_new(attrs) do - {:ok, _} -> + {:ok, :duplicate} -> + :ok + + {:ok, insight} -> + Logger.info("AI network insight: persisted #{insight.id} — \"#{obs.title}\"") :ok {:error, changeset} ->