Skip to content

Commit

Permalink
feat: introduce ended property on Span (#625)
Browse files Browse the repository at this point in the history
* feat: introduce ended property on Span

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

* chore: adapt after merge from master

* chore: revert changes in API

* chore: remove unneeded isEnded
  • Loading branch information
Flarna authored Mar 10, 2020
1 parent 11a572f commit 8bac263
Show file tree
Hide file tree
Showing 9 changed files with 26 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 @@ -33,6 +33,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 @@ -119,6 +119,7 @@ describe('JaegerExporter', () => {
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
},
Expand Down
4 changes: 4 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('transform', () => {
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.OK,
},
Expand Down Expand Up @@ -133,6 +134,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 @@ -189,6 +191,7 @@ describe('transform', () => {
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.OK,
},
Expand Down Expand Up @@ -233,6 +236,7 @@ describe('transform', () => {
},
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
message: 'data loss',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe('Stackdriver Trace Exporter', () => {
duration: [32, 800000000],
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
events: [],
kind: types.SpanKind.CLIENT,
links: [],
Expand Down Expand Up @@ -142,6 +143,7 @@ describe('Stackdriver Trace Exporter', () => {
duration: [32, 800000000],
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
events: [],
kind: types.SpanKind.CLIENT,
links: [],
Expand Down Expand Up @@ -174,6 +176,7 @@ describe('Stackdriver Trace Exporter', () => {
duration: [32, 800000000],
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
events: [],
kind: types.SpanKind.CLIENT,
links: [],
Expand Down Expand Up @@ -204,6 +207,7 @@ describe('Stackdriver Trace Exporter', () => {
duration: [32, 800000000],
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
events: [],
kind: types.SpanKind.CLIENT,
links: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('transform', () => {
duration: [32, 800000000],
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
events: [],
kind: types.SpanKind.CLIENT,
links: [],
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 @@ -40,6 +40,7 @@ function getReadableSpan() {
},
startTime: [startTime, 0],
endTime: [startTime + duration, 0],
ended: true,
duration: [duration, 0],
status: {
code: types.CanonicalCode.OK,
Expand Down Expand Up @@ -136,6 +137,7 @@ describe('ZipkinExporter', () => {
},
startTime: [startTime, 0],
endTime: [startTime + duration, 0],
ended: true,
duration: [duration, 0],
status: {
code: types.CanonicalCode.OK,
Expand Down Expand Up @@ -163,6 +165,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 @@ -358,4 +358,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 8bac263

Please sign in to comment.