Skip to content

Commit

Permalink
chore: update readme example (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx authored Jul 17, 2023
1 parent 5f7af32 commit 2ef94e6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ dylibso-observe-sdk = { git = "https://github.com/dylibso/observe-sdk.git" }
```rust
use dylibso_observe_sdk::adapter::otelstdout::OtelStdoutAdapter;
use tokio::task;

#[tokio::main]
pub async fn main() -> anyhow::Result<()> {
Expand All @@ -64,36 +63,37 @@ pub async fn main() -> anyhow::Result<()> {

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

// Create Observe SDK adapter for OpenTelemetry output written to STDOUT
let adapter = OtelStdoutAdapter::new();
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).await?;

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 instance = linker.instantiate(&mut store, &module)?;

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

f.call(&mut store, &[], &mut []).unwrap();
task::yield_now().await;

// shut down the trace context to flush all remaining spans and cleanup
trace_ctx.shutdown().await;

Ok(())
Expand Down

0 comments on commit 2ef94e6

Please sign in to comment.