DataDog / browser-sdk

Datadog Browser SDK
Apache License 2.0
305 stars 134 forks source link

🙏 Workaround for MFE Logging Supporting Sourcemaps #2585

Open CallMeHK opened 9 months ago

CallMeHK commented 9 months ago

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!

bcaudan commented 9 months ago

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.

aviv-akhansari commented 6 months ago

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?