Skip to content

Commit

Permalink
🐛 fix beforeSend type definition for logs (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-lebeau authored Apr 5, 2024
1 parent c47a9dd commit 975b2e0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/logs/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
objectValues,
} from '@datadog/browser-core'
import type { LogsEvent } from '../logsEvent.types'
import type { LogsEventDomainContext } from '../domainContext.types'

export interface LogsInitConfiguration extends InitConfiguration {
beforeSend?: ((event: LogsEvent) => boolean) | undefined
beforeSend?: ((event: LogsEvent, context: LogsEventDomainContext) => boolean) | undefined
forwardErrorsToLogs?: boolean | undefined
forwardConsoleLogs?: ConsoleApiName[] | 'all' | undefined
forwardReports?: RawReportType[] | 'all' | undefined
Expand Down
11 changes: 2 additions & 9 deletions packages/logs/src/domain/lifeCycle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AbstractLifeCycle } from '@datadog/browser-core'
import type { Context, ErrorSource } from '@datadog/browser-core'
import type { Context } from '@datadog/browser-core'
import type { LogsEvent } from '../logsEvent.types'
import type { CommonContext, RawLogsEvent } from '../rawLogsEvent.types'
import type { LogsEventDomainContext } from '../domainContext.types'

export const enum LifeCycleEventType {
RAW_LOG_COLLECTED,
Expand All @@ -16,14 +17,6 @@ interface LifeCycleEventMap {
export const LifeCycle = AbstractLifeCycle<LifeCycleEventMap>
export type LifeCycle = AbstractLifeCycle<LifeCycleEventMap>

export type LogsEventDomainContext<T extends ErrorSource> = T extends typeof ErrorSource.NETWORK
? NetworkLogsEventDomainContext
: never

type NetworkLogsEventDomainContext = {
isAborted: boolean
}

export interface RawLogsEventCollectedData<E extends RawLogsEvent = RawLogsEvent> {
rawLogsEvent: E
messageContext?: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
isServerError,
} from '@datadog/browser-core'
import type { LogsConfiguration } from '../configuration'
import type { LifeCycle, LogsEventDomainContext } from '../lifeCycle'
import type { LifeCycle } from '../lifeCycle'
import type { LogsEventDomainContext } from '../../domainContext.types'
import { LifeCycleEventType } from '../lifeCycle'
import { StatusType } from '../logger'

Expand Down
9 changes: 9 additions & 0 deletions packages/logs/src/domainContext.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ErrorSource } from '@datadog/browser-core'

export type LogsEventDomainContext<T extends ErrorSource = any> = T extends typeof ErrorSource.NETWORK
? NetworkLogsEventDomainContext
: never

export type NetworkLogsEventDomainContext = {
isAborted: boolean
}

0 comments on commit 975b2e0

Please sign in to comment.