Skip to content

Commit 066e343

Browse files
committed
Update the README to have some useful information about what is going on here
1 parent 8256d06 commit 066e343

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,124 @@
11
This is an umbrella project which contains a few different Rust crates for interacting with Rollbar.
22
Everything is still heavily under development and everything include crate names are subject to
33
change.
4+
5+
## Crates
6+
7+
### rollbar-rust
8+
9+
The subdirectory `core` contains a crate which defines the types necessary to build items for the
10+
Rollbar API, basic configuration, and an HTTP transport for sending items to the API. The intended
11+
purpose of this crate is to serve as the foundation for interacting with the API for other things to
12+
build upon.
13+
14+
I might change the name of this crate to something else and then have a higher level crate take over
15+
the name of `rollbar-rust` which will be the Rust SDK. As of now this crate is not really a full
16+
fledged SDK.
17+
18+
### rollbar-jvm
19+
20+
The subdirectory `jvm_core` contains a crate which encapsulates certain interactions with the JVM
21+
and JVMTI. Building this crate requires `JAVA_HOME` be set correctly so that we can get access to
22+
the JVMTI C headers to generate Rust bindings. You can see what is necessary in the `build.rs` file
23+
within this crate. This crate relies on `rollbar-rust` for some type definitions of Exceptions and
24+
Frames. These are used for getting stack traces from the JNI/JVMTI.
25+
26+
### rollbar-java-agent
27+
28+
The subdirectory `jvm_sdk_agent` contains a crate which builds a cdylib to be used as a native agent
29+
with the JVM. This agent assumes existence and proper configuration of the `rollbar-java` SDK in
30+
your Java project. It is intended to supplement the normal Java SDK by providing extra information
31+
that is only possible to gather from the JVMTI. Currently this is only used for gathering local
32+
variables. This crate is pretty small as most of the functionality is provided by `rollbar-jvm`.
33+
34+
### rollbar-jvm-agent
35+
36+
The subdirectory `jvm_bare_agent` contains a crate which builds a cdylib to be used as a native
37+
agent with the JVM. This agents assumes that `rollbar-java` does NOT exist in your Java project and
38+
therefore does some of the work that would otherwise be done by the Java SDK. Again because
39+
`rollbar-jvm` handles a lot of the heavy lifting of the interaction with the JVM this crate does not
40+
have to do that much.
41+
42+
If you think the naming scheme is terrible I agree with you. Therefore, all of the actual names are
43+
probably going to change once all of the parts are fleshed out. That is why nothing has been
44+
published to crates.io yet.
45+
46+
## Building
47+
48+
* Install Rust: [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install)
49+
* `cargo build --release`
50+
* Get what you want from `target/release`:
51+
* Agent to help Java SDK: `target/release/librollbar_java_agent.{so,dll,dylib}`
52+
* Agent without Java SDK: `target/release/librollbar_jvm_agent.{so,dll,dylib}`
53+
* There is also a Dockerfile for building Linux releases on the Mac
54+
55+
## Building on a Mac for Linux
56+
57+
In the particular case where you are using a Mac but want to build a shared library that works on Linux, you have to do a little bit of extra work. Luckily, Rust has a decent cross compilation story. The first step is adding the right target via `rustup`:
58+
59+
* `rustup target add x86_64-unknown-linux-gnu`
60+
61+
This is not enough because you need a cross compiling toolchain, in particular a linker, that does the right thing. You can get this via:
62+
63+
* `brew tap SergioBenitez/osxct`
64+
* `brew install x86_64-unknown-linux-gnu`
65+
- You might have to run `xcode-select --install` first depending on your setup
66+
67+
Once that is setup, you can build for the specified target:
68+
69+
* `cargo build --release --target x86_64-unknown-linux-gnu`
70+
71+
You will find the resulting `.so` located at:
72+
73+
```
74+
target/x86_64-unknown-linux-gnu/release/librollbar_java_agent.so
75+
```
76+
77+
Alternatively, you can use the `build-lib.sh` script which uses the Dockerfile in the root to build
78+
a `.so` inside a Docker container and then copies it to your file system.
79+
80+
## Debugging
81+
82+
If you want to see additional output from our agent, you can set the environment variable
83+
`ROLLBAR_LOG` to one of `trace`, `debug`, `info`, or `warn`. These will output different levels of
84+
information to standard out where your JVM process is running.
85+
86+
## Using the agent
87+
88+
How to use the agent depends on how you invoke the JVM to start your application. In order
89+
to use a native agent you need to pass a command line argument to this invocation. The most
90+
basic usage would look like:
91+
92+
```
93+
java -jar foo.jar -agentpath:path/to/librollbar_java_agent.dylib
94+
```
95+
96+
However, if you are using a toolchain, such as Gradle, to manage your application then
97+
adding this command line argument might take a bit more effort to figure out where to add it. For
98+
Gradle the easiest way is to add the following to your `build.gradle` file:
99+
100+
```
101+
applicationDefaultJvmArgs = ["-agentpath:path/to/"+System.mapLibraryName("rollbar_java_agent")]
102+
```
103+
104+
Regardless of your JVM language of choice, at some level their is an invocation of the JVM and
105+
therefore there is a configuration option to pass arguments directly to the JVM.
106+
107+
## Configuration
108+
109+
The agent that works with the Rollbar Java SDK does not need any configuration because it relies on
110+
the Java SDK to be properly configured and to send items to the API. The other agent does need to be
111+
configured. The agent assumes a file named `rollbar.conf` which lives at the same path as the
112+
dynamic library. This file should be in TOML format, for example:
113+
114+
```
115+
access_token = "abc123"
116+
endpoint = "https://api.rollbar.com/api/1/item/"
117+
timeout = 10
118+
```
119+
120+
We are still working on the configuration, but the only required field is the `access_token`.
121+
122+
Instead of using a file, if the only thing you want to set is the `access_token`, you can also set
123+
the `ROLLBAR_TOKEN` environment variable in your process with the value of your access token. If
124+
`rollbar.conf` is present it will take precedence over the environment variable.

0 commit comments

Comments
 (0)