From b2b19b94227b5ec7dcb3733da5ddd20d2be5324f Mon Sep 17 00:00:00 2001 From: Peter Marton Date: Sat, 13 Jul 2019 07:51:04 -0700 Subject: [PATCH] feat(span): make tracer available on span --- .../src/trace/model/no-record/no-record-root-span.ts | 4 ++-- .../src/trace/model/no-record/no-record-span.ts | 5 ++++- packages/opencensus-core/src/trace/model/root-span.ts | 3 +++ packages/opencensus-core/src/trace/model/span.ts | 4 ++-- packages/opencensus-core/src/trace/model/types.ts | 5 +++++ 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/opencensus-core/src/trace/model/no-record/no-record-root-span.ts b/packages/opencensus-core/src/trace/model/no-record/no-record-root-span.ts index 0e821ad1a..89a9c6c47 100644 --- a/packages/opencensus-core/src/trace/model/no-record/no-record-root-span.ts +++ b/packages/opencensus-core/src/trace/model/no-record/no-record-root-span.ts @@ -20,8 +20,6 @@ import { NoRecordSpan } from './no-record-span'; /** Implementation for the Span class that does not record trace events. */ export class NoRecordRootSpan extends NoRecordSpan { - /** A tracer object */ - private tracer: types.TracerBase; /** Its trace ID. */ private traceIdLocal: string; /** Its trace state. */ @@ -31,6 +29,8 @@ export class NoRecordRootSpan extends NoRecordSpan { * parent was likely started on another machine. */ private parentSpanIdLocal: string; + /** A tracer object */ + tracer: types.TracerBase; /** * Constructs a new NoRecordRootSpanImpl instance. diff --git a/packages/opencensus-core/src/trace/model/no-record/no-record-span.ts b/packages/opencensus-core/src/trace/model/no-record/no-record-span.ts index 270ee94d3..4454a474d 100644 --- a/packages/opencensus-core/src/trace/model/no-record/no-record-span.ts +++ b/packages/opencensus-core/src/trace/model/no-record/no-record-span.ts @@ -31,6 +31,8 @@ export class NoRecordSpan implements types.Span { private endedLocal = false; /** The Span ID of this span */ readonly id: string; + /** A tracer object */ + tracer: types.TracerBase; /** An object to log information to */ logger: Logger = noopLogger; /** A set of attributes, each in the format [KEY]:[VALUE] */ @@ -66,7 +68,8 @@ export class NoRecordSpan implements types.Span { droppedMessageEventsCount = 0; /** Constructs a new SpanBaseModel instance. */ - constructor(parent?: NoRecordSpan) { + constructor(tracer: types.TracerBase, parent?: NoRecordSpan) { + this.tracer = tracer; this.id = randomSpanId(); if (parent) { this.root = parent.root; diff --git a/packages/opencensus-core/src/trace/model/root-span.ts b/packages/opencensus-core/src/trace/model/root-span.ts index 784951eb3..c3ef2f6ea 100644 --- a/packages/opencensus-core/src/trace/model/root-span.ts +++ b/packages/opencensus-core/src/trace/model/root-span.ts @@ -29,6 +29,8 @@ export class RootSpan extends Span { * parent was likely started on another machine. */ private parentSpanIdLocal: string; + /** A tracer object */ + tracer: types.TracerBase; /** * Constructs a new RootSpanImpl instance. @@ -49,6 +51,7 @@ export class RootSpan extends Span { traceState?: types.TraceState ) { super(tracer); + this.tracer = tracer; this.traceIdLocal = traceId; this.name = name; this.kind = kind; diff --git a/packages/opencensus-core/src/trace/model/span.ts b/packages/opencensus-core/src/trace/model/span.ts index a285b761a..9ed14cb45 100644 --- a/packages/opencensus-core/src/trace/model/span.ts +++ b/packages/opencensus-core/src/trace/model/span.ts @@ -29,8 +29,6 @@ const STATUS_OK = { /** Defines a base model for spans. */ export class Span implements types.Span { protected className: string; - /** A tracer object */ - private tracer: types.TracerBase; /** The clock used to mesure the beginning and ending of a span */ private clock!: Clock; /** Indicates if this span was started */ @@ -41,6 +39,8 @@ export class Span implements types.Span { private spansLocal: types.Span[]; /** The Span ID of this span */ readonly id: string; + /** A tracer object */ + tracer: types.TracerBase; /** An object to log information to */ logger: Logger = noopLogger; /** A set of attributes, each in the format [KEY]:[VALUE] */ diff --git a/packages/opencensus-core/src/trace/model/types.ts b/packages/opencensus-core/src/trace/model/types.ts index 68bf5451a..35d7b9d1f 100644 --- a/packages/opencensus-core/src/trace/model/types.ts +++ b/packages/opencensus-core/src/trace/model/types.ts @@ -315,6 +315,11 @@ export interface Span { /** The Span ID of this span */ readonly id: string; + /** A tracer object, exposong the tracer makes it possible to create child + * spans from the span instance like. span.tracer.startChildSpan() + */ + tracer: TracerBase; + /** If the parent span is in another process. */ remoteParent: boolean;