From 53f9c2ef5588186008829312a6e6f2bdb2cfea07 Mon Sep 17 00:00:00 2001 From: Gouri Hariharan Date: Wed, 28 Feb 2024 10:17:25 +0530 Subject: [PATCH] Added customMetric in Custom Event beacon (#27) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added customMetric * Update lib/customEvents.js with indent Co-authored-by: HUAI NAN ZHOU * Added e2e test for customMetric in weasel * e2e test for exponential value cm --------- Co-authored-by: Gouri-Hariharan1 <“gouri.hariharan1@ibm.com”> Co-authored-by: HUAI NAN ZHOU --- lib/customEvents.js | 6 +- lib/types.js | 10 ++- test/e2e/09_customEvents/customEvents.spec.js | 57 +++++++++++++++ .../09_customEvents/simpleEventReporting.html | 3 +- ...mpleEventReportingWithoutCustomMetric.html | 69 +++++++++++++++++++ 5 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 test/e2e/09_customEvents/simpleEventReportingWithoutCustomMetric.html diff --git a/lib/customEvents.js b/lib/customEvents.js index bee44f5b4..42afb119d 100644 --- a/lib/customEvents.js +++ b/lib/customEvents.js @@ -77,4 +77,8 @@ function enrich(beacon: CustomEventBeacon, opts: CustomEventOptions) { if (typeof opts['componentStack'] === 'string') { beacon['cs'] = opts['componentStack'].substring(0, 4096); } -} + + if (typeof opts['customMetric'] === 'number') { + beacon['cm'] = opts['customMetric']; + } +} diff --git a/lib/types.js b/lib/types.js index b8b0e569d..01fa7c2bf 100644 --- a/lib/types.js +++ b/lib/types.js @@ -241,7 +241,10 @@ export interface CustomEventBeacon extends Beacon { // error stack st: ?string, // component stack - cs: ?string + cs: ?string, + + //custom metric + cm: ?number } export interface CustomEventOptions { @@ -265,7 +268,10 @@ export interface CustomEventOptions { // to permit ['foo'] based access that doesn't break // when pushed through the Closure compiler - [key: string]: any + [key: string]: any, + + // Any custom metric that can be passed with custom events Example: 123.2342 + customMetric: ?number } export interface PageChangeBeacon extends Beacon { diff --git a/test/e2e/09_customEvents/customEvents.spec.js b/test/e2e/09_customEvents/customEvents.spec.js index ff80e1504..17cb3d354 100644 --- a/test/e2e/09_customEvents/customEvents.spec.js +++ b/test/e2e/09_customEvents/customEvents.spec.js @@ -35,6 +35,7 @@ describe('09_customEvents', () => { cexpect(beacon.m_kind).to.equal('experienced'); cexpect(beacon.m_state).to.equal('broken'); cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.equal('123.2342'); }); }); }); @@ -83,4 +84,60 @@ describe('09_customEvents', () => { }); }); }); + + describe('simpleEventReportingWithoutCustomMetric', () => { + beforeEach(() => { + browser.get(getE2ETestBaseUrl('09_customEvents/simpleEventReportingWithoutCustomMetric')); + }); + + it('must report custom events', () => { + return retry(() => { + return getBeacons().then(beacons => { + const pageLoadBeacon = expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('pl'); + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithEmptyCustomMetric'); + cexpect(beacon.e).to.match(/Testing 123/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.be.undefined; + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithNoCustomMetric'); + cexpect(beacon.e).to.match(/something wrong/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.be.undefined; + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithIncorrectCustomMetric'); + cexpect(beacon.e).to.match(/something wrong/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.be.undefined; + }); + + expectOneMatching(beacons, beacon => { + cexpect(beacon.ty).to.equal('cus'); + cexpect(beacon.ts).to.be.a('string'); + cexpect(beacon.n).to.equal('testWithExponentialCustomMetric(1e5)'); + cexpect(beacon.e).to.match(/something wrong/); + cexpect(beacon.pl).to.equal(pageLoadBeacon.t); + cexpect(beacon.bt).to.equal('ab87128a1ff99345'); + cexpect(beacon.cm).to.equal('100000'); + }); + }); + }); + }); + }); }); diff --git a/test/e2e/09_customEvents/simpleEventReporting.html b/test/e2e/09_customEvents/simpleEventReporting.html index 0aa90c2b6..f33478712 100644 --- a/test/e2e/09_customEvents/simpleEventReporting.html +++ b/test/e2e/09_customEvents/simpleEventReporting.html @@ -20,7 +20,8 @@ // one-off overwrite kind: 'experienced', state: 'broken' - } + }, + customMetric: 123.2342 }); diff --git a/test/e2e/09_customEvents/simpleEventReportingWithoutCustomMetric.html b/test/e2e/09_customEvents/simpleEventReportingWithoutCustomMetric.html new file mode 100644 index 000000000..c8eac9d77 --- /dev/null +++ b/test/e2e/09_customEvents/simpleEventReportingWithoutCustomMetric.html @@ -0,0 +1,69 @@ + + + + + error test + + + + + + + + + + simple event reporting without proper CustomMetric + +