Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,56 @@ within your Elsa configuration.

You can find an example of configuring and using Elsa [here](https://github.com/jdenen/let_it_go).

## Telemetry

Starting with Elsa `1.0.0-rc.4` [`:telemetry`](https://github.com/beam-telemetry/telemetry) events are available.

- `[:elsa, :consumer, :handle_messages, :start]` - dispatched by `Elsa.Consumer.Worker` before handling a list of messages.

- Measurement: `%{system_time: integer}`
- Metadata:
```elixir
%{
topic: Elsa.topic(),
partition: Elsa.partition(),
generation_id: non_neg_integer,
offset: non_neg_integer,
messages: [Elsa.Message()]
}
```

- `[:elsa, :consumer, :handle_messages, :end]` - dispatched by `Elsa.Consumer.Worker` after handling a list of messages.

- Measurement: `%{duration: native_time}`
- Metadata:
```elixir
%{
topic: Elsa.topic(),
partition: Elsa.partition(),
generation_id: non_neg_integer,
offset: non_neg_integer,
messages: [Elsa.Message()],
result: any
}
```

- `[:elsa, :consumer, :handle_messages, :exception]` - dispatched by `Elsa.Consumer.Worker` if an exception occures processing messages.

- Measurement: `%{duration: native_time}`
- Metadata:
```elixir
%{
topic: Elsa.topic(),
partition: Elsa.partition(),
generation_id: non_neg_integer,
offset: non_neg_integer,
messages: [Elsa.Message()],
kind: kind,
reason: reason,
stacktrace: stacktrace,
}
```

## Testing

Elsa uses the standard ExUnit testing library for unit testing. For integration testing interactions with Kafka, it uses the [`divo`](https://github.com/smartcitiesdata/divo) library. Run tests with the command `mix test.integration`.
15 changes: 14 additions & 1 deletion lib/elsa/consumer/worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,20 @@ defmodule Elsa.Consumer.Worker do
end

defp send_messages_to_handler(messages, state) do
state.handler.handle_messages(messages, state.handler_state)
:telemetry.span(
[:elsa, :consumer, :handle_messages],
%{
topic: state.topic,
partition: state.partition,
generation_id: state.generation_id,
offset: state.offset,
messages: messages
},
fn ->
result = state.handler.handle_messages(messages, state.handler_state)
{result, %{result: result}}
end
)
end

defp ack_messages(_topic, _partition, offset, %{generation_id: nil} = state) do
Expand Down
5 changes: 3 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Elsa.MixProject do
use Mix.Project

@version "1.0.0-rc.3"
@version "1.0.0-rc.4"
@github "https://github.com/bbalser/elsa"

def project do
Expand Down Expand Up @@ -37,7 +37,8 @@ defmodule Elsa.MixProject do
{:placebo, "~> 2.0", only: [:dev, :test]},
{:checkov, "~> 1.0", only: [:test, :integration]},
{:ex_doc, "~> 0.25.3", only: [:dev]},
{:dialyxir, "~> 1.1.0", only: [:dev], runtime: false}
{:dialyxir, "~> 1.1.0", only: [:dev], runtime: false},
{:telemetry, "~> 1.0"}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
"placebo": {:hex, :placebo, "2.0.0", "c0e773dec77e941bcbcc14d10b759f2d66775aff9b75051f3e41939b64300e81", [:mix], [{:meck, "~> 0.9", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "e0872cec8848d7e59ba96396f45ee1ad34662c689c86ba6190694d38b4289844"},
"snappyer": {:hex, :snappyer, "1.2.8", "201ce9067a33c71a6a5087c0c3a49a010b17112d461e6df696c722dcb6d0934a", [:rebar3], [], "hexpm", "35518e79a28548b56d8fd6aee2f565f12f51c2d3d053f9cfa817c83be88c4f3d"},
"supervisor3": {:hex, :supervisor3, "1.1.11", "d81cdec31d102fde407423e1d05b569572850deebed86b951d5233c387cba80b", [:rebar3], [], "hexpm", "e6c2dedbcabcba24995a218aca12db5e208b80d3252692b22ef0f1a266104b50"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
}