Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💥 [RUMF-1556] Typings: consistent beforeSend return type #2303

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/logs/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion packages/logs/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/e2e/scenario/logs.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ describe('logs', () => {
.withLogs({
beforeSend: (event) => {
event.foo = 'bar'
return true
},
})
.run(async ({ serverEvents }) => {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/scenario/rum/init.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('beforeSend', () => {
.withRum({
beforeSend: (event: any) => {
event.context!.foo = 'bar'
return true
},
})
.withRumSlim()
Expand All @@ -126,6 +127,7 @@ describe('beforeSend', () => {
.withRum({
beforeSend: (event) => {
event.context = { foo: 'bar' }
return true
},
})
.withRumSlim()
Expand Down