designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

Inconsistent behaviour regarding `forwardErrorsToLogs` and `forwardConsoleLogs`

Open OliverJAsh opened this issue 9 months ago • 3 comments
trafficstars

When forwardErrorsToLogs is explicitly enabled, Datadog adds error to forwardConsoleLogs:

https://github.com/DataDog/browser-sdk/blob/8df6ac0bfaa1a98f5b2cb89c2379ec7e8c3692a8/packages/logs/src/domain/configuration.ts#L85-L87

However, if forwardErrorsToLogs is omitted from the initial configuration, this does not happen, despite the fact that forwardErrorsToLogs defaults to true.

Datadog should behave the same when forwardErrorsToLogs: true and when forwardErrorsToLogs is omitted.

OliverJAsh avatar Feb 20 '25 07:02 OliverJAsh

On a related note, I find it strange that you can't opt out from console.error collection when forwardErrorsToLogs is specified, even when specifying forwardConsoleLogs: [].

(When specifying forwardErrorsToLogs: true, forwardConsoleLogs: [], Datadog will resolve the configuration as forwardConsoleLogs: ['error'].)

OliverJAsh avatar Feb 20 '25 08:02 OliverJAsh

Ooh thank you for pointing that out, we'll fix this.

On a related note, I find it strange that you can't opt out from console.error collection when forwardErrorsToLogs is specified, even when specifying forwardConsoleLogs: [].

I agree that it can be a bit confusing. To understand why it works like this: at first we had forwardErrorsToLogs but not forwardConsoleLogs. At this time, when setting forwardErrorsToLogs: true, we considered console.error to be errors, and forwarded it as such. When we introduced forwardConsoleLogs, we didn't want to change the forwardErrorsToLogs behavior, this is why we enforce forwarding error logs in this case. I hope it makes sense.

Thank you for the feedback, we might consider clarifying things in a future major version.

BenoitZugmeyer avatar Feb 20 '25 16:02 BenoitZugmeyer

It seems to be a breaking change: users using the default configuration would start collecting console.error without opting in. I added this to the list to do for our next major.

BenoitZugmeyer avatar Feb 20 '25 16:02 BenoitZugmeyer