From 1aea7a95d7d93341b58345404fb0bcdfc7950683 Mon Sep 17 00:00:00 2001 From: Shubham Jindal Date: Sun, 9 Jun 2019 00:11:43 +0530 Subject: [PATCH] Custom end time for span (#95) --- packages/opencensus-web-core/src/trace/model/span.ts | 4 +++- packages/opencensus-web-core/test/test-span.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/opencensus-web-core/src/trace/model/span.ts b/packages/opencensus-web-core/src/trace/model/span.ts index 578208a7..bf61d215 100644 --- a/packages/opencensus-web-core/src/trace/model/span.ts +++ b/packages/opencensus-web-core/src/trace/model/span.ts @@ -261,7 +261,9 @@ export class Span implements webTypes.Span { /** Ends the span by setting `endTime` to now. */ end() { - this.endPerfTime = performance.now(); + if (this.endPerfTime === 0) { + this.endPerfTime = performance.now(); + } } /** Forces the span to end. Same as `end` for opencensus-web. */ diff --git a/packages/opencensus-web-core/test/test-span.ts b/packages/opencensus-web-core/test/test-span.ts index e37f5d2b..77ec1bb6 100644 --- a/packages/opencensus-web-core/test/test-span.ts +++ b/packages/opencensus-web-core/test/test-span.ts @@ -95,6 +95,12 @@ describe('Span', () => { expect(span.endPerfTime).toBe(33); }); + it('does not set endPerfTime when end is called, if endPerfTime is already set', () => { + span.endPerfTime = 22; + span.end(); + expect(span.endPerfTime).toBe(22); + }); + it('sets endPerfTime when truncate is called', () => { spyOn(performance, 'now').and.returnValue(77); span.truncate();