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

Commit

Permalink
Update to last commit 4a6c3f1. (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
crdgonzalezca authored and draffensperger committed May 17, 2019
1 parent 74ada26 commit ab513e3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 66 deletions.
17 changes: 4 additions & 13 deletions packages/opencensus-web-core/src/trace/model/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,25 +163,16 @@ export class Span implements webTypes.Span {

/**
* Starts a new child span.
* @param nameOrOptions Span name string or SpanOptions object.
* @param kind Span kind if not using options object.
* @param parentSpanId Span parent ID.
* @param [options] A SpanOptions object to start a child span.
*/
startChildSpan(
nameOrOptions?: string | webTypes.SpanOptions,
kind?: webTypes.SpanKind
): Span {
startChildSpan(options?: webTypes.SpanOptions): Span {
this.numberOfChildrenLocal++;
const child = new Span();
child.traceId = this.traceId;
child.traceState = this.traceState;

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();
child.parentSpanId = this.id;
Expand Down
10 changes: 8 additions & 2 deletions packages/opencensus-web-core/test/test-root-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ describe('RootSpan', () => {
it('should get nested spans from rootspan instance', () => {
root.start();
expect(root.numberOfChildren).toBe(0);
const child1 = root.startChildSpan('child1', SpanKind.UNSPECIFIED);
const child1 = root.startChildSpan({
name: 'child1',
kind: SpanKind.UNSPECIFIED,
});
expect(root.numberOfChildren).toBe(1);
expect(child1.numberOfChildren).toBe(0);
const child2 = root.startChildSpan('child2', SpanKind.UNSPECIFIED);
const child2 = root.startChildSpan({
name: 'child2',
kind: SpanKind.UNSPECIFIED,
});
expect(root.numberOfChildren).toBe(2);
const grandchild1 = child1.startChildSpan({
name: 'grandchild1',
Expand Down
12 changes: 9 additions & 3 deletions packages/opencensus-web-core/test/test-span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,14 @@ describe('Span', () => {
it('should get numberOfChildren from span instance', () => {
span.start();
expect(span.numberOfChildren).toBe(0);
span.startChildSpan('spanName', SpanKind.UNSPECIFIED);
span.startChildSpan({ name: 'spanName', kind: SpanKind.UNSPECIFIED });
expect(span.numberOfChildren).toBe(1);

for (let i = 0; i < 10; i++) {
span.startChildSpan('spanName' + i, SpanKind.UNSPECIFIED);
span.startChildSpan({
name: 'spanName' + i,
kind: SpanKind.UNSPECIFIED,
});
}
expect(span.numberOfChildren).toBe(11);
});
Expand All @@ -211,7 +214,10 @@ describe('Span', () => {
span.traceId = '00000000000000000000000000000001';
span.traceState = 'a=b';

const childSpan = span.startChildSpan('child1', SpanKind.CLIENT);
const childSpan = span.startChildSpan({
name: 'child1',
kind: SpanKind.CLIENT,
});

expect(childSpan.traceId).toBe('00000000000000000000000000000001');
expect(childSpan.traceState).toBe('a=b');
Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-web-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "npm run compile",
"clean": "rimraf build/*",
"copytypes": "node scripts/copy-types.js 'v0.0.12' && npm run fix",
"copytypes": "node scripts/copy-types.js '4a6c3f1ea487ba759e3a90dca69e733bbda8887a' && npm run fix",
"check": "gts check",
"compile": "tsc -p .",
"fix": "gts fix",
Expand Down
44 changes: 1 addition & 43 deletions packages/opencensus-web-types/scripts/copy-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ async function logAndExec(cmd, options) {
function getPatchedContents(srcFile, contents) {
contents = updateCopyright(srcFile, contents);
contents = fixNodeJsEventEmitterType(srcFile, contents);
contents = fixStatsImportInternalLibrary(srcFile, contents);
contents = fixSemicolonError(srcFile, contents);
return contents;
}

Expand Down Expand Up @@ -147,44 +145,4 @@ function fixNodeJsEventEmitterType(srcFile, contents) {
`import {NodeJsEventEmitter} from '${relativeSrcDir}node/types';`);
contents = lines.join('\n');
return contents;
}

/**
* Replaces the `cls` import and usage and adds a new type to use instead of that import.
* This function might be provisional until @opencensus/core updates with this change.
*
*/
function fixStatsImportInternalLibrary(srcFile, contents){
if(contents.indexOf('import * as cls from \'../internal/cls\';') === -1){
return contents;
}

console.log(` Using Fix stats import internal library for: ${srcFile}`);

const contentToAdd = [
"/** Default type for functions */",
"// tslint:disable:no-any",
"export type Func<T> = (...args: any[]) => T;",
"\n",
"/** Main interface for stats. */"
].join('\n');

contents = contents.replace("import * as cls from '../internal/cls';\n", "");
contents = contents.replace('/** Main interface for stats. */', contentToAdd);
contents = contents.replace('cls.Func', 'Func');
return contents;
}

/**
* Adds a Semicolon in a specific location in order to perform `npm run fix` automatically without errors.
* This function might be provisional until @opencensus/core updates with this change.
*/
function fixSemicolonError(srcFile, contents){
if(contents.indexOf('[pluginName: string]: string\n') === -1){
return contents;
}

console.log(` Using fix semicolon error for: ${srcFile}`);

return contents.replace('[pluginName: string]: string\n', '[pluginName: string]: string;\n');
}
}
2 changes: 1 addition & 1 deletion packages/opencensus-web-types/src/stats/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { TagKey, TagValue } from '../tags/types';

/** Default type for functions */
// tslint:disable:no-any
export type Func<T> = (...args: any[]) => T;
type Func<T> = (...args: any[]) => T;

/** Main interface for stats. */
export interface Stats {
Expand Down
3 changes: 0 additions & 3 deletions packages/opencensus-web-types/src/trace/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,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 @@ -526,7 +524,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 ab513e3

Please sign in to comment.