You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Initializing Humanloop SDK fails with SemVer TypeError in Cloudflare Worker #10
When initializing Humanloop SDK in a Cloudflare Worker, I encounter the following error: [ERROR] service core:user:: Uncaught TypeError: Invalid Version: in SemVer
Environment:
pnpm version: 10.0.0
node version: 20.16.0
humanloop version: ^0.8.10
Runtime: Cloudflare Worker
Steps to Reproduce:
1- Install Humanloop SDK in a Cloudflare Worker
2- Initialize the SDK
3- Observe the error in the logs
Steps Taken to Resolve:
Deleted node_modules, pnpm-lock.yaml, pnpm cache and reinstalled dependencies
Screenshot:
Any guidance on resolving this issue would be appreciated. Let me know if you need any further details.
Hi @HananAlsawy, after a little digging I've found this occurs because @opentelemetry/sdk-trace-node checks against process.version, which doesn't exist in the CF Worker runtime. We'll consider supporting Cloudflare Workers better, but I can't promise anything soon.
For now, I was able to get around this constraint by patching the globalThis and assigning a mock version to process. Hopefully unnecessary once open-telemetry/opentelemetry-js#5306 is released.
You can try something similar to the following in your worker def and let me know if it works.
import{HumanloopClient}from"humanloop";typeEnv={HUMANLOOP_API_KEY: string;}exportdefault{asyncfetch(request,env,ctx): Promise<Response>{// Hack to fix @opentelemetry/sdk-trace-node// Create a mock process object if it doesn't existconstglobalProcess=(globalThisasany).process||{};// Set the version property if it doesn't existif(!globalProcess.version){globalProcess.version='16.0.0';}// Assign the mock process object to global scope(globalThisasany).process=globalProcess;constclient=newHumanloopClient({apiKey: env.HUMANLOOP_API_KEY});returnnewResponse(JSON.stringify(awaitclient.directories.list()));},}satisfiesExportedHandler<Env>;
Activity
jamesbaskerville commentedon Feb 19, 2025
Hi @HananAlsawy, after a little digging I've found this occurs because
@opentelemetry/sdk-trace-nodechecks againstprocess.version, which doesn't exist in the CF Worker runtime. We'll consider supporting Cloudflare Workers better, but I can't promise anything soon.For now, I was able to get around this constraint by patching the globalThis and assigning a mock version to process. Hopefully unnecessary once open-telemetry/opentelemetry-js#5306 is released.
You can try something similar to the following in your worker def and let me know if it works.
yorjaggy commentedon Feb 24, 2025
I was having the same issue, thanks for that workaround @jamesbaskerville it works for me 🚀