| 1 | import type * as rum from "@distilled.cloud/aws/rum"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { AppMonitor } from "./AppMonitor.ts"; |
| 5 | |
| 6 | export interface PutRumEventsRequest extends Omit< |
| 7 | rum.PutRumEventsRequest, |
| 8 | "Id" | "AppMonitorDetails" |
| 9 | > { |
| 10 | /** |
| 11 | * Details of the app monitor sending the events. Defaults to the bound |
| 12 | * monitor's name and id. |
| 13 | */ |
| 14 | AppMonitorDetails?: rum.AppMonitorDetails; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Runtime binding for `rum:PutRumEvents` — send a batch of telemetry events |
| 19 | * from one user session to the bound {@link AppMonitor}'s data plane (the |
| 20 | * same operation the RUM web client uses); the monitor id and details are |
| 21 | * injected automatically. |
| 22 | * |
| 23 | * Provide `RUM.PutRumEventsHttp` on the hosting Lambda Function to satisfy |
| 24 | * the requirement. |
| 25 | * ### Sending RUM Events |
| 26 | * **Example:** Send a Session's Events Server-Side |
| 27 | * ```typescript |
| 28 | * // init — grants rum:PutRumEvents on the monitor |
| 29 | * const putRumEvents = yield* AWS.RUM.PutRumEvents(monitor); |
| 30 | * |
| 31 | * // runtime |
| 32 | * yield* putRumEvents({ |
| 33 | * BatchId: crypto.randomUUID(), |
| 34 | * UserDetails: { userId, sessionId }, |
| 35 | * RumEvents: [ |
| 36 | * { |
| 37 | * id: crypto.randomUUID(), |
| 38 | * timestamp: new Date(), |
| 39 | * type: "com.amazon.rum.session_start_event", |
| 40 | * details: "{}", |
| 41 | * }, |
| 42 | * ], |
| 43 | * }); |
| 44 | * ``` |
| 45 | * |
| 46 | * @binding |
| 47 | */ |
| 48 | export interface PutRumEvents extends Binding.Service< |
| 49 | PutRumEvents, |
| 50 | "AWS.RUM.PutRumEvents", |
| 51 | ( |
| 52 | monitor: AppMonitor, |
| 53 | ) => Effect.Effect< |
| 54 | ( |
| 55 | request: PutRumEventsRequest, |
| 56 | ) => Effect.Effect<rum.PutRumEventsResponse, rum.PutRumEventsError> |
| 57 | > |
| 58 | > {} |
| 59 | |
| 60 | export const PutRumEvents = Binding.Service<PutRumEvents>( |
| 61 | "AWS.RUM.PutRumEvents", |
| 62 | ); |