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

🐛 fix beforeSend type definition for logs #2686

Merged
merged 3 commits into from
Apr 5, 2024
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
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
}