Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Consolidating Span and RootSpan to allow Spans to recursively have ch…
Browse files Browse the repository at this point in the history
…ildren (#441)

* refactor(tracer): consolidate root span (+10 squashed commits)
Squashed commits:
[a4f2234] Get the test passing
[8276c98] Get allDescendants() working
[379b2eb] Big refactor, tests are mostly passing
[6d93312] Lerna handles cross-package dependencies
[3567e2e] Rough draft of making Span and RootSpan almost identical
[eba18f3] Set 'shared' based on the type of span
[b56a884] Reformat tests
[b1b6dfb] Use parentSpanId if provided
[9d4e601] Tests that ensure nested spans are properly translated for Zipkin
[585034e] Add tests for nested spans.

* Add these files back

* Undo spurious package-lock.json changes

* test(pluginloader): re-enable tests

* Address PR comments

* Add tracer tests, clean ups to tracez.page-handler.ts

* Allow grandchildren via tracer.startChildSpan()
  • Loading branch information
Ken Ashcraft authored and mayurkale22 committed Apr 11, 2019
1 parent fbc618b commit abd41db
Show file tree
Hide file tree
Showing 34 changed files with 847 additions and 833 deletions.
12 changes: 6 additions & 6 deletions packages/opencensus-core/src/exporters/console-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {Exporter, ExporterConfig, StatsEventListener} from './types';
/** Do not send span data */
export class NoopExporter implements Exporter {
logger?: loggerTypes.Logger;
onStartSpan(root: modelTypes.RootSpan) {}
onEndSpan(root: modelTypes.RootSpan) {}
publish(rootSpans: modelTypes.RootSpan[]) {
onStartSpan(root: modelTypes.Span) {}
onEndSpan(root: modelTypes.Span) {}
publish(rootSpans: modelTypes.Span[]) {
return Promise.resolve();
}
}
Expand All @@ -48,21 +48,21 @@ export class ConsoleExporter implements Exporter {
this.logger = config.logger;
}

onStartSpan(root: modelTypes.RootSpan) {}
onStartSpan(root: modelTypes.Span) {}

/**
* Event called when a span is ended.
* @param root Ended span.
*/
onEndSpan(root: modelTypes.RootSpan) {
onEndSpan(root: modelTypes.Span) {
this.buffer.addToBuffer(root);
}

/**
* Sends the spans information to the console.
* @param rootSpans A list of root spans to publish.
*/
publish(rootSpans: modelTypes.RootSpan[]) {
publish(rootSpans: modelTypes.Span[]) {
rootSpans.map((root) => {
const ROOT_STR = `RootSpan: {traceId: ${root.traceId}, spanId: ${
root.id}, name: ${root.name} }`;
Expand Down
6 changes: 3 additions & 3 deletions packages/opencensus-core/src/exporters/exporter-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ExporterBuffer {
/** An object to log information to */
private logger: loggerTypes.Logger;
/** Trace queue of a buffer */
private queue: modelTypes.RootSpan[] = [];
private queue: modelTypes.Span[] = [];

/**
* Constructs a new Buffer instance.
Expand Down Expand Up @@ -70,15 +70,15 @@ export class ExporterBuffer {
return this.bufferSize;
}

getQueue(): modelTypes.RootSpan[] {
getQueue(): modelTypes.Span[] {
return this.queue;
}

/**
* Add a rootSpan in the buffer.
* @param root RootSpan to be added in the buffer.
*/
addToBuffer(root: modelTypes.RootSpan) {
addToBuffer(root: modelTypes.Span) {
this.queue.push(root);
this.logger.debug('ExporterBuffer: added new rootspan');

Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-core/src/exporters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Exporter extends modelTypes.SpanEventListener {
* Sends a list of root spans to the service.
* @param rootSpans A list of root spans to publish.
*/
publish(rootSpans: modelTypes.RootSpan[]): Promise<number|string|void>;
publish(rootSpans: modelTypes.Span[]): Promise<number|string|void>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
import * as logger from '../../../common/console-logger';
import * as types from '../types';
import {NoRecordSpan} from './no-record-span';
import {NoRecordSpanBase} from './no-record-span-base';

/** Implementation for the RootSpan class that does not record trace events. */
export class NoRecordRootSpan extends NoRecordSpanBase implements
types.RootSpan {
/** Implementation for the Span class that does not record trace events. */
export class NoRecordRootSpan extends NoRecordSpan {
/** A tracer object */
private tracer: types.Tracer;
/** Its trace ID. */
private traceIdLocal: string;
/** Its trace state. */
private traceStateLocal?: types.TraceState;
/** set isRootSpan = true */
readonly isRootSpan = true;
/**
* This span's parent Id. This is a string and not a Span because the
* parent was likely started on another machine.
*/
private parentSpanIdLocal: string;

/**
* Constructs a new NoRecordRootSpanImpl instance.
Expand All @@ -49,23 +50,23 @@ export class NoRecordRootSpan extends NoRecordSpanBase implements
this.traceIdLocal = traceId;
this.name = name;
this.kind = kind;
this.parentSpanId = parentSpanId;
this.parentSpanIdLocal = parentSpanId;
if (traceState) {
this.traceStateLocal = traceState;
}
this.logger = this.tracer.logger || logger.logger();
}

/** No-op implementation of this method. */
get spans(): types.Span[] {
return [];
}

/** No-op implementation of this method. */
get traceId(): string {
return this.traceIdLocal;
}

/** Gets the ID of the parent span. */
get parentSpanId(): string {
return this.parentSpanIdLocal;
}

/** No-op implementation of this method. */
get traceState(): types.TraceState|undefined {
return this.traceStateLocal;
Expand All @@ -85,29 +86,4 @@ export class NoRecordRootSpan extends NoRecordSpanBase implements
end() {
super.end();
}

/**
* Starts a new no record child span in the no record root span.
* @param nameOrOptions Span name string or SpanOptions object.
* @param kind Span kind if not using SpanOptions object.
*/
startChildSpan(
nameOrOptions?: string|types.SpanOptions,
kind?: types.SpanKind): types.Span {
const noRecordChild = new NoRecordSpan();

const spanName =
typeof nameOrOptions === 'object' ? nameOrOptions.name : nameOrOptions;
const spanKind =
typeof nameOrOptions === 'object' ? nameOrOptions.kind : kind;
if (spanName) {
noRecordChild.name = spanName;
}
if (spanKind) {
noRecordChild.kind = spanKind;
}

noRecordChild.start();
return noRecordChild;
}
}

This file was deleted.

Loading

0 comments on commit abd41db

Please sign in to comment.