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

Missing events even with flush #119

Open
florian-milky opened this issue Jun 1, 2021 · 3 comments
Open

Missing events even with flush #119

florian-milky opened this issue Jun 1, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@florian-milky
Copy link

florian-milky commented Jun 1, 2021

I am sending 13 events with logEvent at about the same time. I am not awaiting for the promise to resolve.
Later on, before I terminate, I am calling flush to make sure all events will be sent.
Flush responds with status: skipped

Expected Behavior

All events to be logged

Current Behavior

Some events are missing, sometimes 1, sometimes more

Possible Solution

I guess the request is still ongoing for some events?
But flush doesn't know about it?

Steps to Reproduce

Environment

  • SDK Version: 1.6.1
  • Node version: 12.x
@florian-milky florian-milky added the bug Something isn't working label Jun 1, 2021
@florian-milky florian-milky changed the title Missing events Missing events even with flush Jun 1, 2021
@ajhorst
Copy link
Contributor

ajhorst commented Jun 1, 2021

@florian-milky the skipped response should only be returned from flush when either there are no events remaining in the buffer, or the events are incorrectly formatted. Where is it that you notice events are missing? Are they not appearing on the amplitude website?

@florian-milky
Copy link
Author

florian-milky commented Jun 2, 2021

@ajhorst I log something when the promise is resolved. So I got like 13 logs right before logEvents, and then I got like 10 logs that the promise resolved. Then the flush resolves. On amplitude website I don't see events that didn't resolve.

Now I double checked my code and I realise I expected the promise to throw because I was using async/await, but when I stopped awaiting the logEvent, I removed the async/await which means the code is not gonna throw anymore 🤦

So I'll handle that and check why it is throwing.

Edit: ok obviously not fully awake yet. I am not catching the promise so it would fail if one of them would throw.

Some code:

export function logMetrics(metrics) {
  console.log(`Logging metrics into ${process.env.ENV}`, metrics);
  client
    .logEvent({
      event_type: 'KPI - PageSpeed audit',
      user_id: 'lambda-lighthouse',
      event_properties: metrics,
    })
    .then((r) => console.log(metrics.target, r));
}
   // iterating over some stuff and calling logMetrics

    console.log('Flushing metrics to amplitude');
    const response = await flush();
    if (response.status !== Status.Success && response.status !== Status.Skipped) {
      console.log('Flushing did not work', response);
      throw new Error('Could not flush amplitude events');
    }
    console.log('Flushed', { status: response.status });

@ajhorst
Copy link
Contributor

ajhorst commented Jun 2, 2021

@florian-milky are there any console warnings in your browser window when you try this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants