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.

1 Like

Not a surprise as this is not very used and documented so chatGPT is poorly trained on Brut. I think you might have to create like a skill or use a larger context window to pass the documentation and a few examples to get things done with AI.

The issue wasn’t Brut-related, it was OTel-related. A skill would not work since my problem was more fundamental - how do I use the officially published OTel library? My questions were all about integrating into a Rack app, as that is widely understood and documented.

This was over a year ago, and my guess is that OTel is not widely used, so Chat GPT had out of date info + just making stuff up. Even still, it’s wrong answers were far better than the offical docs, which are IMO worthless. It’s probably better now and I could probably just dump the entire Ruby gem into context.

Even as of six months ago, asking both Chat GPT and Claude to debug why it wasn’t working sent them both into a spiral of totally nonsensical suggestions. Chat GPT ended up in a loop where it just suggested two different things over and over again.

I’ll be trying again soon and will report back.

1 Like