Skip to content

Commit

Permalink
Link to examples in each language
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Jul 29, 2023
1 parent aebb5bf commit 6b6597d
Showing 1 changed file with 4 additions and 58 deletions.
62 changes: 4 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,65 +66,11 @@ curl -F [email protected] https://compiler-preview.dylibso.com/instrument -X POST
## Including a runtime SDK

This example covers the integration of the Rust SDK for Wasmtime. First install
the cargo dependency for the SDK:
Each language includes some examples demonstrating use with different adapters. You can view these examples here:

```toml
[dependencies]
dylibso-observe-sdk = { git = "https://github.com/dylibso/observe-sdk.git" }
```

> **Note**: A runnable example can be found
> [here](rust/examples/otel-stdout.rs).
```rust
use dylibso_observe_sdk::adapter::otelstdout::OtelStdoutAdapter;

#[tokio::main]
pub async fn main() -> anyhow::Result<()> {
let args: Vec<_> = std::env::args().skip(1).collect();
let data = std::fs::read(&args[0])?;
let function_name = "_start";
let config = wasmtime::Config::new();

// Create instance
let engine = wasmtime::Engine::new(&config)?;
let module = wasmtime::Module::new(&engine, &data)?;

let adapter = OtelStdoutAdapter::create();

// Setup WASI
let wasi_ctx = wasmtime_wasi::WasiCtxBuilder::new()
.inherit_env()?
.inherit_stdio()
.args(&args.clone())?
.build();

let mut store = wasmtime::Store::new(&engine, wasi_ctx);
let mut linker = wasmtime::Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |wasi| wasi)?;

// Provide the observability functions to the `Linker` to be made available
// to the instrumented guest code. These are safe to add and are a no-op
// if guest code is uninstrumented.
let trace_ctx = adapter.start(&mut linker, &data)?;

let instance = linker.instantiate(&mut store, &module)?;

// get the function and run it, the events pop into the queue
// as the function is running

let f = instance
.get_func(&mut store, function_name)
.expect("function exists");

f.call(&mut store, &[], &mut []).unwrap();

trace_ctx.shutdown().await;

Ok(())
}
```
* [Rust](rust/examples)
* [Go](go/bin)
* [Js](js/packages)

## Development

Expand Down

0 comments on commit 6b6597d

Please sign in to comment.