Skip to content

Commit

Permalink
feat: introduce ended property on Span
Browse files Browse the repository at this point in the history
Add a getter to Span and ReadableSpan to allow checking if the span is
ended without using a private field or rely on internals like
span.duration[0] < 0.

Refs: open-telemetry/opentelemetry-java#693
Refs: open-telemetry/opentelemetry-java#697
  • Loading branch information
Flarna committed Dec 16, 2019
1 parent 9458390 commit a41215c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-collector/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const mockedReadableSpan: ReadableSpan = {
parentSpanId: '78a8915098864388',
startTime: [1574120165, 429803070],
endTime: [1574120165, 438688070],
ended: true,
status: { code: 0 },
attributes: { component: 'document-load' },
links: [
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('JaegerExporter', () => {
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('transform', () => {
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.OK,
},
Expand Down Expand Up @@ -131,6 +132,7 @@ describe('transform', () => {
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
message: 'data loss',
Expand Down Expand Up @@ -187,6 +189,7 @@ describe('transform', () => {
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.OK,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-exporter-zipkin/test/zipkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function getReadableSpan() {
},
startTime: [startTime, 0],
endTime: [startTime + duration, 0],
ended: true,
duration: [duration, 0],
status: {
code: types.CanonicalCode.OK,
Expand Down Expand Up @@ -141,6 +142,7 @@ describe('ZipkinExporter', () => {
},
startTime: [startTime, 0],
endTime: [startTime + duration, 0],
ended: true,
duration: [duration, 0],
status: {
code: types.CanonicalCode.OK,
Expand All @@ -167,6 +169,7 @@ describe('ZipkinExporter', () => {
},
startTime: [startTime, 0],
endTime: [startTime + duration, 0],
ended: true,
duration: [duration, 0],
status: {
code: types.CanonicalCode.OK,
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-tracing/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export class Span implements types.Span, ReadableSpan {
return this._duration;
}

get ended(): boolean {
return this._ended;
}

private _isSpanEnded(): boolean {
if (this._ended) {
this._logger.warn(
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-tracing/src/export/ReadableSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export interface ReadableSpan {
readonly links: Link[];
readonly events: TimedEvent[];
readonly duration: HrTime;
readonly ended: boolean;
}
7 changes: 7 additions & 0 deletions packages/opentelemetry-tracing/test/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,11 @@ describe('Span', () => {
span.updateName('bar-span');
assert.strictEqual(span.name, 'foo-span');
});

it('should have ended', () => {
const span = new Span(tracer, name, spanContext, SpanKind.SERVER);
assert.strictEqual(span.ended, false);
span.end();
assert.strictEqual(span.ended, true);
});
});

0 comments on commit a41215c

Please sign in to comment.