(input: TelemetryEventInput)
| 138 | * @returns Resolves when the event has been handed off to the logger transport. |
| 139 | */ |
| 140 | export async function emitEvent(input: TelemetryEventInput): Promise<void> { |
| 141 | try { |
| 142 | const geo = input.ipAddress ? getGeolocation(input.ipAddress) : {} |
| 143 | |
| 144 | const event: TelemetryEventOutput = { |
| 145 | eventId: uuidv4(), |
| 146 | timestamp: new Date().toISOString(), |
| 147 | version: await getAppVersion(), |
| 148 | category: input.category, |
| 149 | eventType: input.eventType, |
| 150 | actionType: input.actionType, |
| 151 | userId: input.userId, |
| 152 | orgId: input.orgId, |
| 153 | resourceId: input.resourceId, |
| 154 | ipAddress: input.ipAddress ? sanitizeIPAddress(input.ipAddress) : undefined, |
| 155 | countryCode: geo.countryCode, |
| 156 | region: geo.region, |
| 157 | result: input.result, |
| 158 | metadata: input.metadata ? sanitizeAuditMetadata(input.metadata) : undefined |
| 159 | } |
| 160 | |
| 161 | auditLogger.log({ level: 'info', message: event.eventType, ...event }) |
| 162 | } catch (error) { |
| 163 | logger.error(`Failed to emit event: ${error}`) |
| 164 | } |
| 165 | } |
no test coverage detected