Skip to content

Commit 6bedae4

Browse files
NSHkrNSHkr
authored andcommitted
format
1 parent 1691c20 commit 6bedae4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3271
-2468
lines changed

lib/elixir_scope.ex

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ defmodule ElixirScope do
2020
@doc """
2121
Get the current status of all ElixirScope subsystems.
2222
"""
23-
@spec status() :: {:ok, %{
24-
config: map(),
25-
events: map(),
26-
telemetry: map()
27-
}} | {:error, Error.t()}
23+
@spec status() ::
24+
{:ok,
25+
%{
26+
config: map(),
27+
events: map(),
28+
telemetry: map()
29+
}}
30+
| {:error, Error.t()}
2831
def status do
2932
case Foundation.status() do
3033
{:ok, foundation_status} ->
3134
{:ok, foundation_status}
32-
{:error, _} = error -> error
35+
36+
{:error, _} = error ->
37+
error
3338
end
3439
end
3540

lib/elixir_scope/foundation.ex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ defmodule ElixirScope.Foundation do
5454
with {:ok, config_status} <- Config.status(),
5555
{:ok, events_status} <- Events.status(),
5656
{:ok, telemetry_status} <- Telemetry.status() do
57-
{:ok, %{
58-
config: config_status,
59-
events: events_status,
60-
telemetry: telemetry_status
61-
}}
57+
{:ok,
58+
%{
59+
config: config_status,
60+
events: events_status,
61+
telemetry: telemetry_status
62+
}}
6263
else
6364
{:error, _} = error -> error
6465
end
@@ -106,8 +107,10 @@ defmodule ElixirScope.Foundation do
106107
# Stop services in reverse order
107108
# Let the supervision tree handle the actual shutdown
108109
case Process.whereis(ElixirScope.Foundation.Supervisor) do
109-
nil -> :ok
110-
pid ->
110+
nil ->
111+
:ok
112+
113+
pid ->
111114
Supervisor.stop(pid, :normal)
112115
:ok
113116
end
@@ -140,6 +143,7 @@ defmodule ElixirScope.Foundation do
140143
elixir_version: System.version(),
141144
otp_release: System.otp_release()
142145
}
146+
143147
{:ok, health_info}
144148

145149
{:error, _} = error ->
@@ -150,7 +154,7 @@ defmodule ElixirScope.Foundation do
150154
## Private Functions
151155

152156
defp determine_overall_health(service_status) do
153-
all_running =
157+
all_running =
154158
service_status
155159
|> Map.values()
156160
|> Enum.all?(fn status -> Map.get(status, :status) == :running end)

