From 694dc8d164a1d9ad56b6359582df260ca4674656 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Fri, 23 Jun 2023 15:22:36 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20Typings:=20consistent=20beforeSe?= =?UTF-8?q?nd=20return=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/logs/src/domain/assembly.spec.ts | 16 ++++++++++ packages/logs/src/domain/configuration.ts | 2 +- packages/rum-core/src/domain/assembly.spec.ts | 32 +++++++++++++++++++ packages/rum-core/src/domain/configuration.ts | 2 +- test/e2e/scenario/logs.scenario.ts | 1 + test/e2e/scenario/rum/init.scenario.ts | 2 ++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/logs/src/domain/assembly.spec.ts b/packages/logs/src/domain/assembly.spec.ts index 5b233d2ad2..d0c2108f91 100644 --- a/packages/logs/src/domain/assembly.spec.ts +++ b/packages/logs/src/domain/assembly.spec.ts @@ -73,6 +73,22 @@ describe('startLogsAssembly', () => { serverLogs = [] }) + it('should send if beforeSend returned true', () => { + beforeSend = () => true + lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, { + rawLogsEvent: DEFAULT_MESSAGE, + }) + expect(serverLogs.length).toEqual(1) + }) + + it('should send if beforeSend returned undefined', () => { + beforeSend = () => undefined + lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, { + rawLogsEvent: DEFAULT_MESSAGE, + }) + expect(serverLogs.length).toEqual(1) + }) + it('should not send if beforeSend returned false', () => { beforeSend = () => false lifeCycle.notify(LifeCycleEventType.RAW_LOG_COLLECTED, { diff --git a/packages/logs/src/domain/configuration.ts b/packages/logs/src/domain/configuration.ts index f554913101..f2c8959f71 100644 --- a/packages/logs/src/domain/configuration.ts +++ b/packages/logs/src/domain/configuration.ts @@ -14,7 +14,7 @@ import { import type { LogsEvent } from '../logsEvent.types' export interface LogsInitConfiguration extends InitConfiguration { - beforeSend?: ((event: LogsEvent) => void | boolean) | undefined + beforeSend?: ((event: LogsEvent) => boolean) | undefined forwardErrorsToLogs?: boolean | undefined forwardConsoleLogs?: ConsoleApiName[] | 'all' | undefined forwardReports?: RawReportType[] | 'all' | undefined diff --git a/packages/rum-core/src/domain/assembly.spec.ts b/packages/rum-core/src/domain/assembly.spec.ts index fcfcc287cc..95272060b5 100644 --- a/packages/rum-core/src/domain/assembly.spec.ts +++ b/packages/rum-core/src/domain/assembly.spec.ts @@ -329,6 +329,38 @@ describe('rum assembly', () => { expect(displaySpy).toHaveBeenCalledWith("Can't dismiss view events using beforeSend!") }) }) + + it('should not dismiss when true is returned', () => { + const { lifeCycle } = setupBuilder + .withConfiguration({ + beforeSend: () => true, + }) + .build() + + notifyRawRumEvent(lifeCycle, { + rawRumEvent: createRawRumEvent(RumEventType.ACTION, { + view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' }, + }), + }) + + expect(serverRumEvents.length).toBe(1) + }) + + it('should not dismiss when undefined is returned', () => { + const { lifeCycle } = setupBuilder + .withConfiguration({ + beforeSend: () => undefined, + }) + .build() + + notifyRawRumEvent(lifeCycle, { + rawRumEvent: createRawRumEvent(RumEventType.ACTION, { + view: { id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' }, + }), + }) + + expect(serverRumEvents.length).toBe(1) + }) }) describe('rum context', () => { diff --git a/packages/rum-core/src/domain/configuration.ts b/packages/rum-core/src/domain/configuration.ts index eba13ac2c4..413e1b049c 100644 --- a/packages/rum-core/src/domain/configuration.ts +++ b/packages/rum-core/src/domain/configuration.ts @@ -19,7 +19,7 @@ import type { PropagatorType, TracingOption } from './tracing/tracer.types' export interface RumInitConfiguration extends InitConfiguration { // global options applicationId: string - beforeSend?: ((event: RumEvent, context: RumEventDomainContext) => void | boolean) | undefined + beforeSend?: ((event: RumEvent, context: RumEventDomainContext) => boolean) | undefined excludedActivityUrls?: MatchOption[] | undefined // tracing options diff --git a/test/e2e/scenario/logs.scenario.ts b/test/e2e/scenario/logs.scenario.ts index 0f247954d2..fdf9e7716a 100644 --- a/test/e2e/scenario/logs.scenario.ts +++ b/test/e2e/scenario/logs.scenario.ts @@ -159,6 +159,7 @@ describe('logs', () => { .withLogs({ beforeSend: (event) => { event.foo = 'bar' + return true }, }) .run(async ({ serverEvents }) => { diff --git a/test/e2e/scenario/rum/init.scenario.ts b/test/e2e/scenario/rum/init.scenario.ts index 7a44e334b8..846a34a630 100644 --- a/test/e2e/scenario/rum/init.scenario.ts +++ b/test/e2e/scenario/rum/init.scenario.ts @@ -110,6 +110,7 @@ describe('beforeSend', () => { .withRum({ beforeSend: (event: any) => { event.context!.foo = 'bar' + return true }, }) .withRumSlim() @@ -126,6 +127,7 @@ describe('beforeSend', () => { .withRum({ beforeSend: (event) => { event.context = { foo: 'bar' } + return true }, }) .withRumSlim()