Closed gajus closed 6 months ago
@PostHog/team-feature-success
Same issue in Node.js v22
Looks like we are getting error:
Your personalApiKey is invalid. Are you sure you're not using your Project API key?
Since this is node.js version dependent, I am going to guess it is a bug in Node.js SDK.
thanks for the report @gajus , I seemingly can't reproduce with either 21.7 or 22. Can you double check please the API keys are correct?
Just raised related product feedback, as there is no good way to validate if the key I have is valid.
Okay, no, it is def node version specific.
Generated new set of tokens.
Works with 21.6. Breaks with 21.7 and 22.
weird, thanks 🤔 , let me try generating some new tokens too.
While I am not certain what's the cause of the issue, I was able to fix it by overriding the fetch client with got
.
this.client = new PostHog(apiToken, {
featureFlagsPollingInterval: 120_000,
fetch: async (url, options) => {
const response = await get(url, {
body: options.body,
headers: options.headers,
method: options.method.toUpperCase() as 'GET',
signal: options.signal,
});
return {
json: async () => JSON.parse(response.body),
status: response.statusCode,
text: async () => response.body,
};
},
fetchRetryCount: 0,
personalApiKey,
preloadFeatureFlags: false,
requestTimeout: 5_000, // Measured in milliseconds. Defaults to 30_000 (30 seconds)
});
We tracked down the issue to be due to how @sentry/node v8 beta version instruments code in v21.6+.
Thank you for helping to troubleshoot.
Bug description
This code path produces an empty object in Node.js 21.7, but works as expected in Node.js 21.6.
Replicated the same behavior with
posthog-node@4.0.1
andposthog-node@3.2.0
How to reproduce
Related sub-libraries
Additional context
This issue is in relation to Contra account.
https://us.posthog.com/project/8910