* Serializes a passed session object to a JSON object with a slightly different structure. * This is necessary because the Sentry backend requires a slightly different schema of a session * than the one the JS SDKs use internally. * * @param session the session to be converted * * @returns a J
(session: Session)
| 138 | * @returns a JSON object of the passed session |
| 139 | */ |
| 140 | function sessionToJSON(session: Session): SerializedSession { |
| 141 | return { |
| 142 | sid: `${session.sid}`, |
| 143 | init: session.init, |
| 144 | // Make sure that sec is converted to ms for date constructor |
| 145 | started: new Date(session.started * 1000).toISOString(), |
| 146 | timestamp: new Date(session.timestamp * 1000).toISOString(), |
| 147 | status: session.status, |
| 148 | errors: session.errors, |
| 149 | did: typeof session.did === 'number' || typeof session.did === 'string' ? `${session.did}` : undefined, |
| 150 | duration: session.duration, |
| 151 | abnormal_mechanism: session.abnormal_mechanism, |
| 152 | attrs: { |
| 153 | release: session.release, |
| 154 | environment: session.environment, |
| 155 | ip_address: session.ipAddress, |
| 156 | user_agent: session.userAgent, |
| 157 | }, |
| 158 | }; |
| 159 | } |