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

Commit

Permalink
startChildSpan with SpanOptions interface only. (#521)
Browse files Browse the repository at this point in the history
* startChildSpan with SpanOptions interface

* Update CHANGELOG.md
  • Loading branch information
mayurkale22 committed May 15, 2019
1 parent 0fcb0cb commit 800520f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

## Unreleased

**This release has a breaking change. Please test your code accordingly after upgrading.**

- Remove Span's `startChildSpan(nameOrOptions?: string|SpanOptions, kind?: SpanKind)` interface, now only `SpanOptions` object interface is supported.

## 0.0.12 - 2019-05-13
- Add `defaultAttributes` config to `Tracer.start(config)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,12 @@ export class NoRecordSpan implements types.Span {

/**
* 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.
* @param [options] A SpanOptions object to start a child span.
*/
startChildSpan(
nameOrOptions?: string|types.SpanOptions,
kind?: types.SpanKind): types.Span {
startChildSpan(options?: types.SpanOptions): types.Span {
const noRecordChild = new NoRecordSpan(this);

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;
}

if (options && options.name) noRecordChild.name = options.name;
if (options && options.kind) noRecordChild.kind = options.kind;
noRecordChild.start();
return noRecordChild;
}
Expand Down
15 changes: 4 additions & 11 deletions packages/opencensus-core/src/trace/model/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,9 @@ export class Span implements types.Span {

/**
* Starts a new child span.
* @param nameOrOptions Span name string or SpanOptions object.
* @param kind Span kind if not using SpanOptions object.
* @param [options] A SpanOptions object to start a child span.
*/
startChildSpan(
nameOrOptions?: string|types.SpanOptions,
kind?: types.SpanKind): types.Span {
startChildSpan(options?: types.SpanOptions): types.Span {
if (this.ended) {
this.logger.debug(
'calling %s.startSpan() on ended %s %o', this.className,
Expand All @@ -366,12 +363,8 @@ export class Span implements types.Span {
}

const child = new Span(this.tracer, this);
const spanName =
typeof nameOrOptions === 'object' ? nameOrOptions.name : nameOrOptions;
const spanKind =
typeof nameOrOptions === 'object' ? nameOrOptions.kind : kind;
if (spanName) child.name = spanName;
if (spanKind) child.kind = spanKind;
if (options && options.name) child.name = options.name;
if (options && options.kind) child.kind = options.kind;

child.start();
this.spansLocal.push(child);
Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-core/src/trace/model/tracer-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class CoreTracerBase implements types.TracerBase {
'no current trace found - must start a new root span first');
return new NoRecordSpan();
}
const span = options.childOf.startChildSpan(options.name, options.kind);
const span = options.childOf.startChildSpan(options);

// Add default attributes
const defaultAttributes = this.config && this.config.defaultAttributes;
Expand Down
3 changes: 0 additions & 3 deletions packages/opencensus-core/src/trace/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,7 @@ export interface Span {
truncate(): void;

/** Starts a new Span instance as a child of this instance */
startChildSpan(name?: string, kind?: SpanKind): Span;
startChildSpan(options?: SpanOptions): Span;
startChildSpan(nameOrOptions?: string|SpanOptions, kind?: SpanKind): Span;
}

/** Interface for TracerBase */
Expand Down Expand Up @@ -515,7 +513,6 @@ export interface TracerBase extends SpanEventListener {

/**
* Start a new Span instance to the currentRootSpan
* @param childOf Span
* @param [options] A TraceOptions object to start a root span.
* @returns The new Span instance started
*/
Expand Down

0 comments on commit 800520f

Please sign in to comment.