Skip to content
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
13 changes: 9 additions & 4 deletions packages/logs/src/domain/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,24 @@ describe('validateAndBuildLogsConfiguration', () => {
})

describe('forwardConsoleLogs', () => {
it('contains "error" when forwardErrorsToLogs is enabled', () => {
it('does not contain "error" when forwardConsoleLogs is disabled and forwardErrorsToLogs is explicitly enabled', () => {
expect(
validateAndBuildLogsConfiguration({ ...DEFAULT_INIT_CONFIGURATION, forwardErrorsToLogs: true })!
.forwardConsoleLogs
).toEqual(['error'])
).not.toContain('error')
})

it('does not contain "error" when forwardConsoleLogs is disabled and forwardErrorsToLogs is omitted', () => {
expect(validateAndBuildLogsConfiguration({ ...DEFAULT_INIT_CONFIGURATION })!.forwardConsoleLogs).not.toContain(
'error'
)
})

it('contains "error" once when both forwardErrorsToLogs and forwardConsoleLogs are enabled', () => {
it('contains "error" when forwardConsoleLogs contains "error"', () => {
expect(
validateAndBuildLogsConfiguration({
...DEFAULT_INIT_CONFIGURATION,
forwardConsoleLogs: ['error'],
forwardErrorsToLogs: true,
})!.forwardConsoleLogs
).toEqual(['error'])
})
Expand Down
9 changes: 4 additions & 5 deletions packages/logs/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ export interface LogsInitConfiguration extends InitConfiguration {
beforeSend?: LogsBeforeSend | undefined

/**
* Forward console.error logs, uncaught exceptions and network errors to Datadog.
* Forward uncaught exceptions and network errors to Datadog.
*
* To capture `console.error` calls, use {@link forwardConsoleLogs} with `"error"` (or `"all"`).
*
* @category Data Collection
* @defaultValue true
* @see forwardConsoleLogs
*/
forwardErrorsToLogs?: boolean | undefined

Expand Down Expand Up @@ -115,10 +118,6 @@ export function validateAndBuildLogsConfiguration(
return
}

if (initConfiguration.forwardErrorsToLogs && !forwardConsoleLogs.includes(ConsoleApiName.error)) {
forwardConsoleLogs.push(ConsoleApiName.error)
}

return {
forwardErrorsToLogs: initConfiguration.forwardErrorsToLogs !== false,
forwardConsoleLogs,
Expand Down
8 changes: 4 additions & 4 deletions packages/logs/src/domain/console/consoleCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('console collection', () => {

it('console error should have an error object defined', () => {
;({ stop: stopConsoleCollection } = startConsoleCollection(
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardErrorsToLogs: true })!,
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardConsoleLogs: ['error'] })!,
lifeCycle
))

Expand All @@ -80,7 +80,7 @@ describe('console collection', () => {

it('should retrieve fingerprint from console error', () => {
;({ stop: stopConsoleCollection } = startConsoleCollection(
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardErrorsToLogs: true })!,
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardConsoleLogs: ['error'] })!,
lifeCycle
))
interface DatadogError extends Error {
Expand All @@ -104,7 +104,7 @@ describe('console collection', () => {

it('should retrieve dd_context from console', () => {
;({ stop: stopConsoleCollection } = startConsoleCollection(
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardErrorsToLogs: true })!,
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardConsoleLogs: ['error'] })!,
lifeCycle
))
interface DatadogError extends Error {
Expand All @@ -121,7 +121,7 @@ describe('console collection', () => {

it('should retrieve causes from console error', () => {
;({ stop: stopConsoleCollection } = startConsoleCollection(
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardErrorsToLogs: true })!,
validateAndBuildLogsConfiguration({ ...initConfiguration, forwardConsoleLogs: ['error'] })!,
lifeCycle
))
const error = new Error('High level error') as ErrorWithCause
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/scenario/logs.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ test.describe('logs', () => {
})
})

createTest('send console errors')
.withLogs({ forwardErrorsToLogs: true })
createTest('send console errors with forwardConsoleLogs set to ["error"]')
.withLogs({ forwardConsoleLogs: ['error'] })
.run(async ({ intakeRegistry, flushEvents, page, withBrowserLogs }) => {
await page.evaluate(() => {
console.error('oh snap')
Expand Down
Loading