Skip to content

Commit

Permalink
Merge pull request #179 from pma/feature/disable-progress-report
Browse files Browse the repository at this point in the history
Disable Erlang library's pregress report by default
  • Loading branch information
ono committed Dec 28, 2020
2 parents 280d846 + 9b3a4ca commit e9ca8db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Simple Elixir wrapper for the Erlang RabbitMQ client.

The API is based on Langohr, a Clojure client for RabbitMQ.

## Migration from 1.X to 2.X

TO BE WRITTEN

## Migration from 0.X to 1.X

If you use amqp 0.X and plan to migrate to 1.0 please read our [migration guide](https://github.com/pma/amqp/wiki/Upgrade-from-0.X-to-1.0).
Expand Down Expand Up @@ -167,7 +171,21 @@ Error converting Hello, World! to integer
Error converting Hello, World! to integer
```

## Stable RabbitMQ Connection
### Configuration

#### Erlang library's progress report

This library uses an official Erlang RabbitMQ client library internally and we found its logging is too verbose.
These are called progress reports by the Erlang library and you would see a lot of entries with info log level if you
use 1.x version.
AMQP disables that by default from version 2.0.
If you want to see more detailed logs, you can enable it by adding the following line on your config.

```elixir
config :amqp, enable_progress_report: true
```

### Stable RabbitMQ Connection

While the above example works, it does nothing to handle RabbitMQ connection
outages. In case of an outage your Genserver will remain stale and won't
Expand Down Expand Up @@ -235,7 +253,7 @@ When the connection drops or the server is down, the GenServer will stop.
If you have put the GenServer module to your application tree, the Supervisor will automatically restart it.
Then it will try to reconnect indefinitely until it succeeds.

## Types of arguments and headers
### Types of arguments and headers

The parameter `arguments` in `Queue.declare`, `Exchange.declare`, `Basic.consume` and the parameter `headers` in `Basic.publish` are a list of tuples in the form `{name, type, value}`, where `name` is a binary containing the argument/header name, `type` is an atom describing the AMQP field type and `value` a term compatible with the AMQP field type.

Expand Down Expand Up @@ -312,17 +330,6 @@ Try the following configuration.
config :logger, handle_otp_reports: false
```

Or try filtering out the messages at your application start:

```elixir
:logger.add_primary_filter(
:ignore_rabbitmq_progress_reports,
{&:logger_filters.domain/2, {:stop, :equal, [:progress]}}
)
```

See [this comment](https://github.com/pma/amqp/issues/110#issuecomment-442761299) for the
details.

#### Lager conflicts with Elixir logger

Expand Down
29 changes: 29 additions & 0 deletions lib/amqp/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,41 @@ defmodule AMQP.Application do
@moduledoc false

use Application
require Logger

@impl true
def start(_type, _args) do
children = []

load_config()

opts = [strategy: :one_for_one, name: AMQP.Application]
Supervisor.start_link(children, opts)
end

defp load_config do
unless Application.get_env(:amqp, :enable_progress_report, false) do
disable_progress_report()
end
end

@doc """
Disables the progress report logging from Erlang library.
The log outputs are very verbose and can contain credentials.
This AMQP library recommends to disable unless you want the information.
"""
@spec disable_progress_report :: :ok | {:error, any}
def disable_progress_report do
:logger.add_primary_filter(
:amqp_ignore_rabbitmq_progress_reports,
{&:logger_filters.domain/2, {:stop, :equal, [:progress]}}
)

:ok
rescue
e ->
Logger.warn("Failed to disable progress report by Erlang library: detail: #{inspect(e)}")
{:error, e}
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule AMQP.Mixfile do

def application do
[
applications: [:lager, :amqp_client],
applications: [:lager, :amqp_client, :logger],
mod: {AMQP.Application, []}
]
end
Expand Down

0 comments on commit e9ca8db

Please sign in to comment.