This repository is a WIP proof of concept.
This repository contains a rust library that contains logic to send items to Rollbar APIs. It currently has the following examples:
- A nextjs application that can consume this library built to web assembly.
- A nodejs program that can consume this library built to a native compilation target.
- A c++ program that can consume this library as a dynamic library.
rollbar
is a rust library that contains code that knows how to communicate with multiple runtimes.
This library uses wasm-pack
to build a directory that can be used as a node_module
. The standard wasm-bindgen
library is used for the glue between the web assembly runtime and the rust runtime. Both of the mentioned tools are supported by the Rust Webassembly Working Group which is supported by a number of companies including Mozilla.
For node, the library uses neon-bindings
to facilitate communication between the rust runtime and the node runtime. It's supported by a number of companies including 1Password for their desktop (Electron) application.
For C and other languages that have c compatible ffi's, a c library is made available and a header file is generated using cbindgen
.
- Rust must be installed.
wasm-pack
for building to web assembly.- A modern version of
nodejs
python2
must be executable in your$PATH
. It is a dependency ofnode-gyp
which is a tool used by node for managaging native addon modules.- To handle dependency management for c/c++, this project uses cmake. Ensure you have at least version 3.19 installed.
- To make things easier, this project uses
cargo-make
to run tasks. Install with:
cargo install --force cargo-make
Next, make a file named .env
in the root of this repository and add the following.
POST_TOKEN=<your project's post_client_item here>
./examples/nextjs
contains a nextjs application where this library is consumed as a web assembly module. To see it in action run the following from the rollbar-sdk
directory:
cargo make run-nextjs-example
Next, open http://localhost:3000, fiddle with the form fields, and send it 🏂! Once you submit the form, check out the item in the rollbar application.
./examples/nodejs
contains a simple node program where this library is consumed as a native module. Feel free to fiddle with the program at ./examples/nodejs/index.js
. To see it in action, run the following:
cargo make run-nodejs-example
./examples/cpp
contains a simple c++ program where this library is consumed as a dynamic library. Feel free to fiddle with the program at ./examples/cpp/main.cpp
. To see it in action, run the following:
cargo make run-cpp-example
So far, I've found some caveats, particularly with the web assembly target:
- Node has support for loading web assembly files, but it is currently experimental. This means that users would have to ensure the experiment flag be added to their
node
invocation. However, this is not a requirement when build natively with theneon
library. - The
wasm-pack
build tool and it's underlying support program (wasm-bindgen-cli
) don't support compiling to multiple targets. This means that some custom/hacky scripts would have to be added if a separate package for browser and nodejs isn't desired (i.e. just a singlerollbar-sdk
package that the currentrollbar
package can consume. - Web assembly must be consumed from a module ready application. The consumer's web application must be using a bundler configured to consume web assembly or be served from a server that supports module loading. This won't be a problem for most modern web applications. This also means that the application can't be bundled the number of ways that it currently is here.
- While popular companies such as 1Password use
neon
, it's ecosystem is still a little slow. Rollbar would likely need to contribute here, which is not inherently a negative!- In order to use the standard
serde
library to make passing around objects easier, I had to use an outdated version ofneon
(waiting on this PR to be merged).
- In order to use the standard
- For c/c++, consumers of this library will need rust installed when building their application.