Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Add finished flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Onwukike Ibe committed Nov 11, 2016
1 parent fd8e7e4 commit a8f1ea3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Span {
_tags: Array<Tag>;
static _baggageHeaderCache: any;
_references: Array<Reference>
_finished: boolean;

constructor(tracer: any,
operationName: string,
Expand All @@ -54,6 +55,7 @@ export default class Span {
this._references = references;
this._logs = [];
this._tags = [];
this._finished = false;
}

get firstInProcess(): boolean {
Expand All @@ -64,6 +66,10 @@ export default class Span {
return this._operationName;
}

get finished(): boolean {
return this._finished;
}

static _getBaggageHeaderCache() {
if (!Span._baggageHeaderCache) {
Span._baggageHeaderCache = {};
Expand Down Expand Up @@ -154,11 +160,12 @@ export default class Span {
* @param {number} finishTime - The time on which this span finished.
**/
finish(finishTime: ?number): void {
if (this._duration !== undefined) {
if (this.finished) {
throw new Error('You can only call finish() on a span once.');
}

if (this._spanContext.isSampled()) {
this._finished = true;
let endTime = finishTime || Utils.getTimestampMicros();
this._duration = endTime - this._startTime;
this._tracer._report(this);
Expand Down

0 comments on commit a8f1ea3

Please sign in to comment.