zachallaun

zachallaun

Req plugin to instrument requests using Telemetry - request for feedback!

Hey gang,

I’ve been using Req as my primary client for a project I’ve been working on that interacts with a number of APIs, and I quickly found myself wanting some kind of sane, default request logging. At first, I defaulted to a handful of custom steps and a :log option, but recently found myself wanting a bit more granularity.

So, this morning, I banged out a quick plugin to instrument Req requests using Telemetry: ReqTelemetry

As with other Req plugins, it is implemented using request/response/error steps and is set up with an attach function:

Req.new() |> ReqTelemetry.attach() |> Req.get(url: "https://example.org")

I am very much not an expert Telemetry user, so this was developed using a handful of existing Telemetry integrations for reference.

For posterity, at the time of writing this post, the plugin emits the following events:

  • [:req, :request, :pipeline, :start]
  • [:req, :request, :adapter, :start]
  • [:req, :request, :adapter, :stop]
  • [:req, :request, :adapter, :error]
  • [:req, :request, :pipeline, :stop]
  • [:req, :request, :pipeline, :error]

and ships with a default logger that can be installed in your application’s start/2 callback:

@impl true
def start(_type, _args) do
  :ok = ReqTelemetry.attach_default_logger()

  children = [...]
  Supervisor.start_link(children, ...)
end

and logs messages that look like:

15:52:01.462 [info] Req:479128347 - GET https://example.org (pipeline)
15:52:01.466 [info] Req:479128347 - GET https://example.org (adapter)
15:52:01.869 [info] Req:479128347 - 200 in 403ms (adapter)
15:52:01.875 [info] Req:479128347 - 200 in 413ms (pipeline)

Additional examples and information can be found in the docs. I’d very much appreciate any feedback on any aspect of the library.

Cheers,
Zach

Most Liked

zachallaun

zachallaun

v0.1 has been released

This package has been quietly useful for a number of people over the last couple of years! I was somewhat surprised to see that it gets about 1,000 downloads as week.

It’s been on v0.0.x since its inception, but this latest release brings support for Req 0.5.x and, given its use, it seemed reasonable to bump it up to v0.1.

This does mean that you may need to update your dependency if you were using it prevously:

{:req_telemetry, "~> 0.1.0"}

Where Next?

Popular in RFCs Top

brettbeatty
At my work we build a lot of mix tasks for backfills and other maintenance tasks. Even with OptionParser we seem to copy a lot of boilerp...
New
KristerV
I got fed up with removing unused aliases manually so made a package for it: GitHub - KristerV/remove_unused_ex: Remove unused aliases an...
New
senconscious
EctoJuno is a package that provides parsing, validation and applying sorting parameters for your ecto queries on models. Currently sortin...
New
pzingg
https://github.com/pzingg/phx_cookie_consent I took a phx.gen.auth application and added support for storing a user’s cookie consent set...
New
wingyplus
Hi, I start working on the fork version of Elixir GRPC. What I’ve done is the past few days: Support Elixir 1.11+ Support OTP 23+ OTP...
New
miolini
Hi :waving_hand: I’ve been working on CanvasCraft, a 2D drawing library for Elixir built on top of Skia via Rustler. It provides a decla...
New
pepicrft
Hey folks :wave: I implemented a library that uses macros extensively, and I’d appreciate feedback from people that are more versed at w...
New
Billzabob
Hello! I have an idea for an Elixir library I’d like to work on, but wanted to get some thoughts from the community first. It would allo...
New
Overbryd
Polyglot-Ex Rust and wasmex bindings for polyglot. State: Pre-release Hi there, I am starting a thread for my humble bindings library ...
New
sodapopcan
EDIT: I forgot to link the repo, ha: GitHub - sodapopcan/vials: Tweak your mix generators · GitHub This project is not quite ready for p...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement