Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Custom end time for span (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
skjindal93 authored and draffensperger committed Jun 8, 2019
1 parent 82464ed commit 1aea7a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/opencensus-web-core/src/trace/model/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
6 changes: 6 additions & 0 deletions packages/opencensus-web-core/test/test-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1aea7a9

Please sign in to comment.