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
Hello,
I'm experiencing weird behavior of setGroup and flush methods of Amplitude NodeJS client in case when batching is enabled (useBatch: true).
Expected Behavior
I expect one of the following:
setGroup method sends request and resolves returned promise without any delays
Calling flush after setGroup sends all the requests and resolves all pending promises, including promise from setGroup
Current Behavior
The setGroup method waits until flush interval is over and only then it resolves the promise. The timeout is 10000ms by default (managed by flushIntervalMillis configuration option).
Manual calling of flush() doesn't help either. I've tried the following, no success:
I digged into amplitude code and found this line - it's being reached when context.timeout is 0, and this is hardcoded when invoking method via execute() (see here).
What I'm trying to do here is to ensure the group is assigned in the amplitude before any other events both in service backend and frontend are sent. Thus, I need to wait until setGroup request is executed, and it might take up to 10 seconds which is not a satisfactory delay for a backend entrypoint. I've decreased flushIntervalMillis option to 1000ms for now and it helped (well, sort of), but it doesn't look like a proper solution.
Possible Solution
Please confirm if this is a bug or it's an expected behavior.
Environment
JS SDK Version: "@amplitude/analytics-node": "^1.0.1", actual installed version is 1.0.1. I'm pretty sure all behavior described above exists in latest version, according to what I can see in current master branch.
Installation Method: yarn
Browser and Version: Node 18.19.0
The text was updated successfully, but these errors were encountered:
Hello,
I'm experiencing weird behavior of
setGroup
andflush
methods of Amplitude NodeJS client in case when batching is enabled (useBatch: true
).Expected Behavior
I expect one of the following:
setGroup
method sends request and resolves returned promise without any delaysflush
aftersetGroup
sends all the requests and resolves all pending promises, including promise fromsetGroup
Current Behavior
The
setGroup
method waits until flush interval is over and only then it resolves the promise. The timeout is 10000ms by default (managed byflushIntervalMillis
configuration option).Manual calling of
flush()
doesn't help either. I've tried the following, no success:const promise = ampli.setGroup(...); await Promise.all([ampli.flush(), promise]);
const promise = ampli.setGroup(...); ampli.flush(); await promise;
I digged into amplitude code and found this line - it's being reached when
context.timeout
is 0, and this is hardcoded when invoking method viaexecute()
(see here).What I'm trying to do here is to ensure the group is assigned in the amplitude before any other events both in service backend and frontend are sent. Thus, I need to wait until
setGroup
request is executed, and it might take up to 10 seconds which is not a satisfactory delay for a backend entrypoint. I've decreasedflushIntervalMillis
option to 1000ms for now and it helped (well, sort of), but it doesn't look like a proper solution.Possible Solution
Please confirm if this is a bug or it's an expected behavior.
Environment
"@amplitude/analytics-node": "^1.0.1"
, actual installed version is1.0.1
. I'm pretty sure all behavior described above exists in latest version, according to what I can see in current master branch.The text was updated successfully, but these errors were encountered: