designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

🙏 Workaround for MFE Logging Supporting Sourcemaps

Open CallMeHK opened this issue 1 year ago • 3 comments

What are you trying to achieve and what is your issue? Please describe. Looking for a workaround for microfrontend applications - I'm not looking for a way to do this natively, just a way to send logs as a different service/version tag than the init configuration.

Describe the solution you'd like I would like to be able to override the init configuration for one window.DD_LOGS.logger.log invocation. If the logger has been initialized with service a and version 2.2.2, overwriting the services via:

window.DD_LOGS.logger.log('test', { service: 'b', version: '1.11.111' }, 'error')

Results in a log with Event attributes {service: 'b', version: '1.11.111'}, but it still has the tags {service: 'a', version: '2.2.2'}. I need the tags to change so that source maps will work for errors. it would be great if i could access the internal properties via something similar to:

{
  ...window.DD_LOGS.logger.log('test', { service: 'b', version: '1.11.111' }, 'error'),
  service: 'b', version: '1.11.111'
}.log('test', { ... }, 'error')

until datadog has adequate MFE support.

Describe alternatives you've considered I dont know what alternatives i have until DD has some form of MFE support. Thanks!

CallMeHK avatar Feb 01 '24 20:02 CallMeHK

Hi @CallMeHK,

Indeed, we don't have an adequate support for MFE for now and we don't allow to overwrite tags at SDK level. However, similarly to the error stack remapping, it should be possible to use a log remapper to overwrite service/version tags with service/version attributes.

bcaudan avatar Feb 02 '24 10:02 bcaudan

Hi @bcaudan

I know that with RUM, we can override the service thanks to startView. On the other hand, in our app we'd like to only use browser-logs to keep it lightweight.

Do you think that in the future we'll be able to have the same functionality as startView with createLogger, for MFEs? As the workaround, is it a good idea to remap the logger name to service name?

aviv-akhansari avatar Apr 15 '24 09:04 aviv-akhansari