fix(buffer): fixed issues with buffer

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-18 23:45:05 +02:00
parent 3ca3079737
commit e18ac4d79e
2 changed files with 13 additions and 4 deletions

View File

@@ -103,6 +103,7 @@ export class RedisBuffer<T> {
await cb();
} catch (e) {
this.logger.error(`#2 Failed to execute callback: ${cb.name}`, e);
throw e;
}
}
}
@@ -160,14 +161,14 @@ export class RedisBuffer<T> {
},
);
} catch (error) {
this.logger.error('Failed to process queue while flushing buffer}:', {
this.logger.error('Failed to process queue while flushing buffer', {
error,
queueSize: items.length,
});
if (items.length > 0) {
// Add back items to keep
this.logger.debug('Adding all items back to buffer');
this.logger.info('Adding all items back to buffer');
await getRedisCache().lpush(
this.getKey(),
...items.map((item) => JSON.stringify(item)),

View File

@@ -67,7 +67,8 @@ export class EventBuffer extends RedisBuffer<BufferType> {
return (
lastEvent.project_id === item.project_id &&
lastEvent.profile_id === item.profile_id &&
lastEvent.path !== ''
lastEvent.path !== '' &&
lastEvent.name === 'screen_view'
);
});
@@ -76,6 +77,10 @@ export class EventBuffer extends RedisBuffer<BufferType> {
item,
);
if (!event.properties) {
event.properties = {};
}
if (lastEventWithData) {
event.properties.__properties_from = lastEventWithData.id;
}
@@ -114,9 +119,12 @@ export class EventBuffer extends RedisBuffer<BufferType> {
new Date(item.created_at).getTime();
const event = {
...item,
properties: {
...(item?.properties || {}),
__duration_from: nextScreenView.id,
},
duration,
};
event.properties.__duration_from = nextScreenView.id;
toInsert.add(event);
} else if (hasSessionEnd) {
// push last event in session if we have a session_end event