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

Commit ab513e3

Browse files
crdgonzalezcadraffensperger
authored andcommitted
Update to last commit 4a6c3f1. (#81)
1 parent 74ada26 commit ab513e3

7 files changed

Lines changed: 24 additions & 66 deletions

File tree

packages/opencensus-web-core/src/trace/model/span.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,16 @@ export class Span implements webTypes.Span {
163163

164164
/**
165165
* Starts a new child span.
166-
* @param nameOrOptions Span name string or SpanOptions object.
167-
* @param kind Span kind if not using options object.
168-
* @param parentSpanId Span parent ID.
166+
* @param [options] A SpanOptions object to start a child span.
169167
*/
170-
startChildSpan(
171-
nameOrOptions?: string | webTypes.SpanOptions,
172-
kind?: webTypes.SpanKind
173-
): Span {
168+
startChildSpan(options?: webTypes.SpanOptions): Span {
174169
this.numberOfChildrenLocal++;
175170
const child = new Span();
176171
child.traceId = this.traceId;
177172
child.traceState = this.traceState;
178173

179-
const spanName =
180-
typeof nameOrOptions === 'object' ? nameOrOptions.name : nameOrOptions;
181-
const spanKind =
182-
typeof nameOrOptions === 'object' ? nameOrOptions.kind : kind;
183-
if (spanName) child.name = spanName;
184-
if (spanKind) child.kind = spanKind;
174+
if (options && options.name) child.name = options.name;
175+
if (options && options.kind) child.kind = options.kind;
185176

186177
child.start();
187178
child.parentSpanId = this.id;

packages/opencensus-web-core/test/test-root-span.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,16 @@ describe('RootSpan', () => {
9191
it('should get nested spans from rootspan instance', () => {
9292
root.start();
9393
expect(root.numberOfChildren).toBe(0);
94-
const child1 = root.startChildSpan('child1', SpanKind.UNSPECIFIED);
94+
const child1 = root.startChildSpan({
95+
name: 'child1',
96+
kind: SpanKind.UNSPECIFIED,
97+
});
9598
expect(root.numberOfChildren).toBe(1);
9699
expect(child1.numberOfChildren).toBe(0);
97-
const child2 = root.startChildSpan('child2', SpanKind.UNSPECIFIED);
100+
const child2 = root.startChildSpan({
101+
name: 'child2',
102+
kind: SpanKind.UNSPECIFIED,
103+
});
98104
expect(root.numberOfChildren).toBe(2);
99105
const grandchild1 = child1.startChildSpan({
100106
name: 'grandchild1',

packages/opencensus-web-core/test/test-span.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,14 @@ describe('Span', () => {
196196
it('should get numberOfChildren from span instance', () => {
197197
span.start();
198198
expect(span.numberOfChildren).toBe(0);
199-
span.startChildSpan('spanName', SpanKind.UNSPECIFIED);
199+
span.startChildSpan({ name: 'spanName', kind: SpanKind.UNSPECIFIED });
200200
expect(span.numberOfChildren).toBe(1);
201201

202202
for (let i = 0; i < 10; i++) {
203-
span.startChildSpan('spanName' + i, SpanKind.UNSPECIFIED);
203+
span.startChildSpan({
204+
name: 'spanName' + i,
205+
kind: SpanKind.UNSPECIFIED,
206+
});
204207
}
205208
expect(span.numberOfChildren).toBe(11);
206209
});
@@ -211,7 +214,10 @@ describe('Span', () => {
211214
span.traceId = '00000000000000000000000000000001';
212215
span.traceState = 'a=b';
213216

214-
const childSpan = span.startChildSpan('child1', SpanKind.CLIENT);
217+
const childSpan = span.startChildSpan({
218+
name: 'child1',
219+
kind: SpanKind.CLIENT,
220+
});
215221

216222
expect(childSpan.traceId).toBe('00000000000000000000000000000001');
217223
expect(childSpan.traceState).toBe('a=b');

packages/opencensus-web-types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"build": "npm run compile",
99
"clean": "rimraf build/*",
10-
"copytypes": "node scripts/copy-types.js 'v0.0.12' && npm run fix",
10+
"copytypes": "node scripts/copy-types.js '4a6c3f1ea487ba759e3a90dca69e733bbda8887a' && npm run fix",
1111
"check": "gts check",
1212
"compile": "tsc -p .",
1313
"fix": "gts fix",

packages/opencensus-web-types/scripts/copy-types.js

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ async function logAndExec(cmd, options) {
105105
function getPatchedContents(srcFile, contents) {
106106
contents = updateCopyright(srcFile, contents);
107107
contents = fixNodeJsEventEmitterType(srcFile, contents);
108-
contents = fixStatsImportInternalLibrary(srcFile, contents);
109-
contents = fixSemicolonError(srcFile, contents);
110108
return contents;
111109
}
112110

@@ -147,44 +145,4 @@ function fixNodeJsEventEmitterType(srcFile, contents) {
147145
`import {NodeJsEventEmitter} from '${relativeSrcDir}node/types';`);
148146
contents = lines.join('\n');
149147
return contents;
150-
}
151-
152-
/**
153-
* Replaces the `cls` import and usage and adds a new type to use instead of that import.
154-
* This function might be provisional until @opencensus/core updates with this change.
155-
*
156-
*/
157-
function fixStatsImportInternalLibrary(srcFile, contents){
158-
if(contents.indexOf('import * as cls from \'../internal/cls\';') === -1){
159-
return contents;
160-
}
161-
162-
console.log(` Using Fix stats import internal library for: ${srcFile}`);
163-
164-
const contentToAdd = [
165-
"/** Default type for functions */",
166-
"// tslint:disable:no-any",
167-
"export type Func<T> = (...args: any[]) => T;",
168-
"\n",
169-
"/** Main interface for stats. */"
170-
].join('\n');
171-
172-
contents = contents.replace("import * as cls from '../internal/cls';\n", "");
173-
contents = contents.replace('/** Main interface for stats. */', contentToAdd);
174-
contents = contents.replace('cls.Func', 'Func');
175-
return contents;
176-
}
177-
178-
/**
179-
* Adds a Semicolon in a specific location in order to perform `npm run fix` automatically without errors.
180-
* This function might be provisional until @opencensus/core updates with this change.
181-
*/
182-
function fixSemicolonError(srcFile, contents){
183-
if(contents.indexOf('[pluginName: string]: string\n') === -1){
184-
return contents;
185-
}
186-
187-
console.log(` Using fix semicolon error for: ${srcFile}`);
188-
189-
return contents.replace('[pluginName: string]: string\n', '[pluginName: string]: string;\n');
190-
}
148+
}

packages/opencensus-web-types/src/stats/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { TagKey, TagValue } from '../tags/types';
2121

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

2626
/** Main interface for stats. */
2727
export interface Stats {

packages/opencensus-web-types/src/trace/model/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,7 @@ export interface Span {
469469
truncate(): void;
470470

471471
/** Starts a new Span instance as a child of this instance */
472-
startChildSpan(name?: string, kind?: SpanKind): Span;
473472
startChildSpan(options?: SpanOptions): Span;
474-
startChildSpan(nameOrOptions?: string | SpanOptions, kind?: SpanKind): Span;
475473
}
476474

477475
/** Interface for TracerBase */
@@ -526,7 +524,6 @@ export interface TracerBase extends SpanEventListener {
526524

527525
/**
528526
* Start a new Span instance to the currentRootSpan
529-
* @param childOf Span
530527
* @param [options] A TraceOptions object to start a root span.
531528
* @returns The new Span instance started
532529
*/

0 commit comments

Comments
 (0)