BrutRB Deep Thoughts for Apr 9

I’ve been trying hard not to just randomly add features to Brut. My method has been to build real apps, then see what’s missing or annoying, and fold those back into Brut or at least document how to do it.

HOWTOs

I recently created a bunch of “HOWTOs” that just explain simply how to achieve something. It’s a bit of a mish-mash, but I recently needed to test webhooks on my dev environment, and used ngrok. Fortunately, Brut had the features needed to use it, but it just wasn’t clearly documented. Thus, HOWTO ngrok

Webhooks

It did make me think that it’s worth having webhooks as a first class concept. Brut applies CSRF protection to every HTTP POST, but for a webhook this doesn’t make any sense. Brut allows you to control how CSRF is applied by creating a class, but rather than do that, I’m considering something like

webhook "/telnxy" # => /webhooks/telnxy; Webhooks::TelnyxHandler

and then storing “this is for a webhook” as metadata internally, then opting it out of CSRF protection.

Observability

One struggle I’m constantly having is getting OpenTelemetry to work outside of a web request. I’ve tried many incantations with Sidekiq and can’t quite get it working. It’s really hard to debug (or hard for me to anyway :). Similarly, tasks initiated from e.g a CLI I also cannot get to show up.

OTel is extremely poorly documented (despite having thousands and thousands of pages of documentation) so it’s been a lot of trial and error. Something I will probably work on so, since the current app I’m using has an SMS-based UI, so almost none of its behavior is part of a web request - even webhooks just validate the request and queue a job.

1 Like

Thanks for sharing your progress and some insights on how you’re working with Brut. The guide to use ngrok to test webhooks is pretty handy too.

Does Brut use a library or sdk to provide OTel of the box? Or is that something you’re adding on top for this specific app?

I’m using the otel-provided ruby library. I am 99% sure that code is auto-generated from some IDL-type language. It is not idiomatic ruby and it is super over-abstracted + not well documented. My strategy getting what I got to work to work was to ask ChatGPT for help. It was almost always wrong, but it’s wrong answers were helpful and let me get to right answers. I’m using the otel-desktop-viewer to examine what it produces so it’s all been a lot of trial and error.