lib/elixir_scope/foundation/application.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ defmodule ElixirScope.Foundation.Application do
1111
def start(_type, _args) do
1212
children = [
1313
# Core foundation services
14-
{ElixirScope.Foundation.Services.ConfigServer, name: ElixirScope.Foundation.Services.ConfigServer},
15-
{ElixirScope.Foundation.Services.EventStore, name: ElixirScope.Foundation.Services.EventStore},
16-
{ElixirScope.Foundation.Services.TelemetryService, name: ElixirScope.Foundation.Services.TelemetryService},
14+
{ElixirScope.Foundation.Services.ConfigServer,
15+
name: ElixirScope.Foundation.Services.ConfigServer},
16+
{ElixirScope.Foundation.Services.EventStore,
17+
name: ElixirScope.Foundation.Services.EventStore},
18+
{ElixirScope.Foundation.Services.TelemetryService,
19+
name: ElixirScope.Foundation.Services.TelemetryService},
1720

1821
# Task supervisor for dynamic tasks
1922
{Task.Supervisor, name: ElixirScope.Foundation.TaskSupervisor}

lib/elixir_scope/foundation/config.ex

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,19 @@ defmodule ElixirScope.Foundation.Config do
203203
if path in updatable_paths() do
204204
update(path, value)
205205
else
206-
{:error, Error.new(
207-
error_type: :config_update_forbidden,
208-
message: "Configuration path cannot be updated at runtime",
209-
context: %{path: path, allowed_paths: updatable_paths()},
210-
category: :config,
211-
subcategory: :validation,
212-
severity: :medium
213-
)}
206+
{:error,
207+
Error.new(
208+
error_type: :config_update_forbidden,
209+
message: "Configuration path cannot be updated at runtime",
210+
context: %{path: path, allowed_paths: updatable_paths()},
211+
category: :config,
212+
subcategory: :validation,
213+
severity: :medium
214+
)}
214215
end
215216
end
216217
end
217218

218-
219-
220-
221219
# defmodule ElixirScope.Foundation.Config do
222220
# @moduledoc """
223221
# Centralized configuration management for ElixirScope with robust error handling.
@@ -488,7 +486,6 @@ end
488486
# end
489487
# end
490488

491-
492489
# @impl GenServer
493490
# def handle_call(:get_config, _from, config) do
494491
# {:reply, config, config}
@@ -518,7 +515,6 @@ end
518515
# {:reply, value, config}
519516
# end
520517

521-
522518
# @impl GenServer
523519
# def handle_call({:update_config, path, value}, _from, config) do
524520
# context = ErrorContext.new(__MODULE__, :handle_update, metadata: %{path: path, value: value})

lib/elixir_scope/foundation/contracts/telemetry.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule ElixirScope.Foundation.Contracts.Telemetry do
2121
@doc """
2222
Measure execution time and emit results.
2323
"""
24-
@callback measure(event_name(), metadata(), (() -> result)) :: result when result: var
24+
@callback measure(event_name(), metadata(), (-> result)) :: result when result: var
2525

2626
@doc """
2727
Emit a counter metric.

lib/elixir_scope/foundation/events.ex

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ defmodule ElixirScope.Foundation.Events do
127127
iex> ElixirScope.Foundation.Events.function_entry(MyModule, :my_func, 2, [arg1, arg2])
128128
{:ok, %Event{event_type: :function_entry, ...}}
129129
"""
130-
@spec function_entry(module(), atom(), arity(), [term()], keyword()) :: {:ok, Event.t()} | {:error, Error.t()}
130+
@spec function_entry(module(), atom(), arity(), [term()], keyword()) ::
131+
{:ok, Event.t()} | {:error, Error.t()}
131132
def function_entry(module, function, arity, args, opts \\ []) do
132133
alias ElixirScope.Foundation.Logic.EventLogic
133134
EventLogic.create_function_entry(module, function, arity, args, opts)
@@ -141,10 +142,20 @@ defmodule ElixirScope.Foundation.Events do
141142
iex> ElixirScope.Foundation.Events.function_exit(MyModule, :my_func, 2, 123, :ok, 1000, :normal)
142143
{:ok, %Event{event_type: :function_exit, ...}}
143144
"""
144-
@spec function_exit(module(), atom(), arity(), pos_integer(), term(), non_neg_integer(), atom()) :: {:ok, Event.t()} | {:error, Error.t()}
145+
@spec function_exit(module(), atom(), arity(), pos_integer(), term(), non_neg_integer(), atom()) ::
146+
{:ok, Event.t()} | {:error, Error.t()}
145147
def function_exit(module, function, arity, call_id, result, duration_ns, exit_reason) do
146148
alias ElixirScope.Foundation.Logic.EventLogic
147-
EventLogic.create_function_exit(module, function, arity, call_id, result, duration_ns, exit_reason)
149+
150+
EventLogic.create_function_exit(
151+
module,
152+
function,
153+
arity,
154+
call_id,
155+
result,
156+
duration_ns,
157+
exit_reason
158+
)
148159
end
149160

150161
@doc """
@@ -155,7 +166,8 @@ defmodule ElixirScope.Foundation.Events do
155166
iex> ElixirScope.Foundation.Events.state_change(self(), :handle_call, old_state, new_state)
156167
{:ok, %Event{event_type: :state_change, ...}}
157168
"""
158-
@spec state_change(pid(), atom(), term(), term(), keyword()) :: {:ok, Event.t()} | {:error, Error.t()}
169+
@spec state_change(pid(), atom(), term(), term(), keyword()) ::
170+
{:ok, Event.t()} | {:error, Error.t()}
159171
def state_change(server_pid, callback, old_state, new_state, opts \\ []) do
160172
alias ElixirScope.Foundation.Logic.EventLogic
161173
EventLogic.create_state_change(server_pid, callback, old_state, new_state, opts)
@@ -288,6 +300,7 @@ defmodule ElixirScope.Foundation.Events do
288300
alias ElixirScope.Foundation.Logic.EventLogic
289301
chain = EventLogic.extract_correlation_chain(events, correlation_id)
290302
{:ok, chain}
303+
291304
{:error, _} = error ->
292305
error
293306
end
@@ -328,8 +341,6 @@ defmodule ElixirScope.Foundation.Events do
328341
end
329342
end
330343

331-
332-
333344
# defmodule ElixirScope.Foundation.Events do
334345
# @moduledoc """
335346
# Core event system for ElixirScope.

lib/elixir_scope/foundation/graceful_degradation.ex

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ defmodule ElixirScope.Foundation.Config.GracefulDegradation do
145145
cold: %{enable: false}
146146
},
147147
interface: %{query_timeout: 1000, max_results: 100, enable_streaming: false},
148-
dev: %{debug_mode: false, verbose_logging: false, performance_monitoring: false},
148+
dev: %{debug_mode: false, verbose_logging: false, performance_monitoring: false}
149149
}
150150
end
151151
end
@@ -184,11 +184,12 @@ defmodule ElixirScope.Foundation.Events.GracefulDegradation do
184184
IO.puts("📥 Input event: #{inspect(event_or_tuple, limit: :infinity)}")
185185

