From 975b2e0da2735d94aec1e29a5bf1183c137a4592 Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Fri, 5 Apr 2024 12:53:07 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20beforeSend=20type=20defini?= =?UTF-8?q?tion=20for=20logs=20(#2686)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/logs/src/domain/configuration.ts | 3 ++- packages/logs/src/domain/lifeCycle.ts | 11 ++--------- .../src/domain/networkError/networkErrorCollection.ts | 3 ++- packages/logs/src/domainContext.types.ts | 9 +++++++++ 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 packages/logs/src/domainContext.types.ts diff --git a/packages/logs/src/domain/configuration.ts b/packages/logs/src/domain/configuration.ts index 9b2a06e393..07271b94ce 100644 --- a/packages/logs/src/domain/configuration.ts +++ b/packages/logs/src/domain/configuration.ts @@ -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 diff --git a/packages/logs/src/domain/lifeCycle.ts b/packages/logs/src/domain/lifeCycle.ts index 35f452abc2..64ac8ee6b2 100644 --- a/packages/logs/src/domain/lifeCycle.ts +++ b/packages/logs/src/domain/lifeCycle.ts @@ -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, @@ -16,14 +17,6 @@ interface LifeCycleEventMap { export const LifeCycle = AbstractLifeCycle export type LifeCycle = AbstractLifeCycle -export type LogsEventDomainContext = T extends typeof ErrorSource.NETWORK - ? NetworkLogsEventDomainContext - : never - -type NetworkLogsEventDomainContext = { - isAborted: boolean -} - export interface RawLogsEventCollectedData { rawLogsEvent: E messageContext?: object diff --git a/packages/logs/src/domain/networkError/networkErrorCollection.ts b/packages/logs/src/domain/networkError/networkErrorCollection.ts index 2913921fa1..ab2a4cb409 100644 --- a/packages/logs/src/domain/networkError/networkErrorCollection.ts +++ b/packages/logs/src/domain/networkError/networkErrorCollection.ts @@ -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' diff --git a/packages/logs/src/domainContext.types.ts b/packages/logs/src/domainContext.types.ts new file mode 100644 index 0000000000..1df7217422 --- /dev/null +++ b/packages/logs/src/domainContext.types.ts @@ -0,0 +1,9 @@ +import type { ErrorSource } from '@datadog/browser-core' + +export type LogsEventDomainContext = T extends typeof ErrorSource.NETWORK + ? NetworkLogsEventDomainContext + : never + +export type NetworkLogsEventDomainContext = { + isAborted: boolean +}