mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 17:15:40 -06:00
EchoSrv: Capture early events (#67977)
* feat: catch any events that were reported before the EchoSrv got initialised * fix: add events to the new echo service * chore: update comment * refactor: use `instanceof` to check if it is a FakeEchoSrv
This commit is contained in:
parent
1ff5170c83
commit
dce01441fc
@ -120,6 +120,13 @@ let singletonInstance: EchoSrv;
|
||||
* @internal
|
||||
*/
|
||||
export function setEchoSrv(instance: EchoSrv) {
|
||||
// Check if there were any events reported to the FakeEchoSrv (before the main EchoSrv was initialized), and track them
|
||||
if (singletonInstance instanceof FakeEchoSrv) {
|
||||
for (const item of singletonInstance.buffer) {
|
||||
instance.addEvent(item.event, item.meta);
|
||||
}
|
||||
}
|
||||
|
||||
singletonInstance = instance;
|
||||
}
|
||||
|
||||
@ -148,15 +155,15 @@ export const registerEchoBackend = (backend: EchoBackend) => {
|
||||
};
|
||||
|
||||
export class FakeEchoSrv implements EchoSrv {
|
||||
events: Array<Omit<EchoEvent, 'meta'>> = [];
|
||||
buffer: Array<{ event: Omit<EchoEvent, 'meta'>; meta?: {} | undefined }> = [];
|
||||
|
||||
flush(): void {
|
||||
this.events = [];
|
||||
this.buffer = [];
|
||||
}
|
||||
|
||||
addBackend(backend: EchoBackend): void {}
|
||||
|
||||
addEvent<T extends EchoEvent>(event: Omit<T, 'meta'>, meta?: {} | undefined): void {
|
||||
this.events.push(event);
|
||||
this.buffer.push({ event, meta });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user