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

call without distinctId (mandatory) causes ~10 second timeout awaiting client.shtdown() #253

Open
tompscanlan opened this issue Aug 26, 2024 · 2 comments
Labels
enhancement New feature or request nodejs

Comments

@tompscanlan
Copy link

Bug description

In a minimal node http handler I'm trying to use posthog to capture an event. I'm seeing a ~10 second timeout when waiting on the call to shutdown(). At that time I get the error:

ERROR Error while shutting down PostHog HTTP error while fetching PostHog: 400

at retriable (node_modules/posthog-core/src/index.ts:652:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at retriable (node_modules/posthog-core/src/utils.ts:27:19)
at PostHog.fetchWithRetry (node_modules/posthog-core/src/index.ts:635:12)
at PostHog._flush (node_modules/posthog-core/src/index.ts:605:7)

How to reproduce

This is a Nuxt project backend running in node 20.


export default defineEventHandler(async (event) => {
  let posthogClient = null;
  try {
    posthogClient = new PostHog("XXXXX", {
      host: "https://us.i.posthog.com",
    });
    posthogClient.on("error", (err) => {
        console.error("PostHog had an error!", err);
    });
    posthogClient.debug();
    posthogClient.capture({
      distinct_id: "test",
      event: "Test",
    });
  
  } catch (error) {
    console.error("Error initializing PostHog:", error);
  } finally {
  await posthogClient.shutdown();
}
});

Additional context

I'm not to posthog, and a hack front end person, I'm probably doing something silly. I'm getting front end events through just fine using the same api key, but none of my backend events show up, and get a 400 instead.

@tompscanlan tompscanlan added the bug Something isn't working label Aug 26, 2024
@tompscanlan
Copy link
Author

Oh... I may have found it... distinctId is different than distinct_id. Changing that seems to make the difference.

Chalking this one up to new-userism... might want a documentation change at https://posthog.com/docs/libraries/node. Seeing distinct_id so much stuck in my head. maybe switch up the examples, or get smarter users.

@benjackwhite
Copy link
Collaborator

I think we should perhaps do some more SDK side alerting if a call happens without a distinctId. Most people seem to use Typescript which indicates this immediately but we may need to rely on that less...

@marandaneto marandaneto added enhancement New feature or request and removed bug Something isn't working labels Sep 3, 2024
@marandaneto marandaneto changed the title ~10 second timeout awaiting client.shtdown() call without distinctId (mandatory) causes ~10 second timeout awaiting client.shtdown() Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request nodejs
Projects
None yet
Development

No branches or pull requests

8 participants
@benjackwhite @tompscanlan @marandaneto and others