03 Feb 24

Posted Pendo in Rust + WebAssembly

Yesterday, I worked out how to implement Pendo in a Rust + WebAssembly app…

If you’re not familiar, Pendo is a client-side tracking tool, that is implemented using a JavaScript library.

Rust + WebAssembly means executing logic written in Rust in the browser.

It was a relatively simple solution in the end using wasm (a bridge between JS and the Rust logic). I included a plain ol’ JavaScript file, loaded it in a wasm binding, exposed a JS function to Rust using the bridge and finally was able to call the JavaScript function from Rust, even passing primitive values. That sounds like a mouthful, but really isn’t it. It’s three files and about 20 lines of code, some of which are the JS boilerplate provided by Pendo.

It reminded me of a similar experience with the Flash plugin from back in the early browser days. We had an interface for calling JavaScript from Flash logic. And vice versa.

Years ago, I experimented with doing something similar with Ruby and Go. The idea being a Rails application could hand off computationally expensive operations to Go code sitting in the same directory.

These intersections between languages are powerful, but I wonder about the developer experience and how it contributes to adoption. The tooling will obviously evolve and improve. What exists today enables functionality, but how do you easily implement something like client-side logging for observability using a tool like Datadog. It’s possible in various ways. In Rust, with wasm, you could include the web_sys crate that provides the ability to write to the browser console log. It works, in a line of code, but is the extra dependency really needed. Maybe something more simple exists that I am just unaware of currently.

The Rust community has invested pretty heavily in Tracing. Again, getting that Telemetry data out into a tool like Honeycomb is possible, but isn’t just plug and play. Eventually it will be. Rust has a WebAssembly working group that steers an RFC process. As I gain more experience, I may want to get involved there. I like helping improve the developer experience.

If you’d like to learn about Rust and some of the things I am working on, let me know. I write about my learnings in various places, including a newsletter on Substack.