browser-sdk
                                
                                
                                
                                    browser-sdk copied to clipboard
                            
                            
                            
                        define createLogger API
Motivation
As of today there's no easy way to send RUM errors or actions that share the same tags, this is something that makes a lot of sense if you wish to define scopes for your application that all share the same information.
Changes
Introduce a new API that allows to specify a context to all addError and addAction calls from it
{
  // ... rum public api methods
  createReporter: (component: string, conf?: ReporterConfiguration) => Reporter
  // ...
}
export interface Reporter {
  addAction: RumPublicApi['addAction']
  addError: RumPublicApi['addError']
}
export interface ReporterConfiguration {
  context?: object
}
This new createReporter method returns an object that has the addError  and addAction methods that will add the context supplied to the reporter to any events sent from them
const reporter = createReporter('MyComponent', {
  context: { team: 'datadog' }
})
reporter.addError(new Error()) // will have context.team:datadog and context.component:MyComponent
Testing
Unit tests were defined