From 7136bcc2a629f5a8ad8056ed7ce6bbddfb44a39a Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Thu, 8 Aug 2024 13:46:33 -0400 Subject: [PATCH] chore: remove component model support The component model support was unmaintained and there was a lot of churn with the component model and its packages. Feel free to readd it if you need it! --- .github/workflows/ci.yml | 21 -- .gitignore | 1 - Cargo.toml | 2 +- README.md | 30 -- corpus/00-component-instr-command/Cargo.lock | 85 ------ corpus/00-component-instr-command/Cargo.toml | 17 -- .../src/bindings.rs | 210 -------------- corpus/00-component-instr-command/src/main.rs | 9 - .../wit/component.wit | 5 - .../01-component-instr-component/Cargo.lock | 85 ------ .../01-component-instr-component/Cargo.toml | 22 -- .../src/bindings.rs | 266 ------------------ .../01-component-instr-component/src/lib.rs | 17 -- .../wit/world.wit | 7 - corpus/02-component-instr-combined/Cargo.lock | 25 -- corpus/02-component-instr-combined/Cargo.toml | 15 - corpus/02-component-instr-combined/config.yml | 4 - .../src/bindings.rs | 49 ---- .../02-component-instr-combined/src/main.rs | 7 - justfile | 28 -- rust/Cargo.toml | 3 - rust/examples/otel-stdout-components.rs | 88 ------ ...ctor-hello-world-otel-stdout-components.rs | 88 ------ rust/src/adapter/mod.rs | 21 -- rust/src/context.rs | 260 ----------------- wit/observe.wasm | Bin 449 -> 0 bytes wit/observe.wit | 27 -- 27 files changed, 1 insertion(+), 1391 deletions(-) delete mode 100644 corpus/00-component-instr-command/Cargo.lock delete mode 100644 corpus/00-component-instr-command/Cargo.toml delete mode 100644 corpus/00-component-instr-command/src/bindings.rs delete mode 100644 corpus/00-component-instr-command/src/main.rs delete mode 100644 corpus/00-component-instr-command/wit/component.wit delete mode 100644 corpus/01-component-instr-component/Cargo.lock delete mode 100644 corpus/01-component-instr-component/Cargo.toml delete mode 100644 corpus/01-component-instr-component/src/bindings.rs delete mode 100644 corpus/01-component-instr-component/src/lib.rs delete mode 100644 corpus/01-component-instr-component/wit/world.wit delete mode 100644 corpus/02-component-instr-combined/Cargo.lock delete mode 100644 corpus/02-component-instr-combined/Cargo.toml delete mode 100644 corpus/02-component-instr-combined/config.yml delete mode 100644 corpus/02-component-instr-combined/src/bindings.rs delete mode 100644 corpus/02-component-instr-combined/src/main.rs delete mode 100644 rust/examples/otel-stdout-components.rs delete mode 100644 rust/examples/reactor-hello-world-otel-stdout-components.rs delete mode 100644 wit/observe.wasm delete mode 100644 wit/observe.wit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ed8cc10..7145b0b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,19 +80,6 @@ jobs: with: version: "23.4" - - name: Install Component CLI Deps - uses: actions-rs/cargo@v1 - with: - command: install - args: wasm-tools@^1.0.57 cargo-component@0.7.0 - - - name: Install Just - uses: extractions/setup-just@v1 - - # building wit is necessary for cargo test - - name: Build wit - run: just build_wit - - name: Run cargo test uses: actions-rs/cargo@v1 with: @@ -125,11 +112,3 @@ jobs: command: run args: --example=reactor-hello test/reactor-hello.c.instr.wasm - - name: Component Demo - run: just component_demo - - - name: Component Demo 2 - run: just component_demo_2 - - - name: Component Demo 3 - run: just component_demo_3 diff --git a/.gitignore b/.gitignore index 77195f92..7bfc656b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ target build.js node_modules dist -corpus/01-component-instr-component/wit/deps/observe/observe.wit \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 668fd506..21fe2d5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ [workspace] members = [ "rust" ] -exclude = [ "observe-api/rust", "observe-api/test/rust", "corpus/" ] +exclude = [ "observe-api/rust", "observe-api/test/rust" ] resolver = "2" diff --git a/README.md b/README.md index a6902593..5046ed85 100644 --- a/README.md +++ b/README.md @@ -138,33 +138,3 @@ One of the test adapters will output to Zipkin, defaulting to one running on localhost. docker run -d -p 9411:9411 openzipkin/zipkin - -## Component Support - -WIT is available in `wit` for the (manual) observe api and (automatic) observe instrument api. - -### Examples - -First install dependencies: - -```bash -cargo install wasm-tools cargo-component -``` - -Build the wit: - -```bash -just build_wit -``` - -Build and run `component_demo`: - -```bash -just component_demo -``` - -Build and run `component_demo_2`: - -```bash -just component_demo_2 -``` diff --git a/corpus/00-component-instr-command/Cargo.lock b/corpus/00-component-instr-command/Cargo.lock deleted file mode 100644 index 6f97c91f..00000000 --- a/corpus/00-component-instr-command/Cargo.lock +++ /dev/null @@ -1,85 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "bitflags" -version = "2.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" - -[[package]] -name = "component-instr-command" -version = "0.1.0" -dependencies = [ - "log", - "observe_api", - "wit-bindgen", -] - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "observe_api" -version = "0.1.0" -dependencies = [ - "log", - "observe_instrument", -] - -[[package]] -name = "observe_instrument" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wit-bindgen" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" -dependencies = [ - "bitflags", -] diff --git a/corpus/00-component-instr-command/Cargo.toml b/corpus/00-component-instr-command/Cargo.toml deleted file mode 100644 index 77e13d98..00000000 --- a/corpus/00-component-instr-command/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "component-instr-command" -version = "0.1.0" -edition = "2021" - -[package.metadata.component] -package = "example:component-instr-command" - -[package.metadata.component.target.dependencies] -"dylibso:observe" = { path = "../../wit/observe.wasm" } - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4.20" -wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"]} -observe_api = { path = "../../observe-api/rust" } diff --git a/corpus/00-component-instr-command/src/bindings.rs b/corpus/00-component-instr-command/src/bindings.rs deleted file mode 100644 index b4052d79..00000000 --- a/corpus/00-component-instr-command/src/bindings.rs +++ /dev/null @@ -1,210 +0,0 @@ -// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! -pub mod dylibso { - pub mod observe { - - #[allow(clippy::all)] - pub mod api { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_section; - #[repr(u8)] - #[derive(Clone, Copy, Eq, PartialEq)] - pub enum LogLevel { - Error, - Warn, - Info, - Debug, - Trace, - } - impl ::core::fmt::Debug for LogLevel { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - LogLevel::Error => { - f.debug_tuple("LogLevel::Error").finish() - } - LogLevel::Warn => { - f.debug_tuple("LogLevel::Warn").finish() - } - LogLevel::Info => { - f.debug_tuple("LogLevel::Info").finish() - } - LogLevel::Debug => { - f.debug_tuple("LogLevel::Debug").finish() - } - LogLevel::Trace => { - f.debug_tuple("LogLevel::Trace").finish() - } - } - } - } - - impl LogLevel{ - pub(crate) unsafe fn _lift(val: u8) -> LogLevel{ - if !cfg!(debug_assertions) { - return ::core::mem::transmute(val); - } - - match val { - 0 => LogLevel::Error, - 1 => LogLevel::Warn, - 2 => LogLevel::Info, - 3 => LogLevel::Debug, - 4 => LogLevel::Trace, - - _ => panic!("invalid enum discriminant"), - } - } - } - - #[repr(u8)] - #[derive(Clone, Copy, Eq, PartialEq)] - pub enum MetricFormat { - Statsd, - } - impl ::core::fmt::Debug for MetricFormat { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - MetricFormat::Statsd => { - f.debug_tuple("MetricFormat::Statsd").finish() - } - } - } - } - - impl MetricFormat{ - pub(crate) unsafe fn _lift(val: u8) -> MetricFormat{ - if !cfg!(debug_assertions) { - return ::core::mem::transmute(val); - } - - match val { - 0 => MetricFormat::Statsd, - - _ => panic!("invalid enum discriminant"), - } - } - } - - #[allow(unused_unsafe, clippy::all)] - pub fn metric(format: MetricFormat,name: &[u8],){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = name; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "metric"] - fn wit_import(_: i32, _: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, ){ unreachable!() } - wit_import(format.clone() as i32, ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn log(level: LogLevel,msg: &[u8],){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = msg; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "log"] - fn wit_import(_: i32, _: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, ){ unreachable!() } - wit_import(level.clone() as i32, ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn span_enter(name: &str,){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = name; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "span-enter"] - fn wit_import(_: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, ){ unreachable!() } - wit_import(ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn span_tags(tags: &str,){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = tags; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "span-tags"] - fn wit_import(_: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, ){ unreachable!() } - wit_import(ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn span_exit(){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "span-exit"] - fn wit_import(); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(){ unreachable!() } - wit_import(); - } - } - - } - - } -} - -#[cfg(target_arch = "wasm32")] -#[link_section = "component-type:component-instr-command"] -#[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 454] = [3, 0, 23, 99, 111, 109, 112, 111, 110, 101, 110, 116, 45, 105, 110, 115, 116, 114, 45, 99, 111, 109, 109, 97, 110, 100, 0, 97, 115, 109, 13, 0, 1, 0, 7, 168, 2, 1, 65, 2, 1, 65, 2, 1, 66, 15, 1, 109, 5, 5, 101, 114, 114, 111, 114, 4, 119, 97, 114, 110, 4, 105, 110, 102, 111, 5, 100, 101, 98, 117, 103, 5, 116, 114, 97, 99, 101, 4, 0, 9, 108, 111, 103, 45, 108, 101, 118, 101, 108, 3, 0, 0, 1, 109, 1, 6, 115, 116, 97, 116, 115, 100, 4, 0, 13, 109, 101, 116, 114, 105, 99, 45, 102, 111, 114, 109, 97, 116, 3, 0, 2, 1, 112, 125, 1, 64, 2, 6, 102, 111, 114, 109, 97, 116, 3, 4, 110, 97, 109, 101, 4, 1, 0, 4, 0, 6, 109, 101, 116, 114, 105, 99, 1, 5, 1, 64, 2, 5, 108, 101, 118, 101, 108, 1, 3, 109, 115, 103, 4, 1, 0, 4, 0, 3, 108, 111, 103, 1, 6, 1, 64, 1, 4, 110, 97, 109, 101, 115, 1, 0, 4, 0, 10, 115, 112, 97, 110, 45, 101, 110, 116, 101, 114, 1, 7, 1, 64, 1, 4, 116, 97, 103, 115, 115, 1, 0, 4, 0, 9, 115, 112, 97, 110, 45, 116, 97, 103, 115, 1, 8, 1, 64, 0, 1, 0, 4, 0, 9, 115, 112, 97, 110, 45, 101, 120, 105, 116, 1, 9, 3, 1, 19, 100, 121, 108, 105, 98, 115, 111, 58, 111, 98, 115, 101, 114, 118, 101, 47, 97, 112, 105, 5, 0, 4, 1, 55, 101, 120, 97, 109, 112, 108, 101, 58, 99, 111, 109, 112, 111, 110, 101, 110, 116, 45, 105, 110, 115, 116, 114, 45, 99, 111, 109, 109, 97, 110, 100, 47, 99, 111, 109, 112, 111, 110, 101, 110, 116, 45, 105, 110, 115, 116, 114, 45, 99, 111, 109, 109, 97, 110, 100, 4, 0, 11, 29, 1, 0, 23, 99, 111, 109, 112, 111, 110, 101, 110, 116, 45, 105, 110, 115, 116, 114, 45, 99, 111, 109, 109, 97, 110, 100, 3, 0, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; - -#[inline(never)] -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn __link_section() {} diff --git a/corpus/00-component-instr-command/src/main.rs b/corpus/00-component-instr-command/src/main.rs deleted file mode 100644 index bc1d43bc..00000000 --- a/corpus/00-component-instr-command/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod bindings; -use observe_api::*; - -fn main() { - span_enter("hello world"); - log(log::Level::Info, "hello world"); - span_exit(); - println!("Hello, world!"); -} diff --git a/corpus/00-component-instr-command/wit/component.wit b/corpus/00-component-instr-command/wit/component.wit deleted file mode 100644 index 7af736b3..00000000 --- a/corpus/00-component-instr-command/wit/component.wit +++ /dev/null @@ -1,5 +0,0 @@ -package example:component-instr-command; - -world component-instr-command { - import dylibso:observe/api; -} diff --git a/corpus/01-component-instr-component/Cargo.lock b/corpus/01-component-instr-component/Cargo.lock deleted file mode 100644 index 8810d14d..00000000 --- a/corpus/01-component-instr-component/Cargo.lock +++ /dev/null @@ -1,85 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "bitflags" -version = "2.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" - -[[package]] -name = "component-instr-component" -version = "0.1.0" -dependencies = [ - "log", - "observe_api", - "wit-bindgen", -] - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "observe_api" -version = "0.1.0" -dependencies = [ - "log", - "observe_instrument", -] - -[[package]] -name = "observe_instrument" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.78" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "wit-bindgen" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" -dependencies = [ - "bitflags", -] diff --git a/corpus/01-component-instr-component/Cargo.toml b/corpus/01-component-instr-component/Cargo.toml deleted file mode 100644 index 30ab3177..00000000 --- a/corpus/01-component-instr-component/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "component-instr-component" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4.20" -wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"]} -observe_api = { path = "../../observe-api/rust" } - -[lib] -crate-type = ["cdylib"] - -[package.metadata.component] -package = "component:component-instr-component" - -[package.metadata.component.dependencies] - -[package.metadata.component.target.dependencies] -"dylibso:observe" = { path = "../../wit/observe.wasm" } diff --git a/corpus/01-component-instr-component/src/bindings.rs b/corpus/01-component-instr-component/src/bindings.rs deleted file mode 100644 index a7ae6034..00000000 --- a/corpus/01-component-instr-component/src/bindings.rs +++ /dev/null @@ -1,266 +0,0 @@ -// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! -const _: () = { - - #[doc(hidden)] - #[export_name = "hello-world"] - #[allow(non_snake_case)] - unsafe extern "C" fn __export_hello_world() -> i32 { - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - - // Before executing any other code, use this function to run all static - // constructors, if they have not yet been run. This is a hack required - // to work around wasi-libc ctors calling import functions to initialize - // the environment. - // - // This functionality will be removed once rust 1.69.0 is stable, at which - // point wasi-libc will no longer have this behavior. - // - // See - // https://github.com/bytecodealliance/preview2-prototyping/issues/99 - // for more details. - #[cfg(target_arch="wasm32")] - wit_bindgen::rt::run_ctors_once(); - - let result0 = <_GuestImpl as Guest>::hello_world(); - let ptr1 = _RET_AREA.0.as_mut_ptr() as i32; - let vec2 = (result0.into_bytes()).into_boxed_slice(); - let ptr2 = vec2.as_ptr() as i32; - let len2 = vec2.len() as i32; - ::core::mem::forget(vec2); - *((ptr1 + 4) as *mut i32) = len2; - *((ptr1 + 0) as *mut i32) = ptr2; - ptr1 - } - - const _: () = { - #[doc(hidden)] - #[export_name = "cabi_post_hello-world"] - #[allow(non_snake_case)] - unsafe extern "C" fn __post_return_hello_world(arg0: i32,) { - let l0 = *((arg0 + 0) as *const i32); - let l1 = *((arg0 + 4) as *const i32); - wit_bindgen::rt::dealloc(l0, (l1) as usize, 1); - } - }; -}; -use super::Component as _GuestImpl; -pub trait Guest { - fn hello_world() -> wit_bindgen::rt::string::String; -} - -#[allow(unused_imports)] -use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - -#[repr(align(4))] -struct _RetArea([u8; 8]); -static mut _RET_AREA: _RetArea = _RetArea([0; 8]); -pub mod dylibso { - pub mod observe { - - #[allow(clippy::all)] - pub mod api { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_section; - #[repr(u8)] - #[derive(Clone, Copy, Eq, PartialEq)] - pub enum LogLevel { - Error, - Warn, - Info, - Debug, - Trace, - } - impl ::core::fmt::Debug for LogLevel { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - LogLevel::Error => { - f.debug_tuple("LogLevel::Error").finish() - } - LogLevel::Warn => { - f.debug_tuple("LogLevel::Warn").finish() - } - LogLevel::Info => { - f.debug_tuple("LogLevel::Info").finish() - } - LogLevel::Debug => { - f.debug_tuple("LogLevel::Debug").finish() - } - LogLevel::Trace => { - f.debug_tuple("LogLevel::Trace").finish() - } - } - } - } - - impl LogLevel{ - pub(crate) unsafe fn _lift(val: u8) -> LogLevel{ - if !cfg!(debug_assertions) { - return ::core::mem::transmute(val); - } - - match val { - 0 => LogLevel::Error, - 1 => LogLevel::Warn, - 2 => LogLevel::Info, - 3 => LogLevel::Debug, - 4 => LogLevel::Trace, - - _ => panic!("invalid enum discriminant"), - } - } - } - - #[repr(u8)] - #[derive(Clone, Copy, Eq, PartialEq)] - pub enum MetricFormat { - Statsd, - } - impl ::core::fmt::Debug for MetricFormat { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - MetricFormat::Statsd => { - f.debug_tuple("MetricFormat::Statsd").finish() - } - } - } - } - - impl MetricFormat{ - pub(crate) unsafe fn _lift(val: u8) -> MetricFormat{ - if !cfg!(debug_assertions) { - return ::core::mem::transmute(val); - } - - match val { - 0 => MetricFormat::Statsd, - - _ => panic!("invalid enum discriminant"), - } - } - } - - #[allow(unused_unsafe, clippy::all)] - pub fn metric(format: MetricFormat,name: &[u8],){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = name; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "metric"] - fn wit_import(_: i32, _: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, ){ unreachable!() } - wit_import(format.clone() as i32, ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn log(level: LogLevel,msg: &[u8],){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = msg; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "log"] - fn wit_import(_: i32, _: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, _: i32, ){ unreachable!() } - wit_import(level.clone() as i32, ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn span_enter(name: &str,){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = name; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "span-enter"] - fn wit_import(_: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, ){ unreachable!() } - wit_import(ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn span_tags(tags: &str,){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - let vec0 = tags; - let ptr0 = vec0.as_ptr() as i32; - let len0 = vec0.len() as i32; - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "span-tags"] - fn wit_import(_: i32, _: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: i32, ){ unreachable!() } - wit_import(ptr0, len0); - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn span_exit(){ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "dylibso:observe/api")] - extern "C" { - #[link_name = "span-exit"] - fn wit_import(); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(){ unreachable!() } - wit_import(); - } - } - - } - - } -} - -#[cfg(target_arch = "wasm32")] -#[link_section = "component-type:example"] -#[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 508] = [3, 0, 7, 101, 120, 97, 109, 112, 108, 101, 0, 97, 115, 109, 13, 0, 1, 0, 7, 177, 2, 1, 65, 2, 1, 65, 4, 1, 66, 15, 1, 109, 5, 5, 101, 114, 114, 111, 114, 4, 119, 97, 114, 110, 4, 105, 110, 102, 111, 5, 100, 101, 98, 117, 103, 5, 116, 114, 97, 99, 101, 4, 0, 9, 108, 111, 103, 45, 108, 101, 118, 101, 108, 3, 0, 0, 1, 109, 1, 6, 115, 116, 97, 116, 115, 100, 4, 0, 13, 109, 101, 116, 114, 105, 99, 45, 102, 111, 114, 109, 97, 116, 3, 0, 2, 1, 112, 125, 1, 64, 2, 6, 102, 111, 114, 109, 97, 116, 3, 4, 110, 97, 109, 101, 4, 1, 0, 4, 0, 6, 109, 101, 116, 114, 105, 99, 1, 5, 1, 64, 2, 5, 108, 101, 118, 101, 108, 1, 3, 109, 115, 103, 4, 1, 0, 4, 0, 3, 108, 111, 103, 1, 6, 1, 64, 1, 4, 110, 97, 109, 101, 115, 1, 0, 4, 0, 10, 115, 112, 97, 110, 45, 101, 110, 116, 101, 114, 1, 7, 1, 64, 1, 4, 116, 97, 103, 115, 115, 1, 0, 4, 0, 9, 115, 112, 97, 110, 45, 116, 97, 103, 115, 1, 8, 1, 64, 0, 1, 0, 4, 0, 9, 115, 112, 97, 110, 45, 101, 120, 105, 116, 1, 9, 3, 1, 19, 100, 121, 108, 105, 98, 115, 111, 58, 111, 98, 115, 101, 114, 118, 101, 47, 97, 112, 105, 5, 0, 1, 64, 0, 0, 115, 4, 0, 11, 104, 101, 108, 108, 111, 45, 119, 111, 114, 108, 100, 1, 1, 4, 1, 43, 99, 111, 109, 112, 111, 110, 101, 110, 116, 58, 99, 111, 109, 112, 111, 110, 101, 110, 116, 45, 105, 110, 115, 116, 114, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 47, 101, 120, 97, 109, 112, 108, 101, 4, 0, 11, 13, 1, 0, 7, 101, 120, 97, 109, 112, 108, 101, 3, 0, 0, 0, 93, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 34, 119, 111, 114, 108, 100, 115, 34, 58, 123, 34, 101, 120, 97, 109, 112, 108, 101, 34, 58, 123, 34, 100, 111, 99, 115, 34, 58, 34, 65, 110, 32, 101, 120, 97, 109, 112, 108, 101, 32, 119, 111, 114, 108, 100, 32, 102, 111, 114, 32, 116, 104, 101, 32, 99, 111, 109, 112, 111, 110, 101, 110, 116, 32, 116, 111, 32, 116, 97, 114, 103, 101, 116, 46, 34, 125, 125, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; - -#[inline(never)] -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn __link_section() {} diff --git a/corpus/01-component-instr-component/src/lib.rs b/corpus/01-component-instr-component/src/lib.rs deleted file mode 100644 index c92ef628..00000000 --- a/corpus/01-component-instr-component/src/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -mod bindings; - -use observe_api::*; - -use bindings::Guest; - -struct Component; - -impl Guest for Component { - /// Say hello! - fn hello_world() -> String { - span_enter("hello world"); - log(log::Level::Info, "hello world"); - span_exit(); - "Hello, World!".to_string() - } -} diff --git a/corpus/01-component-instr-component/wit/world.wit b/corpus/01-component-instr-component/wit/world.wit deleted file mode 100644 index db86e211..00000000 --- a/corpus/01-component-instr-component/wit/world.wit +++ /dev/null @@ -1,7 +0,0 @@ -package component:component-instr-component; - -/// An example world for the component to target. -world example { - import dylibso:observe/api; - export hello-world: func() -> string; -} diff --git a/corpus/02-component-instr-combined/Cargo.lock b/corpus/02-component-instr-combined/Cargo.lock deleted file mode 100644 index b06a795a..00000000 --- a/corpus/02-component-instr-combined/Cargo.lock +++ /dev/null @@ -1,25 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "bitflags" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" - -[[package]] -name = "combined" -version = "0.1.0" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wit-bindgen" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b76f1d099678b4f69402a421e888bbe71bf20320c2f3f3565d0e7484dbe5bc20" -dependencies = [ - "bitflags", -] diff --git a/corpus/02-component-instr-combined/Cargo.toml b/corpus/02-component-instr-combined/Cargo.toml deleted file mode 100644 index 575d0ddc..00000000 --- a/corpus/02-component-instr-combined/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "combined" -version = "0.1.0" -edition = "2021" - -[package.metadata.component] -package = "component:combined" - -[package.metadata.component.dependencies] -"component:component-instr-component" = { path = "../01-component-instr-component/target/wasm32-wasi/debug/component_instr_component.wasm" } - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"]} \ No newline at end of file diff --git a/corpus/02-component-instr-combined/config.yml b/corpus/02-component-instr-combined/config.yml deleted file mode 100644 index e59933c3..00000000 --- a/corpus/02-component-instr-combined/config.yml +++ /dev/null @@ -1,4 +0,0 @@ -dependencies: - component-instr-component: - path: ../01-component-instr-component/target/wasm32-wasi/debug/component_instr_component.wasm - diff --git a/corpus/02-component-instr-combined/src/bindings.rs b/corpus/02-component-instr-combined/src/bindings.rs deleted file mode 100644 index 7ad2b179..00000000 --- a/corpus/02-component-instr-combined/src/bindings.rs +++ /dev/null @@ -1,49 +0,0 @@ -// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! - -#[allow(clippy::all)] -pub mod component_instr_component { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = super::__link_section; - #[allow(unused_unsafe, clippy::all)] - pub fn hello_world() -> wit_bindgen::rt::string::String{ - - #[allow(unused_imports)] - use wit_bindgen::rt::{alloc, vec::Vec, string::String}; - unsafe { - - #[repr(align(4))] - struct RetArea([u8; 8]); - let mut ret_area = ::core::mem::MaybeUninit::::uninit(); - let ptr0 = ret_area.as_mut_ptr() as i32; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component-instr-component")] - extern "C" { - #[link_name = "hello-world"] - fn wit_import(_: i32, ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, ){ unreachable!() } - wit_import(ptr0); - let l1 = *((ptr0 + 0) as *const i32); - let l2 = *((ptr0 + 4) as *const i32); - let len3 = l2 as usize; - let bytes3 = Vec::from_raw_parts(l1 as *mut _, len3, len3); - wit_bindgen::rt::string_lift(bytes3) - } - } - -} - - -#[cfg(target_arch = "wasm32")] -#[link_section = "component-type:combined"] -#[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 219] = [3, 0, 8, 99, 111, 109, 98, 105, 110, 101, 100, 0, 97, 115, 109, 13, 0, 1, 0, 7, 92, 1, 65, 2, 1, 65, 2, 1, 66, 2, 1, 64, 0, 0, 115, 4, 0, 11, 104, 101, 108, 108, 111, 45, 119, 111, 114, 108, 100, 1, 0, 3, 0, 25, 99, 111, 109, 112, 111, 110, 101, 110, 116, 45, 105, 110, 115, 116, 114, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 5, 0, 4, 1, 27, 99, 111, 109, 112, 111, 110, 101, 110, 116, 58, 99, 111, 109, 98, 105, 110, 101, 100, 47, 99, 111, 109, 98, 105, 110, 101, 100, 4, 0, 11, 14, 1, 0, 8, 99, 111, 109, 98, 105, 110, 101, 100, 3, 0, 0, 0, 16, 12, 112, 97, 99, 107, 97, 103, 101, 45, 100, 111, 99, 115, 0, 123, 125, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112, 114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101, 110, 116, 6, 48, 46, 49, 56, 46, 50, 16, 119, 105, 116, 45, 98, 105, 110, 100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 54, 46, 48]; - -#[inline(never)] -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn __link_section() {} diff --git a/corpus/02-component-instr-combined/src/main.rs b/corpus/02-component-instr-combined/src/main.rs deleted file mode 100644 index b9e007a3..00000000 --- a/corpus/02-component-instr-combined/src/main.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod bindings; - -use bindings::component_instr_component::hello_world; - -fn main() { - println!("calling component: \"{}\"", hello_world()); -} diff --git a/justfile b/justfile index 02f3c8bc..677681f8 100644 --- a/justfile +++ b/justfile @@ -4,33 +4,5 @@ _help: _edit: @$EDITOR {{justfile()}} -build_wit: - wasm-tools component wit wit/observe.wit -w -o wit/observe.wasm - mkdir -p corpus/01-component-instr-component/wit/deps/observe - cp wit/observe.wit corpus/01-component-instr-component/wit/deps/observe/ - -component_demo: - #!/bin/bash - set -eou pipefail - (cd corpus/00-component-instr-command; cargo component build) - (cd rust/; cargo run -F component-model --example otel-stdout-components ../corpus/00-component-instr-command/target/wasm32-wasi/debug/component-instr-command.wasm) - -component_demo_2: - #!/bin/bash - set -eou pipefail - (cd corpus/01-component-instr-component; cargo component build) - (cd corpus/02-component-instr-combined; - - cargo component build - wasm-tools compose -c config.yml target/wasm32-wasi/debug/combined.wasm -o target/wasm32-wasi/debug/final.wasm - ) - (cd rust/; cargo run -F component-model --example otel-stdout-components ../corpus/02-component-instr-combined/target/wasm32-wasi/debug/final.wasm) - -component_demo_3: - #!/bin/bash - set -eou pipefail - (cd corpus/01-component-instr-component; cargo component build) - (cd rust/; cargo run -F component-model --example reactor-hello-world-otel-stdout-components ../corpus/01-component-instr-component/target/wasm32-wasi/debug/component_instr_component.wasm) - local_instr instr_path="../wasm-instr/wasm-instr": for i in test/*.c.wasm; do o=${i%.wasm}; {{ instr_path }} $i > $o.instr.wasm; done diff --git a/rust/Cargo.toml b/rust/Cargo.toml index adc4bfe9..4cf0a5d6 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -3,9 +3,6 @@ name = "dylibso-observe-sdk" version = "0.1.0" edition = "2021" -[features] -component-model = ["wasmtime/component-model", "wasmtime/async"] - [lib] # not testing docs because the prost generated structs fail doctest = false diff --git a/rust/examples/otel-stdout-components.rs b/rust/examples/otel-stdout-components.rs deleted file mode 100644 index 679fae2b..00000000 --- a/rust/examples/otel-stdout-components.rs +++ /dev/null @@ -1,88 +0,0 @@ -use dylibso_observe_sdk::{ - adapter::otelstdout::OtelStdoutAdapter, - context::component::{ObserveSdk, ObserveSdkView}, -}; - -use wasmtime_wasi::preview2::{ResourceTable, WasiCtx, WasiView}; - -struct State { - table: ResourceTable, - wasi_ctx: WasiCtx, - observe_sdk: ObserveSdk, -} - -impl WasiView for State { - fn table(&self) -> &ResourceTable { - &self.table - } - - fn table_mut(&mut self) -> &mut ResourceTable { - &mut self.table - } - - fn ctx(&self) -> &WasiCtx { - &self.wasi_ctx - } - - fn ctx_mut(&mut self) -> &mut WasiCtx { - &mut self.wasi_ctx - } -} - -impl ObserveSdkView for State { - fn sdk_mut(&mut self) -> &mut ObserveSdk { - &mut self.observe_sdk - } -} - -#[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 mut config = wasmtime::Config::new(); - - config.async_support(true); - config.wasm_component_model(true); - - // Create instance - let engine = wasmtime::Engine::new(&config)?; - let component = wasmtime::component::Component::new(&engine, &data)?; - - let table = ResourceTable::new(); - - // Setup WASI - let wasi_ctx = wasmtime_wasi::preview2::WasiCtxBuilder::new() - .inherit_stdio() - .args(&args.clone()) - .build(); - - let mut linker = wasmtime::component::Linker::new(&engine); - - let adapter = OtelStdoutAdapter::create(); - let observe_sdk = adapter.build_observe_sdk(&data, Default::default())?; - - let state = State { - table, - wasi_ctx, - observe_sdk, - }; - let mut store = wasmtime::Store::new(&engine, state); - - wasmtime_wasi::preview2::command::add_to_linker(&mut linker)?; - dylibso_observe_sdk::context::component::add_to_linker(&mut linker)?; - - // get the function and run it, the events pop into the queue as the function is running - let (cmd, _) = wasmtime_wasi::preview2::command::Command::instantiate_async( - &mut store, &component, &linker, - ) - .await?; - let run = cmd.wasi_cli_run(); - if let Err(()) = run.call_run(&mut store).await? { - println!("encountered error"); - }; - - let state = store.into_data(); - state.observe_sdk.shutdown().await?; - - Ok(()) -} diff --git a/rust/examples/reactor-hello-world-otel-stdout-components.rs b/rust/examples/reactor-hello-world-otel-stdout-components.rs deleted file mode 100644 index b2780be5..00000000 --- a/rust/examples/reactor-hello-world-otel-stdout-components.rs +++ /dev/null @@ -1,88 +0,0 @@ -use dylibso_observe_sdk::{ - adapter::otelstdout::OtelStdoutAdapter, - context::component::{ObserveSdk, ObserveSdkView}, -}; - -use wasmtime_wasi::preview2::{ResourceTable, WasiCtx, WasiView}; - -struct State { - table: ResourceTable, - wasi_ctx: WasiCtx, - observe_sdk: ObserveSdk, -} - -impl WasiView for State { - fn table(&self) -> &ResourceTable { - &self.table - } - - fn table_mut(&mut self) -> &mut ResourceTable { - &mut self.table - } - - fn ctx(&self) -> &WasiCtx { - &self.wasi_ctx - } - - fn ctx_mut(&mut self) -> &mut WasiCtx { - &mut self.wasi_ctx - } -} - -impl ObserveSdkView for State { - fn sdk_mut(&mut self) -> &mut ObserveSdk { - &mut self.observe_sdk - } -} - -wasmtime::component::bindgen!({path: "../corpus/01-component-instr-component/wit", async: true}); - -#[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 mut config = wasmtime::Config::new(); - - config.async_support(true); - config.wasm_component_model(true); - - // Create instance - let engine = wasmtime::Engine::new(&config)?; - let component = wasmtime::component::Component::new(&engine, &data)?; - - let table = ResourceTable::new(); - - // Setup WASI - let wasi_ctx = wasmtime_wasi::preview2::WasiCtxBuilder::new() - .inherit_stdio() - .args(&args.clone()) - .build(); - - let mut linker = wasmtime::component::Linker::new(&engine); - - let adapter = OtelStdoutAdapter::create(); - let observe_sdk = adapter.build_observe_sdk(&data, Default::default())?; - - let state = State { - table, - wasi_ctx, - observe_sdk, - }; - let mut store = wasmtime::Store::new(&engine, state); - wasmtime_wasi::preview2::command::add_to_linker(&mut linker)?; - - dylibso_observe_sdk::context::component::add_to_linker(&mut linker)?; - - let (component_instr_component, _instance) = - Example::instantiate_async(&mut store, &component, &linker).await?; - - match component_instr_component.call_hello_world(&mut store).await { - Ok(result) => println!("hello_world: {:?}", result), - _ => println!("encountered error"), - }; - - let state = store.into_data(); - state.observe_sdk.shutdown().await?; - - Ok(()) -} diff --git a/rust/src/adapter/mod.rs b/rust/src/adapter/mod.rs index 3cc18498..7106108a 100644 --- a/rust/src/adapter/mod.rs +++ b/rust/src/adapter/mod.rs @@ -14,12 +14,6 @@ use crate::{ Event, TelemetryId, TraceEvent, }; -#[cfg(feature = "component-model")] -use crate::{ - context::{component::ObserveSdk, InstrumentationContext}, - wasm_instr::WasmInstrInfo, -}; - use self::datadog::DatadogMetadata; pub mod datadog; @@ -189,21 +183,6 @@ impl AdapterHandle { Ok(TraceContext { collector }) } - #[cfg(feature = "component-model")] - /// Given a slice representing a Wasm component and [`Options`], create an [`ObserveSdk`]. - pub fn build_observe_sdk(&self, data: &[u8], options: Options) -> Result { - let (ctx, collector, collector_rx) = InstrumentationContext::new(options); - let wasm_instr_info = WasmInstrInfo::new(data)?; - - Collector::start(collector_rx, self.clone()); - let bindings = ObserveSdk { - instr_context: ctx, - wasm_instr_info, - trace_context: TraceContext { collector }, - }; - Ok(bindings) - } - pub fn try_send(&self, event: TraceEvent) -> Result<()> { self.adapter_tx.try_send(event)?; Ok(()) diff --git a/rust/src/context.rs b/rust/src/context.rs index 4d8eda52..7f847805 100644 --- a/rust/src/context.rs +++ b/rust/src/context.rs @@ -548,263 +548,3 @@ pub fn add_to_linker( linker.allow_unknown_exports(true); Ok((events_tx, events_rx)) } - -#[cfg(feature = "component-model")] -pub mod component { - //! # Component Model Observability - //! - //! Available via `feature = "component-model"`. - //! - //! This module exposes host observability capabilities to the component model. By using this - //! module, hosts can provide support for guest components which depend on the - //! `dylibso:observe/api` and `dylibso:observe/instrument` WIT interfaces. - //! - //! ## Integrating - //! - //! Like Wasmtime's [`wasmtime_wasi::preview2`] module, Observability support involves three steps: - //! - //! 1. Adding an [`ObserveSdk`] member to your host's [`wasmtime::Store`] state struct. - //! 2. Providing access to that member by implementing [`ObserveSdkView`] for your host's state - //! struct. - //! 3. Adding the host bindings to the [`wasmtime::component::Linker`]. - //! - //! ```rust - //! use dylibso_observe_sdk::context::component::{ ObserveSdk, ObserveSdkView }; - //! - //! struct MyState { - //! // Step 1: add a member to your state... - //! sdk: ObserveSdk, - //! } - //! - //! // Step 2: implement the view trait for your state. - //! impl ObserveSdkView for MyState { - //! fn sdk_mut(&mut self) -> &mut ObserveSdk { - //! &mut self.sdk - //! } - //! } - //! ``` - //! - //! Once you've completed step 1 and 2, you can add host bindings like so: - //! - //! ```no_run - //! # use dylibso_observe_sdk::context::component::{ ObserveSdk, ObserveSdkView }; - //! # struct MyState { - //! # sdk: ObserveSdk, - //! # } - //! # impl ObserveSdkView for MyState { - //! # fn sdk_mut(&mut self) -> &mut ObserveSdk { - //! # &mut self.sdk - //! # } - //! # } - //! # #[tokio::main] - //! # async fn main() -> anyhow::Result<()> { - //! use dylibso_observe_sdk::adapter::otelstdout::OtelStdoutAdapter; - //! - //! // (Setup: Read a Wasm module from stdin.) - //! let args: Vec<_> = std::env::args().skip(1).collect(); - //! let wasm_data = std::fs::read(&args[0])?; - //! let mut config = wasmtime::Config::new(); - //! - //! config.async_support(true); - //! config.wasm_component_model(true); - //! let engine = wasmtime::Engine::new(&config)?; - //! let component = wasmtime::component::Component::new(&engine, &wasm_data)?; - //! let mut linker = wasmtime::component::Linker::new(&engine); - //! - //! // All adapters have component support, OtelStdoutAdapter just happens to be - //! // easiest to use as an example: - //! let adapter = OtelStdoutAdapter::create(); - //! - //! // Use the adapter to create observe_sdk bindings which you can then pass to your state. - //! let observe_sdk = adapter.build_observe_sdk(&wasm_data, Default::default())?; - //! - //! // Create your state and wrap it in a wasmtime::Store. - //! let state = MyState { - //! sdk: observe_sdk - //! }; - //! let mut store = wasmtime::Store::new(&engine, state); - //! - //! // ...Then add it to the linker. - //! dylibso_observe_sdk::context::component::add_to_linker(&mut linker)?; - //! - //! # let (cmd, _) = wasmtime_wasi::preview2::command::Command::instantiate_async(&mut store, &component, &linker).await?; - //! # let run = cmd.wasi_cli_run(); - //! // Once you're done with wasm, call `shutdown()`, which shuts down the collector associated - //! // with the Observe SDK. - //! let state = store.into_data(); - //! state.sdk.shutdown().await?; - //! # Ok(()) - //! # } - //! ``` - //! - //! To see an example integrating both Wasi preview 2 and the Observe SDK, see - //! `rust/examples/otel-stdout-components.rs` in the [observe sdk - //! repo](https://github.com/dylibso/observe-sdk/). - use crate::adapter::TraceContext; - - use super::*; - use wasmtime::component::Linker; - - /// Provide access to [`ObserveSdk`] from a [`wasmtime::Store`]'s inner object. - /// - /// ```rust - /// use dylibso_observe_sdk::context::component::{ ObserveSdk, ObserveSdkView }; - /// - /// struct MyState { - /// sdk: ObserveSdk, - /// } - /// - /// impl ObserveSdkView for MyState { - /// fn sdk_mut(&mut self) -> &mut ObserveSdk { - /// &mut self.sdk - /// } - /// } - /// ``` - pub trait ObserveSdkView { - fn sdk_mut(&mut self) -> &mut ObserveSdk; - } - - // Hide the bindgen-generated modules from rustdoc by using an "internal" module. - mod internal { - wasmtime::component::bindgen!({ - interfaces: r#" - import dylibso:observe/api; - import dylibso:observe/instrument; - "#, - path: "../wit", - async: false - }); - } - - use internal::dylibso::observe::api::{Host as ApiHost, LogLevel, MetricFormat}; - use internal::dylibso::observe::instrument::Host as InstrumentHost; - - /// A data structure backing ObserveSdk bindings: contains private information mapping - /// function ids to names and contexts for collector channels. - /// - /// Instantiate by calling - /// [`AdapterHandle::build_observe_sdk`](crate::adapter::AdapterHandle::build_observe_sdk) - /// using any adapter type: - /// - /// ```no_run - /// # use dylibso_observe_sdk::context::component::ObserveSdk; - /// use dylibso_observe_sdk::adapter::zipkin::ZipkinAdapter; - /// # fn main() -> anyhow::Result<()> { - /// let args: Vec<_> = std::env::args().skip(1).collect(); - /// let wasm_data = std::fs::read(&args[0])?; - /// let zipkin = ZipkinAdapter::create(); - /// - /// // NB: the ": ObserveSdk" type annotation here isn't necessary, it's just to indicate the - /// // return type. - /// let observe_sdk: ObserveSdk = zipkin.build_observe_sdk(&wasm_data, - /// Default::default()).unwrap(); - /// # Ok(()) - /// # } - /// ``` - pub struct ObserveSdk { - pub(crate) instr_context: Arc>, - pub(crate) wasm_instr_info: WasmInstrInfo, - pub(crate) trace_context: TraceContext, - } - - impl ObserveSdk { - /// Shut down the trace collector. Once the collector is shut down this instance - /// should no longer be used. `shutdown` may be called multiple times but will emit - /// warnings on subsequent calls. - pub async fn shutdown(&self) -> Result<()> { - self.trace_context.shutdown().await; - Ok(()) - } - } - - impl TryInto for MetricFormat { - type Error = anyhow::Error; - - fn try_into(self) -> std::result::Result { - #[allow(unreachable_patterns)] - match self { - MetricFormat::Statsd => Ok(super::MetricFormat::Statsd), - _ => bail!("Illegal metric format value"), - } - } - } - - impl ApiHost for ObserveSdk { - fn metric(&mut self, format: MetricFormat, name: Vec) -> wasmtime::Result<()> { - if let Ok(mut cont) = self.instr_context.lock() { - cont.metric(format.try_into()?, name.as_slice())?; - } - Ok(()) - } - - fn log(&mut self, level: LogLevel, msg: Vec) -> wasmtime::Result<()> { - if let Ok(mut cont) = self.instr_context.lock() { - cont.log_write(level as u8, msg.as_slice())?; - } - Ok(()) - } - - fn span_enter(&mut self, name: String) -> wasmtime::Result<()> { - if let Ok(mut cont) = self.instr_context.lock() { - cont.enter(0u32, Some(name.as_str()))?; - } - Ok(()) - } - - fn span_tags(&mut self, tags: String) -> wasmtime::Result<()> { - let tags: Vec = tags.split(',').map(|xs| xs.to_string()).collect(); - if let Ok(mut cont) = self.instr_context.lock() { - cont.span_tags(tags)?; - } - Ok(()) - } - - fn span_exit(&mut self) -> wasmtime::Result<()> { - if let Ok(mut cont) = self.instr_context.lock() { - cont.exit(0u32)?; - } - Ok(()) - } - } - - impl InstrumentHost for ObserveSdk { - fn memory_grow(&mut self, amount_in_pages: u32) -> wasmtime::Result<()> { - if let Ok(mut cont) = self.instr_context.lock() { - cont.allocate(amount_in_pages)?; - } - Ok(()) - } - - fn enter(&mut self, func_id: u32) -> wasmtime::Result<()> { - let printname = self.wasm_instr_info.function_names.get(&func_id); - if let Ok(mut cont) = self.instr_context.lock() { - cont.enter(func_id, printname.map(|x| x.as_str()))?; - } - Ok(()) - } - - fn exit(&mut self, func_id: u32) -> wasmtime::Result<()> { - if let Ok(mut cont) = self.instr_context.lock() { - cont.exit(func_id)?; - } - Ok(()) - } - } - - /// Make ObserveSdk host bindings available to the component model - /// [`wasmtime::component::Linker`]. Assumes that [`ObserveSdkView`] has been implemented to - /// map from the [`wasmtime::Store`] to an instance of [`ObserveSdk`]. - pub fn add_to_linker(linker: &mut Linker) -> Result<()> - where - T: ObserveSdkView + 'static, - { - internal::dylibso::observe::api::add_to_linker(linker, |s| -> &mut ObserveSdk { - s.sdk_mut() - })?; - - internal::dylibso::observe::instrument::add_to_linker(linker, |s| -> &mut ObserveSdk { - s.sdk_mut() - })?; - Ok(()) - } -} diff --git a/wit/observe.wasm b/wit/observe.wasm deleted file mode 100644 index 735a3c9ea0bb6c5d9f4752098237ee57bfb6a87e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 449 zcmZ9HO-{ow5QS$FJ0blMmDq6ym%@@&;U$8}Y5c_j|OQQwTn=iwuq#ck*0QJ9az;sfa<-`%d(9roIF~i&acAMa^JqDFvg% z$pXaGR+8-E zqBM&#uXu;Y{6%hegFj8ehT(&rdecV#>f1=+Oiyw!9M%m&nWx;p?w7A~6TFw!k1h%0 z#2`D0(`>i4WPO-K7yJbwQ}tE!qjU7n6kYcJMCSRfqk{VgLLCi+Fcy diff --git a/wit/observe.wit b/wit/observe.wit deleted file mode 100644 index bcf4a862..00000000 --- a/wit/observe.wit +++ /dev/null @@ -1,27 +0,0 @@ -package dylibso:observe; - -interface api { - enum log-level { - error, - warn, - info, - debug, - trace - } - - enum metric-format { - statsd, - } - - metric: func(format: metric-format, name: list); - log: func(level: log-level, msg: list); - span-enter: func(name: string); - span-tags: func(tags: string); - span-exit: func(); -} - -interface instrument { - memory-grow: func(amount-in-pages: u32); - enter: func(func-id: u32); - exit: func(func-id: u32); -}