From b9a4cfdff6fe72dd4dae8bb89c22742c1df37132 Mon Sep 17 00:00:00 2001 From: Gerhard Stoebich <18708370+Flarna@users.noreply.github.com> Date: Wed, 18 Dec 2019 12:34:31 +0100 Subject: [PATCH] feat: add isEnded on types.Span --- packages/opentelemetry-api/src/trace/NoopSpan.ts | 8 ++++++++ packages/opentelemetry-api/src/trace/span.ts | 7 +++++++ packages/opentelemetry-tracing/src/Span.ts | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/packages/opentelemetry-api/src/trace/NoopSpan.ts b/packages/opentelemetry-api/src/trace/NoopSpan.ts index cfa3c9c4c08..bb1cd755748 100644 --- a/packages/opentelemetry-api/src/trace/NoopSpan.ts +++ b/packages/opentelemetry-api/src/trace/NoopSpan.ts @@ -76,11 +76,19 @@ export class NoopSpan implements Span { // By default does nothing end(endTime?: TimeInput): void {} + this._ended = true; + } // isRecording always returns false for noopSpan. isRecording(): boolean { return false; } + + isEnded(): boolean { + return this._ended; + } + + private _ended: boolean = false; } export const NOOP_SPAN = new NoopSpan(); diff --git a/packages/opentelemetry-api/src/trace/span.ts b/packages/opentelemetry-api/src/trace/span.ts index 2a725afdc2a..7813f7ed494 100644 --- a/packages/opentelemetry-api/src/trace/span.ts +++ b/packages/opentelemetry-api/src/trace/span.ts @@ -100,4 +100,11 @@ export interface Span { * with the AddEvent operation and attributes using setAttributes. */ isRecording(): boolean; + + /** + * Returns if the span has been ended. + * + * @returns true if the Span has been ended. + */ + isEnded(): boolean; } diff --git a/packages/opentelemetry-tracing/src/Span.ts b/packages/opentelemetry-tracing/src/Span.ts index 7292cb43a61..902fd8f2472 100644 --- a/packages/opentelemetry-tracing/src/Span.ts +++ b/packages/opentelemetry-tracing/src/Span.ts @@ -172,6 +172,10 @@ export class Span implements types.Span, ReadableSpan { return true; } + isEnded(): boolean { + return this._ended; + } + toReadableSpan(): ReadableSpan { return this; }