Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: JS SDK doesn't work in Cloudflare workers #150

Closed
mhmd-azeez opened this issue Dec 31, 2023 · 0 comments · Fixed by #151
Closed

bug: JS SDK doesn't work in Cloudflare workers #150

mhmd-azeez opened this issue Dec 31, 2023 · 0 comments · Fixed by #151

Comments

@mhmd-azeez
Copy link
Contributor

When trying to use the Observe SDK in cloudflare workers, there is an error:

[wrangler:err] TypeError: wasm.__wbindgen_add_to_stack_pointer is not a function
    at demangle (/home/nilslice/Projects/dylibso/workers-wasm-observability/node_modules/@dylibso/observe-sdk-honeycomb/dist/esm/index.js:2204:10)
    at null.<anonymous> (/home/nilslice/Projects/dylibso/workers-wasm-observability/node_modules/@dylibso/observe-sdk-honeycomb/dist/esm/index.js:2293:27)
    at [object Object]
    at SpanCollector.setNames (/home/nilslice/Projects/dylibso/workers-wasm-observability/node_modules/@dylibso/observe-sdk-honeycomb/dist/esm/index.js:2292:18)
    at HoneycombAdapter.start (/home/nilslice/Projects/dylibso/workers-wasm-observability/node_modules/@dylibso/observe-sdk-honeycomb/dist/esm/index.js:3898:21)
    at Object.fetch (/home/nilslice/Projects/dylibso/workers-wasm-observability/src/worker.ts:38:38)
    at async jsonError (/home/nilslice/Projects/dylibso/workers-wasm-observability/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:10)
[wrangler:inf] POST / 500 Internal Server Error (44ms)

From my investigation, it seems like Cloudlfare Workers doesn't support loading wasm modules from a Base64 string: cloudflare/workers-sdk#1366 (comment)

Which is what we are doing in the published npm pacakges: (look for var modsurfer_demangle_bg_default = __toBinary("AGFzbQEAAAABngEUYAJ/fwF).

Repro

https://github.com/dylibso/workers-wasm-observability

Workaround

I manually patched the problematic code like so:

import _wasm from "./demangle.wasm";
const _wasm_memory = new WebAssembly.Memory({ initial: 512 });
let importsObject = {
  env: { memory: _wasm_memory },
};

var wasm = new WebAssembly.Instance(_wasm, importsObject).exports;

Please note that we are using this pattern here too, but it seems like the build process encodes the binary during bundling. So we probably need to change the build process to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant