designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

define createLogger API

Open eloytoro opened this issue 10 months ago • 2 comments

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

eloytoro avatar Jan 15 '25 08:01 eloytoro

Codecov Report

Attention: Patch coverage is 60.86957% with 9 lines in your changes missing coverage. Please review.

Project coverage is 93.58%. Comparing base (4623045) to head (c9898cb).

Files with missing lines Patch % Lines
packages/rum-core/src/boot/rumPublicApi.ts 60.86% 9 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3286      +/-   ##
==========================================
- Coverage   93.68%   93.58%   -0.10%     
==========================================
  Files         288      288              
  Lines        7611     7634      +23     
  Branches     1735     1738       +3     
==========================================
+ Hits         7130     7144      +14     
- Misses        481      490       +9     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Jan 15 '25 08:01 codecov-commenter

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 145.29 KiB 145.91 KiB 634 B +0.43%
Logs 51.09 KiB 51.09 KiB 0 B 0.00%
Rum Slim 104.08 KiB 104.61 KiB 536 B +0.50%
Worker 24.50 KiB 24.50 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
addglobalcontext 0.002 0.002 -0.000
addaction 0.052 0.035 -0.017
addtiming 0.001 0.001 0.000
adderror 0.089 0.047 -0.042
startstopsessionreplayrecording 0.012 0.011 -0.001
startview 0.454 0.498 0.044
logmessage 0.026 0.021 -0.005
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 27.43 KiB 27.84 KiB 414 B
addaction 53.85 KiB 56.10 KiB 2.25 KiB
addtiming 25.98 KiB 26.84 KiB 877 B
adderror 59.66 KiB 60.84 KiB 1.17 KiB
startstopsessionreplayrecording 25.93 KiB 26.33 KiB 414 B
startview 413.10 KiB 418.59 KiB 5.49 KiB
logmessage 59.05 KiB 58.92 KiB -133 B

🔗 RealWorld

cit-pr-commenter[bot] avatar Jan 15 '25 08:01 cit-pr-commenter[bot]