Skip to content

Commit 74c9634

Browse files
committed
fix: make sure logger resets the timer
1 parent 40b3dde commit 74c9634

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

lib/otel_metric_exporter/log_accumulator.ex

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,24 @@ defmodule OtelMetricExporter.LogAccumulator do
101101
{:noreply, Map.merge(state, Map.merge(rest, %{api: api}))}
102102
end
103103

104-
# Do nothing on an empty queue
105-
def handle_info(:send_log_batch, %{event_queue: []} = state), do: {:noreply, state}
106-
107-
def handle_info(:send_log_batch, state)
108-
when map_size(state.pending_tasks) < state.api.otlp_concurrent_requests do
109-
# We can spin up a new task to send the logs
110-
{:noreply, send_events_via_task(state)}
111-
end
112-
113-
# No task budget, so we're blocking on this message
114104
def handle_info(:send_log_batch, state) do
115-
{:noreply, state |> block_until_any_task_ready() |> send_events_via_task()}
105+
# Reset the timer
106+
state = Map.put(state, :timer_ref, nil)
107+
108+
case state do
109+
%{event_queue: []} ->
110+
# Do nothing on an empty queue
111+
{:noreply, state}
112+
113+
%{pending_tasks: pending_tasks, api: api}
114+
when map_size(pending_tasks) < api.otlp_concurrent_requests ->
115+
# We have some task budget, let's put in a task
116+
{:noreply, send_events_via_task(state)}
117+
118+
_ ->
119+
# No task budget, so we're blocking on this message
120+
{:noreply, state |> block_until_any_task_ready() |> send_events_via_task()}
121+
end
116122
end
117123

118124
def handle_info({ref, result}, state)

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule OtelMetricExporter.MixProject do
66
app: :otel_metric_exporter,
77
name: "OTel Metric Exporter",
88
description: "An unofficial OTel-compatible metric exporter",
9-
version: "0.3.0",
9+
version: "0.3.1",
1010
elixir: "~> 1.17",
1111
start_permanent: Mix.env() == :prod,
1212
source_url: "https://github.com/electric-sql/elixir-otel-metric-exporter",

0 commit comments

Comments
 (0)