Skip to content

Commit 4dc8b8b

Browse files
committed
ref: Rename flush
1 parent a72b2f8 commit 4dc8b8b

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/opentracing/src/span.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Log {
1111

1212
/** JSDoc */
1313
export class Span extends opentracing.Span implements SpanInterface {
14+
private flushed: boolean = false;
1415
private finishTime: number = 0;
1516

1617
private readonly logs: Log[] = [];
@@ -105,6 +106,28 @@ export class Span extends opentracing.Span implements SpanInterface {
105106
return this.finishTime - this.startTime;
106107
}
107108

109+
/**
110+
* Returns wether the span has been finished.
111+
*/
112+
public isFinished(): boolean {
113+
return this.finishTime > 0;
114+
}
115+
116+
/**
117+
* Marks the span as flushed.
118+
*/
119+
public flush(): this {
120+
this.flushed = true;
121+
return this;
122+
}
123+
124+
/**
125+
* Returns wether the span has already be flushed.
126+
*/
127+
public isFlushed(): boolean {
128+
return this.flushed;
129+
}
130+
108131
/**
109132
* @inheritdoc
110133
*/

packages/opentracing/src/tracer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SpanContext } from './spancontext';
88
*/
99
export class Tracer extends opentracing.Tracer {
1010
private traceId?: string = undefined;
11-
private spans: Span[] = [];
11+
private readonly spans: Span[] = [];
1212

1313
/**
1414
* Called by public method startSpan
@@ -41,7 +41,9 @@ export class Tracer extends opentracing.Tracer {
4141
* Flushes all spans and sends an event
4242
*/
4343
public flush(): void {
44-
getCurrentHub().captureEvent({ spans: [...this.spans] });
45-
this.spans = [];
44+
const finishedSpans = this.spans.filter((span: Span) => span.isFinished() && !span.isFlushed());
45+
if (finishedSpans.length) {
46+
getCurrentHub().captureEvent({ spans: finishedSpans.map((span: Span) => span.flush()) });
47+
}
4648
}
4749
}

0 commit comments

Comments
 (0)