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

Commit 4a3d279

Browse files
djonathascardososilva-fabio
authored andcommitted
fix: fixed typescript code style
1 parent 2201ed6 commit 4a3d279

4 files changed

Lines changed: 49 additions & 34 deletions

File tree

packages/opencensus-core/src/internal/cls-ah.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as asyncHook from 'async_hooks'
18-
import {Context, Func, Namespace as CLSNamespace} from 'continuation-local-storage'
19-
import {EventEmitter} from 'events'
20-
import * as shimmer from 'shimmer'
17+
import * as asyncHook from 'async_hooks';
18+
import {Context, Func, Namespace as CLSNamespace} from 'continuation-local-storage';
19+
import {EventEmitter} from 'events';
20+
import * as shimmer from 'shimmer';
2121

2222
const wrappedSymbol = Symbol('context_wrapped');
2323
let contexts: {[asyncId: number]: Context;} = {};

packages/opencensus-core/src/internal/cls.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as CLS from 'continuation-local-storage'
18-
import * as semver from 'semver'
19-
import { debug } from './util'
17+
import * as CLS from 'continuation-local-storage';
18+
import * as semver from 'semver';
19+
20+
import * as cls_ah from './cls-ah';
21+
import {debug} from './util';
2022

2123
export type Namespace = CLS.Namespace;
2224
export type Func<T> = CLS.Func<T>;
2325

24-
const useAsyncHooks: boolean = semver.satisfies(process.version, '>=8') ;//&&
25-
// !!process.env.GCLOUD_TRACE_NEW_CONTEXT;
26+
const useAsyncHooks: boolean = semver.satisfies(
27+
process.version, '>=8'); //&&
28+
// !!process.env.GCLOUD_TRACE_NEW_CONTEXT;
2629

27-
debug('useAsyncHooks = %s',useAsyncHooks);
30+
debug('useAsyncHooks = %s', useAsyncHooks);
2831

2932
const cls: typeof CLS =
30-
useAsyncHooks ? require('./cls-ah') : require('continuation-local-storage');
33+
useAsyncHooks ? cls_ah : CLS;
3134

3235

3336
const TRACE_NAMESPACE = 'opencensus.io';
@@ -51,5 +54,3 @@ export function destroyNamespace(): void {
5154
export function getNamespace(): CLS.Namespace {
5255
return cls.getNamespace(TRACE_NAMESPACE);
5356
}
54-
55-

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import * as uuid from 'uuid';
1818

1919
import {Clock} from '../../internal/clock';
2020
import {debug} from '../../internal/util';
21-
import {OnEndSpanEventListener, RootSpan, TraceContext, TraceOptions, Span, Tracer} from './types';
2221

2322
import {SpanImpl} from './span';
2423
import {SpanBaseModel} from './spanbasemodel';
2524
import {TracerImpl} from './tracer';
25+
import {OnEndSpanEventListener, RootSpan, Span, TraceContext, TraceOptions, Tracer} from './types';
2626

2727
/** Defines a root span */
2828
export class RootSpanImpl extends SpanBaseModel implements RootSpan {
@@ -45,21 +45,25 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
4545
this.spansLocal = [];
4646
}
4747

48-
get spans() {
48+
/** Get span list from rootspan instance */
49+
get spans(): Span[] {
4950
return this.spansLocal;
5051
}
5152

52-
get traceId() {
53+
/** Get trace id from rootspan instance */
54+
get traceId(): string {
5355
return this.traceIdLocal;
5456
}
5557

58+
/** Start a rootspan instance */
5659
start() {
5760
super.start();
5861
debug(
5962
'starting %s %o', this.className,
6063
{traceId: this.traceId, id: this.id, parentSpanId: this.parentSpanId});
6164
}
6265

66+
/** End a rootspan instance */
6367
end() {
6468
super.end();
6569

@@ -72,6 +76,10 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
7276
this.tracer.onEndSpan(this);
7377
}
7478

79+
/**
80+
* Event called when a span ended
81+
* @param span Span ended
82+
*/
7583
onEndSpan(span: Span) {
7684
debug('ending span %o', {
7785
id: span.id,
@@ -83,6 +91,12 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
8391
});
8492
}
8593

94+
/**
95+
* Start a new span linked with the rootspan
96+
* @param name Span name
97+
* @param type Span type
98+
* @param parentSpanId Span parent ID
99+
*/
86100
startSpan(name: string, type: string, parentSpanId?: string) {
87101
if (!this.started) {
88102
debug(

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import {SpanImpl} from '../src/trace/model/span';
2222
import {TracerImpl} from '../src/trace/model/tracer';
2323
import {Span} from '../src/trace/model/types';
2424

25-
let tracer = new TracerImpl();
25+
const tracer = new TracerImpl();
2626

27-
describe('Span', function() {
27+
describe('Span', () => {
2828
/**
2929
* Should create a span
3030
*/
31-
describe('new Span()', function() {
32-
it('should create a Span instance', function() {
31+
describe('new Span()', () => {
32+
it('should create a Span instance', () => {
3333
const rootSpan = new RootSpanImpl(tracer);
3434
const span = new SpanImpl(rootSpan);
3535
assert.ok(span instanceof SpanImpl);
@@ -39,8 +39,8 @@ describe('Span', function() {
3939
/**
4040
* Should return the Trace ID
4141
*/
42-
describe('get traceId()', function() {
43-
it('should return the trace id', function() {
42+
describe('get traceId()', () => {
43+
it('should return the trace id', () => {
4444
const rootSpan = new RootSpanImpl(tracer);
4545
rootSpan.start();
4646
const span = new SpanImpl(rootSpan);
@@ -51,11 +51,11 @@ describe('Span', function() {
5151
/**
5252
* Should the trace context of span
5353
*/
54-
describe('get traceContext()', function() {
55-
it('should the trace context of span', function() {
54+
describe('get traceContext()', () => {
55+
it('should the trace context of span', () => {
5656
const rootSpan = new RootSpanImpl(tracer);
5757
rootSpan.start();
58-
58+
5959
const span = new SpanImpl(rootSpan);
6060
const context = span.traceContext;
6161

@@ -68,11 +68,11 @@ describe('Span', function() {
6868
/**
6969
* Should start a span instance
7070
*/
71-
describe('start()', function() {
72-
it('should start a span instance', function() {
71+
describe('start()', () => {
72+
it('should start a span instance', () => {
7373
const rootSpan = new RootSpanImpl(tracer);
7474
rootSpan.start();
75-
75+
7676
const span = new SpanImpl(rootSpan);
7777
span.start();
7878

@@ -83,11 +83,11 @@ describe('Span', function() {
8383
/**
8484
* Should end a span instance
8585
*/
86-
describe('end()', function() {
87-
it('should end a span instance', function() {
86+
describe('end()', () => {
87+
it('should end a span instance', () => {
8888
const rootSpan = new RootSpanImpl(tracer);
8989
rootSpan.start();
90-
90+
9191
const span = new SpanImpl(rootSpan);
9292
span.start();
9393
span.end();
@@ -99,11 +99,11 @@ describe('Span', function() {
9999
/**
100100
* Should not end a span instance
101101
*/
102-
describe('end() before start the span', function() {
103-
it('should not end a span instance', function() {
102+
describe('end() before start the span', () => {
103+
it('should not end a span instance', () => {
104104
const rootSpan = new RootSpanImpl(tracer);
105105
rootSpan.start();
106-
106+
107107
const span = new SpanImpl(rootSpan);
108108
span.end();
109109

0 commit comments

Comments
 (0)