| 5 | * Get a session with defaults & applied sampling. |
| 6 | */ |
| 7 | export function makeSession(session: Partial<Session> & { sampled: Sampled }): Session { |
| 8 | const now = Date.now(); |
| 9 | const id = session.id || uuid4(); |
| 10 | // Note that this means we cannot set a started/lastActivity of `0`, but this should not be relevant outside of tests. |
| 11 | const started = session.started || now; |
| 12 | const lastActivity = session.lastActivity || now; |
| 13 | const segmentId = session.segmentId || 0; |
| 14 | const sampled = session.sampled; |
| 15 | const previousSessionId = session.previousSessionId; |
| 16 | const dirty = session.dirty || false; |
| 17 | |
| 18 | return { |
| 19 | id, |
| 20 | started, |
| 21 | lastActivity, |
| 22 | segmentId, |
| 23 | sampled, |
| 24 | previousSessionId, |
| 25 | dirty, |
| 26 | }; |
| 27 | } |