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

bennydreamtech23
So recently I have been looking for ways to improve my workflow in elixir and I saw all the commands I need to run to setup a project and...
New
pzingg
I took a phx.gen.auth application and added support for storing a user’s cookie consent settings. Created a couple of modal dialogs to ha...
New
c4710n
This package is a simple wrapper of beam-telemetry packages. It provides a modular approach for using beam-telemetry packages. The basi...
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
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
wingyplus
I just publish a library called redoc_ui_plug | Hex. The library renders Redoc UI from the openapi specification url. I used this library...
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
alisinabh
Hey everyone :wave: I was recently working on a hobby project that I have deployed on a platform that did not provide quick and easy acc...
New
zachallaun
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 quickl...
New
benlime
In the last couple of days I was playing around with LiveView, function components and animations. I ended up with a little prototype whi...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement