From d349a12e8ffc97ec7fcd46da94508a3a3f68c583 Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Tue, 10 Oct 2023 10:49:30 -0700 Subject: [PATCH] feat(component): rename core module imports Align core module instrumentation naming with component model naming. This relies on corresponding (undeployed, private) changes to the observe http api [1]. [1]: https://github.com/dylibso/wasm-instr/pull/69 --- go/trace_ctx.go | 18 +++++++-------- js/src/lib/collectors/span/mod.ts | 8 +++---- observe-api/README.md | 10 ++++----- observe-api/c/observe_api.c | 12 +++++----- observe-api/c/observe_api.h | 23 ++++++++++--------- rust/src/context.rs | 36 ++++++++++++++---------------- test/kitchensink.c | 8 +++---- test/kitchensink.c.instr.wasm | Bin 65180 -> 65180 bytes test/nested.c.instr.wasm | Bin 63468 -> 63468 bytes test/test.c.instr.wasm | Bin 64285 -> 64285 bytes wit/observe.wasm | Bin 874 -> 808 bytes wit/observe.wit | 6 ++--- 12 files changed, 60 insertions(+), 61 deletions(-) diff --git a/go/trace_ctx.go b/go/trace_ctx.go index 4ad3bc80..4b8e021a 100644 --- a/go/trace_ctx.go +++ b/go/trace_ctx.go @@ -75,19 +75,19 @@ func (t *TraceCtx) withListener(ctx context.Context) context.Context { // Should only be called once. func (t *TraceCtx) init(ctx context.Context, r wazero.Runtime) error { ctx = t.withListener(ctx) - observe := r.NewHostModuleBuilder("dylibso_observe") - functions := observe.NewFunctionBuilder() + instrument := r.NewHostModuleBuilder("dylibso:observe/instrument") + instrFunctions := instrument.NewFunctionBuilder() - functions.WithFunc(func(ctx context.Context, m api.Module, i int32) { + instrFunctions.WithFunc(func(ctx context.Context, m api.Module, i int32) { start := time.Now() ev := <-t.raw if ev.Kind != RawEnter { log.Println("Expected event", RawEnter, "but got", ev.Kind) } t.pushFunction(CallEvent{Raw: []RawEvent{ev}, Time: start}) - }).Export("instrument_enter") + }).Export("instrument-enter") - functions.WithFunc(func(ctx context.Context, i int32) { + instrFunctions.WithFunc(func(ctx context.Context, i int32) { end := time.Now() ev := <-t.raw if ev.Kind != RawExit { @@ -140,9 +140,9 @@ func (t *TraceCtx) init(ctx context.Context, r wazero.Runtime) error { t.pushFunction(f) } - }).Export("instrument_exit") + }).Export("instrument-exit") - functions.WithFunc(func(ctx context.Context, amt int32) { + instrFunctions.WithFunc(func(ctx context.Context, amt int32) { ev := <-t.raw if ev.Kind != RawMemoryGrow { log.Println("Expected event", MemoryGrow, "but got", ev.Kind) @@ -167,9 +167,9 @@ func (t *TraceCtx) init(ctx context.Context, r wazero.Runtime) error { } fn.within = append(fn.within, event) t.pushFunction(fn) - }).Export("instrument_memory_grow") + }).Export("instrument-memory-grow") - _, err := observe.Instantiate(ctx) + _, err := instrument.Instantiate(ctx) if err != nil { return err } diff --git a/js/src/lib/collectors/span/mod.ts b/js/src/lib/collectors/span/mod.ts index 4d49ce66..01560c29 100644 --- a/js/src/lib/collectors/span/mod.ts +++ b/js/src/lib/collectors/span/mod.ts @@ -114,10 +114,10 @@ export class SpanCollector implements Collector { public getImportObject(): WebAssembly.Imports { return { - "dylibso_observe": { - "instrument_enter": this.instrumentEnter, - "instrument_exit": this.instrumentExit, - "instrument_memory_grow": this.instrumentMemoryGrow, + "dylibso:observe/instrument": { + "instrument-enter": this.instrumentEnter, + "instrument-exit": this.instrumentExit, + "instrument-memory-grow": this.instrumentMemoryGrow, }, }; } diff --git a/observe-api/README.md b/observe-api/README.md index 4ba8d56d..0f0735e4 100644 --- a/observe-api/README.md +++ b/observe-api/README.md @@ -5,11 +5,11 @@ This acts as the contract between the host and the guest layer. All data flows i from the guest to the host. Most of these APIs are simply ways to pass observability data as strings to the host layer. -* `dylibso_observe.metric(i32, i64, i32)` -* `dylibso_observe.log(i32, i64, i32)` -* `dylibso_observe.span_enter(i64, i32)` -* `dylibso_observe.span_exit()` -* `dylibso_observe.span_tags(i64, i32)` +* `dylibso:observe/api.metric(i32, i32, i32)` +* `dylibso:observe/api.log(i32, i32, i32)` +* `dylibso:observe/api.span-enter(i32, i32)` +* `dylibso:observe/api.span-exit()` +* `dylibso:observe/api.span-tags(i32, i32)` Ideally, you will not call this API layer directly but instead use language specific bindings to call them. And for end users, eventually, open source observability clients will *export* data to this layer. diff --git a/observe-api/c/observe_api.c b/observe-api/c/observe_api.c index a83ed326..ae61d8bd 100644 --- a/observe-api/c/observe_api.c +++ b/observe-api/c/observe_api.c @@ -5,22 +5,22 @@ #include void span_enter(const char *name) { - const uint64_t uint64_ptr = (uint64_t)name; + const uint32_t uint32_ptr = (uint32_t)name; const uint32_t uint32_length = strlen(name); - _span_enter(uint64_ptr, uint32_length); + _span_enter(uint32_ptr, uint32_length); } void span_exit(void) { _span_exit(); } void metric(const char *metric) { - const uint64_t uint64_ptr = (uint64_t)metric; + const uint32_t uint32_ptr = (uint32_t)metric; const uint32_t uint32_length = strlen(metric); - _metric(1, uint64_ptr, uint32_length); + _metric(1, uint32_ptr, uint32_length); } void write_log(const enum DO_LOG_LEVEL level, const char *msg) { - const uint64_t uint64_ptr = (uint64_t)msg; + const uint32_t uint32_ptr = (uint32_t)msg; const uint32_t uint32_length = strlen(msg); const uint32_t uint32_level = level; - _log(uint32_level, uint64_ptr, uint32_length); + _log(uint32_level, uint32_ptr, uint32_length); } diff --git a/observe-api/c/observe_api.h b/observe-api/c/observe_api.h index 42b34451..e28318d3 100644 --- a/observe-api/c/observe_api.h +++ b/observe-api/c/observe_api.h @@ -5,20 +5,21 @@ #define IMPORT(a, b) __attribute__((import_module(a), import_name(b))) -IMPORT("dylibso_observe", "metric") -extern void _metric(uint32_t, uint64_t, uint32_t); -IMPORT("dylibso_observe", "log") -extern void _log(uint32_t, uint64_t, uint32_t); -IMPORT("dylibso_observe", "span_enter") -extern void _span_enter(uint64_t, uint32_t); -IMPORT("dylibso_observe", "span_exit") +IMPORT("dylibso:observe/api", "metric") +extern void _metric(uint32_t, uint32_t, uint32_t); +IMPORT("dylibso:observe/api", "log") +extern void _log(uint32_t, uint32_t, uint32_t); +IMPORT("dylibso:observe/api", "span-enter") +extern void _span_enter(uint32_t, uint32_t); +IMPORT("dylibso:observe/api", "span-exit") extern void _span_exit(void); enum DO_LOG_LEVEL { - DO_LL_ERROR = 1, - DO_LL_WARN = 2, - DO_LL_INFO = 3, - DO_LL_DEBUG = 4 + DO_LL_ERROR = 0, + DO_LL_WARN = 1, + DO_LL_INFO = 2, + DO_LL_DEBUG = 3, + DO_LL_TRACE = 4 }; void span_enter(const char *name); diff --git a/rust/src/context.rs b/rust/src/context.rs index 9d758c72..1e84cb29 100644 --- a/rust/src/context.rs +++ b/rust/src/context.rs @@ -420,8 +420,6 @@ pub(crate) fn span_exit( Ok(()) } -const MODULE_NAME: &str = "dylibso_observe"; - type EventChannel = (Sender, Receiver); /// Link observability import functions required by instrumented wasm code @@ -444,8 +442,8 @@ pub fn add_to_linker( let enter_ctx = ctx.clone(); linker.func_new( - MODULE_NAME, - "instrument_enter", + "dylibso:observe/instrument", + "enter", t.clone(), move |_caller: Caller, params, results| { instrument_enter( @@ -459,16 +457,16 @@ pub fn add_to_linker( let exit_ctx = ctx.clone(); linker.func_new( - MODULE_NAME, - "instrument_exit", + "dylibso:observe/instrument", + "exit", t.clone(), move |_caller, params, results| instrument_exit(params, results, exit_ctx.clone()), )?; let grow_ctx = ctx.clone(); linker.func_new( - MODULE_NAME, - "instrument_memory_grow", + "dylibso:observe/instrument", + "memory-grow", t, move |_caller, params, results| instrument_memory_grow(params, results, grow_ctx.clone()), )?; @@ -477,8 +475,8 @@ pub fn add_to_linker( let span_enter_ctx = ctx.clone(); linker.func_new( - MODULE_NAME, - "span_enter", + "dylibso:observe/api", + "span-enter", t.clone(), move |mut caller, params, results| { span_enter(&mut caller, params, results, span_enter_ctx.clone()) @@ -487,8 +485,8 @@ pub fn add_to_linker( let span_tags_ctx = ctx.clone(); linker.func_new( - MODULE_NAME, - "span_tags", + "dylibso:observe/api", + "span-tags", t.clone(), move |mut caller, params, results| { span_tags(&mut caller, params, results, span_tags_ctx.clone()) @@ -499,14 +497,14 @@ pub fn add_to_linker( let metric_ctx = ctx.clone(); linker.func_new( - MODULE_NAME, + "dylibso:observe/api", "metric", t.clone(), move |mut caller, params, results| metric(&mut caller, params, results, metric_ctx.clone()), )?; let log_ctx = ctx.clone(); - linker.func_new(MODULE_NAME, "log", t, move |mut caller, params, results| { + linker.func_new("dylibso:observe/api", "log", t, move |mut caller, params, results| { log_write(&mut caller, params, results, log_ctx.clone()) })?; @@ -514,8 +512,8 @@ pub fn add_to_linker( let span_exit_ctx = ctx.clone(); linker.func_new( - MODULE_NAME, - "span_exit", + "dylibso:observe/api", + "span-exit", t, move |mut caller, params, results| { span_exit(&mut caller, params, results, span_exit_ctx.clone()) @@ -598,14 +596,14 @@ pub mod component { } impl InstrumentHost for ObserveSdkBindings { - fn instrument_memory_grow(&mut self, amount_in_pages: u32) -> wasmtime::Result<()> { + 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 instrument_enter(&mut self, func_id: u32) -> wasmtime::Result<()> { + 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()))?; @@ -613,7 +611,7 @@ pub mod component { Ok(()) } - fn instrument_exit(&mut self, func_id: u32) -> wasmtime::Result<()> { + fn exit(&mut self, func_id: u32) -> wasmtime::Result<()> { if let Ok(mut cont) = self.instr_context.lock() { cont.exit(func_id)?; } diff --git a/test/kitchensink.c b/test/kitchensink.c index a89e18a1..1116564e 100644 --- a/test/kitchensink.c +++ b/test/kitchensink.c @@ -5,13 +5,13 @@ #define IMPORT(a, b) __attribute__((import_module(a), import_name(b))) -IMPORT("dylibso_observe", "metric") +IMPORT("dylibso:observe/api", "metric") extern void metric(uint32_t, uint64_t, uint32_t); -IMPORT("dylibso_observe", "log") +IMPORT("dylibso:observe/api", "log") extern void log_write(uint32_t, uint64_t, uint32_t); -IMPORT("dylibso_observe", "span_enter") +IMPORT("dylibso:observe/api", "span-enter") extern void span_enter(uint64_t, uint32_t); -IMPORT("dylibso_observe", "span_exit") extern void span_exit(); +IMPORT("dylibso:observe/api", "span-exit") extern void span_exit(); void custom_span_enter(char name[]) { uintptr_t ptr = (uintptr_t)name; diff --git a/test/kitchensink.c.instr.wasm b/test/kitchensink.c.instr.wasm index 8de14111f536be900d639686d785d8e9a2e77dac..0607f08e9afb589280f939df1720efb3a4b41898 100644 GIT binary patch delta 148 zcmbR9mwC=#<_%{U>!ngEb25{P^R4oeic^cqQuQ-keEb25{P^W*cAic^cqQUx;eic5-0b5rw5;(<7|h=B!N2|u!u zip&yB6=Fy#a#M5jiz?&Oi}K4ESeUJ?n3!0YfPj&inT3UsWwJMu7bD~5X-sT?0Ly1H APyhe` diff --git a/test/nested.c.instr.wasm b/test/nested.c.instr.wasm index 7f74c7f74fc6729799cd6ea5e0f9d04ae2393dd5..285bad647f369d863fd09264a7287ac3dc70d4ec 100644 GIT binary patch delta 125 zcmaF!p83st<_(dI8B!^gIhjet`BwQ!#i>PQsrs3D#U(|hxv6<2tU#Pv#K3|_2}^24 cW(i&u+_|Z_`9+nwlMgb+GqP+}WIFv706H@;kN^Mx delta 125 zcmaF!p83st<_(dI8T=`gIhjet`SJNl#i>PQsREgK#U(|hxv6<2@j#qf#K3~CgdbT+ fMP>=63Na)Vxv9DNMV0ZB4>HCxGHzC6I{g&@a+5K> diff --git a/test/test.c.instr.wasm b/test/test.c.instr.wasm index 5be1d3a2ba506e475001d997ed9ffd67c387356a..38320fb421a815a5bfbad2963991be7f03a1dc4e 100644 GIT binary patch delta 125 zcmbRHjd|`j<_(dI8B!^gIhjet`BwQ!#i>PQsrs3D#U(|hxv6<2tU#Pv#K4S42}^24 cW(i&u+_|Z_`9+nwlMgb+FtTixWBUIC0Q6-rF8}}l delta 125 zcmbRHjd|`j<_(dI8T=`gIhjet`SJNl#i>PQsREgK#U(|hxv6<2@j#qf#K4TMgdbT+ fMP>=63Na)Vxv9DNMV0ZB4>HCuGH#Y*`u_s}EYvYw diff --git a/wit/observe.wasm b/wit/observe.wasm index 818f4385f7c9f69f5101ae7ec393bf8d42a75c20..425f85b21b28ac29ef08dac77eceb2fe5989b303 100644 GIT binary patch delta 71 zcmaFGwt|h1A+b1@mw}Oi{QxVYBirOg#&Z+z7&CHD?qibWW=+j2NiAYzWMN?09LcE3 Lh$%ez4AVRSj|36X delta 148 zcmZ3%_KJ;