186186
# Handle both Event structs and {:ok, Event} tuples
187-
event = case event_or_tuple do
188-
{:ok, %ElixirScope.Foundation.Types.Event{} = e} -> e
189-
%ElixirScope.Foundation.Types.Event{} = e -> e
190-
other -> other
191-
end
187+
event =
188+
case event_or_tuple do
189+
{:ok, %ElixirScope.Foundation.Types.Event{} = e} -> e
190+
%ElixirScope.Foundation.Types.Event{} = e -> e
191+
other -> other
192+
end
192193

193194
result =
194195
case Events.serialize(event) do
@@ -334,6 +335,7 @@ defmodule ElixirScope.Foundation.Events.GracefulDegradation do
334335
defp reconstruct_event_from_map(map) do
335336
# Attempt to reconstruct event from map
336337
alias ElixirScope.Foundation.Types.Event
338+
337339
%Event{
338340
event_id: Map.get(map, "event_id", Utils.generate_id()),
339341
event_type: String.to_atom(Map.get(map, "event_type", "unknown")),
@@ -349,6 +351,7 @@ defmodule ElixirScope.Foundation.Events.GracefulDegradation do
349351

350352
defp create_error_event(binary) do
351353
alias ElixirScope.Foundation.Types.Event
354+
352355
%Event{
353356
event_id: Utils.generate_id(),
354357
event_type: :deserialization_error,

lib/elixir_scope/foundation/logic/config_logic.ex

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ defmodule ElixirScope.Foundation.Logic.ConfigLogic do
154154

155155
defp deep_merge(left, right) when is_map(left) and is_list(right) do
156156
right_map = Enum.into(right, %{})
157+
157158
Map.merge(left, right_map, fn _key, left_val, right_val ->
158159
deep_merge(left_val, right_val)
159160
end)
@@ -176,10 +177,13 @@ defmodule ElixirScope.Foundation.Logic.ConfigLogic do
176177
current_path = path ++ [key]
177178

178179
cond do
179-
old_val == new_val -> acc
180+
old_val == new_val ->
181+
acc
182+
180183
is_map(old_val) and is_map(new_val) ->
181184
nested_diff = create_diff(old_val, new_val, current_path)
182185
if map_size(nested_diff) > 0, do: Map.put(acc, key, nested_diff), else: acc
186+
183187
true ->
184188
Map.put(acc, key, %{old: old_val, new: new_val, path: current_path})
185189
end
@@ -195,14 +199,15 @@ defmodule ElixirScope.Foundation.Logic.ConfigLogic do
195199
end
196200

197201
defp create_error(error_type, message, context) do
198-
error = Error.new(
199-
error_type: error_type,
200-
message: message,
201-
context: context,
202-
category: :config,
203-
subcategory: :runtime,
204-
severity: :medium
205-
)
202+
error =
203+
Error.new(
204+
error_type: error_type,
205+
message: message,
206+
context: context,
207+
category: :config,
208+
subcategory: :runtime,
209+
severity: :medium
210+
)
206211

207212
{:error, error}
208213
end

lib/elixir_scope/foundation/logic/event_logic.ex

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ defmodule ElixirScope.Foundation.Logic.EventLogic do
1818
"""
1919
@spec create_event(atom(), term(), event_opts()) :: {:ok, Event.t()} | {:error, Error.t()}
2020
def create_event(event_type, data, opts \\ []) do
21-
event = Event.new(
22-
event_id: Keyword.get(opts, :event_id, Utils.generate_id()),
23-
event_type: event_type,
24-
timestamp: Keyword.get(opts, :timestamp, Utils.monotonic_timestamp()),
25-
wall_time: Keyword.get(opts, :wall_time, DateTime.utc_now()),
26-
node: Keyword.get(opts, :node, Node.self()),
27-
pid: Keyword.get(opts, :pid, self()),
28-
correlation_id: Keyword.get(opts, :correlation_id),
29-
parent_id: Keyword.get(opts, :parent_id),
30-
data: data
31-
)
21+
event =
22+
Event.new(
23+
event_id: Keyword.get(opts, :event_id, Utils.generate_id()),
24+
event_type: event_type,
25+
timestamp: Keyword.get(opts, :timestamp, Utils.monotonic_timestamp()),
26+
wall_time: Keyword.get(opts, :wall_time, DateTime.utc_now()),
27+
node: Keyword.get(opts, :node, Node.self()),
28+
pid: Keyword.get(opts, :pid, self()),
29+
correlation_id: Keyword.get(opts, :correlation_id),
30+
parent_id: Keyword.get(opts, :parent_id),
31+
data: data
32+
)
3233

3334
case EventValidator.validate(event) do
3435
:ok -> {:ok, event}
@@ -109,11 +110,12 @@ defmodule ElixirScope.Foundation.Logic.EventLogic do
109110
compression = Keyword.get(opts, :compression, true)
110111

111112
try do
112-
binary = if compression do
113-
:erlang.term_to_binary(event, [:compressed])
114-
else
115-
:erlang.term_to_binary(event)
116-
end
113+
binary =
114+
if compression do
115+
:erlang.term_to_binary(event, [:compressed])
116+
else
117+
:erlang.term_to_binary(event)
118+
end
117119

118120
{:ok, binary}
119121
rescue
@@ -163,7 +165,8 @@ defmodule ElixirScope.Foundation.Logic.EventLogic do
163165
Extract correlation chain from a list of events.
164166
"""
165167
@spec extract_correlation_chain([Event.t()], String.t()) :: [Event.t()]
166-
def extract_correlation_chain(events, correlation_id) when is_list(events) and is_binary(correlation_id) do
168+
def extract_correlation_chain(events, correlation_id)
169+
when is_list(events) and is_binary(correlation_id) do
167170
events
168171
|> Enum.filter(fn event -> event.correlation_id == correlation_id end)
169172
|> Enum.sort_by(& &1.timestamp)
@@ -212,14 +215,15 @@ defmodule ElixirScope.Foundation.Logic.EventLogic do
212215
end
213216

214217
defp create_error(error_type, message, context) do
215-
error = Error.new(
216-
error_type: error_type,
217-
message: message,
218-
context: context,
219-
category: :data,
220-
subcategory: :runtime,
221-
severity: :medium
222-
)
218+
error =
219+
Error.new(
220+
error_type: error_type,
221+
message: message,
222+
context: context,
223+
category: :data,
224+
subcategory: :runtime,
225+
severity: :medium
226+
)
223227

224228
{:error, error}
225229
end

0 commit comments

Comments
 (0)