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

Analytics not flushed in Node >= 18 #1069

Closed
dormesica opened this issue Apr 17, 2024 · 1 comment
Closed

Analytics not flushed in Node >= 18 #1069

dormesica opened this issue Apr 17, 2024 · 1 comment

Comments

@dormesica
Copy link

dormesica commented Apr 17, 2024

Hi

I'm using @segment/analytics-node to track analytics from my Lambda functions (runtime Node 18.x).
I recently noticed that by mistake some tests ran using Node 16 so I decided to fix that but when I upgraded to Node 18 (only changed the runtime for the tests), the tests that were meant to make sure analytics are sent started failing.
From my investigation it looks like the request itself was not sent, but event after I manually flushed (await client.flush()) the events the tests kept failing.

We use the following client configuration:

const analytics = new Analytics({
    flushAt: 1,
    writeKey: <api_key>
  });

We create a new client with each tracked event (tried to use a single client but that didn't help).
It's worth mentioning that I tried to sent flushInterval to 0 and it didn't help and I also tried waiting for 2.5 seconds after flushing and that did not help either.

Our tests fail on the line that checks that a request was sent to https://api.segment.io/v1/batch.

Would appreciate any help with that.
Thanks.

@silesky
Copy link
Contributor

silesky commented Apr 18, 2024

@dormesica If you look at at .github/ci.yaml, we have integration tests that run in node 18. Did you test manually with the Segment debugger?

Node 18 introduced a new fetch implementation. It could be that the bug is with the interception library: i.e. undici vs fetch: nock/nock#2183?

Our library, by default, uses the global fetch. Our tests actually monkey patch the global fetch with node-fetch to get around the nock interception issue.

@silesky silesky closed this as completed Apr 22, 2024
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

No branches or pull requests

2 participants