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

Commit 1d0bafe

Browse files
committed
fix: some tests and tslint issues
1 parent 19b9bce commit 1d0bafe

13 files changed

Lines changed: 205 additions & 177 deletions

File tree

packages/opencensus-core/src/exporters/buffer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export class Buffer {
3535
/** Max time for a buffer can wait before being sent */
3636
private bufferTimeout: number;
3737
/** Manage when the buffer timeout needs to be reseted */
38-
private resetTimeout: boolean = false;
38+
private resetTimeout = false;
3939
/** Indicates when the buffer timeout is running */
40-
private bufferTimeoutInProgress: boolean = false;
40+
private bufferTimeoutInProgress = false;
4141

4242
constructor(exporter: Exporter, config: BufferConfig) {
4343
this.exporter = exporter;

packages/opencensus-core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717

18-
// opencensus core api interfaces
18+
// opencensus core api interfaces
1919
export * from './trace/types';
2020
export * from './trace/model/types';
2121
export * from './trace/config/types';
@@ -33,7 +33,7 @@ export * from './trace/config/sampler';
3333
// base instrumetation class
3434
export * from './trace/instrumentation/baseplugin';
3535

36-
// console exporter and buffer impls
36+
// console exporter and buffer impls
3737
export * from './exporters/buffer';
3838
export * from './exporters/consolelog-exporter';
3939

packages/opencensus-core/src/trace/config/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface Sampler {
4242
*/
4343
export interface BufferConfig {
4444
bufferSize?: number;
45-
bufferTimeout?: number
45+
bufferTimeout?: number;
4646
}
4747

4848
/** Defines tracer configuration parameters */

packages/opencensus-core/src/trace/instrumentation/base-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {Tracer} from '../model/types';
2020
* This class represent the base to patch plugin
2121
*/
2222
export abstract class BasePlugin {
23+
// tslint:disable:no-any
2324
exporter: any;
2425
moduleName: string;
2526
tracer: Tracer;
@@ -34,14 +35,15 @@ export abstract class BasePlugin {
3435
* @param tracer tracer relating to context
3536
* @param version module version description
3637
*/
38+
// tslint:disable:no-any
3739
protected setPluginContext(exporter: any, tracer: Tracer, version: string) {
3840
this.exporter = exporter;
3941
this.tracer = tracer;
4042
this.version = version;
4143
}
4244

43-
protected wrap(nodule, name, wrapper ) {
44-
shimmer.wrap(nodule, name, wrapper )
45+
protected wrap(nodule, name, wrapper) {
46+
shimmer.wrap(nodule, name, wrapper);
4547
}
4648

4749
protected unwrap(nodule, name) {

packages/opencensus-core/src/trace/instrumentation/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {Tracer} from "../model/types";
2020
* Interface Plugin to apply patch.
2121
*/
2222
export interface Plugin {
23+
// tslint:disable:no-any
2324
applyPatch(module: {}, tracer: Tracer, version: string): any;
2425
applyUnpatch(): void;
2526
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ export abstract class SpanBaseModel implements Span {
137137
addAnnotation(description: string, timestamp: number,
138138
attributes?: Attributes) {
139139
this.annotations.push({
140-
description: description,
141-
timestamp: timestamp,
142-
attributes: attributes,
143-
} as Annotation)
140+
'description': description,
141+
'timestamp': timestamp,
142+
'attributes': attributes,
143+
} as Annotation);
144144
}
145145

146146
/**
@@ -153,11 +153,11 @@ export abstract class SpanBaseModel implements Span {
153153
addLink(traceId: string, spanId: string, type: string,
154154
attributes?: Attributes) {
155155
this.links.push({
156-
traceId: traceId,
157-
SpanId: spanId,
158-
type: type,
159-
attributes: attributes
160-
} as Link)
156+
'traceId': traceId,
157+
'spanId': spanId,
158+
'type': type,
159+
'attributes': attributes
160+
} as Link);
161161
}
162162

163163
/**
@@ -167,9 +167,9 @@ export abstract class SpanBaseModel implements Span {
167167
*/
168168
addMessageEvent(type: string, id: string) {
169169
this.messageEvents.push({
170-
type: type,
171-
id: id,
172-
} as MessageEvent)
170+
'type': type,
171+
'id': id,
172+
} as MessageEvent);
173173
}
174174

175175
/** Starts a span. */

packages/opencensus-core/src/trace/model/tracer.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {OnEndSpanEventListener, Func } from './types';
2222
import {Sampler, TracerConfig} from '../config/types';
2323
import {Config} from '../config/types';
2424
import {SpanImpl} from './span';
25-
import {SamplerImpl} from '../config/sampler'
25+
import {SamplerImpl} from '../config/sampler';
2626
import {RootSpanImpl} from './rootspan';
2727

2828

@@ -38,9 +38,6 @@ export class TracerImpl implements Tracer {
3838
private eventListenersLocal: OnEndSpanEventListener[] = [];
3939
//TODO: temp solution
4040
private endedTraces: RootSpan[] = [];
41-
42-
43-
samplingRate: number;
4441

4542
constructor() {
4643
this.activeLocal = false;
@@ -79,14 +76,13 @@ export class TracerImpl implements Tracer {
7976
let newRoot = null;
8077
if(this.active) {
8178
newRoot = new RootSpanImpl (this, options);
82-
this.currentRootSpan = newRoot;
83-
8479
if (this.sampler.shouldSample(newRoot.traceId)) {
8580
newRoot.start();
81+
this.currentRootSpan = newRoot;
8682
return fn(newRoot);
8783
}
8884
} else {
89-
debug("Tracer is inactive, can't start new RootSpan")
85+
debug("Tracer is inactive, can't start new RootSpan");
9086
}
9187
return fn(newRoot);
9288
});

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { Sampler, Config, TracerConfig } from '../config/types';
1818

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

2223
/** Maps a label to a string, number or boolean. */
@@ -25,19 +26,19 @@ export interface Attributes { [attributeKey: string]: string|number|boolean; }
2526
/** A text annotation with a set of attributes. */
2627
export interface Annotation {
2728
/** A user-supplied message describing the event. */
28-
description: string,
29+
description: string;
2930
/** A timestamp that maks the event. */
30-
timestamp: number,
31+
timestamp: number;
3132
/** A set of attributes on the annotation. */
32-
attributes: Attributes
33+
attributes: Attributes;
3334
}
3435

3536
/** An event describing a message sent/received between Spans. */
3637
export interface MessageEvent {
3738
/** Indicates whether the message was sent or received. */
38-
type: string,
39+
type: string;
3940
/** An identifier for the MessageEvent's message. */
40-
id: string,
41+
id: string;
4142
}
4243

4344
/**
@@ -46,13 +47,13 @@ export interface MessageEvent {
4647
*/
4748
export interface Link {
4849
/** The trace ID for a trace within a project. */
49-
traceId: string,
50+
traceId: string;
5051
/** The span ID for a span within a trace. */
51-
SpanId: string,
52+
spanId: string;
5253
/** The relationship of the current span relative to the linked. */
53-
type: string,
54+
type: string;
5455
/** A set of attributes on the link. */
55-
attributes: Attributes
56+
attributes: Attributes;
5657
}
5758

5859

packages/opencensus-core/src/trace/types.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,43 @@ import {Sampler} from './config/types';
1919
import {Exporter} from '../exporters/types';
2020
import {Config} from './config/types';
2121

22+
//TODO: Improve JSDoc
2223

24+
/**
25+
* Main interface for tracing. Holds instances for {@link Tracer} and
26+
* {@link Exporter}.
27+
*
28+
*/
2329
export interface Tracing {
30+
31+
/**
32+
* Returns the {@link Tracer} object responsible for managing a trace.
33+
* @return the {@link Tracer} implementation.
34+
*/
2435
readonly tracer: Tracer;
25-
// readonly sampler: Sampler;
36+
37+
/**
38+
* Returns the {@link Exportert}
39+
* @return the {@link ExportComponent} implementation.
40+
*/
2641
readonly exporter: Exporter;
27-
start(config?:Config): Tracing;
42+
43+
/**
44+
* Enable tracing process.
45+
* @param userConfig Configuration provided by a client
46+
*/
47+
start(userConfig?:Config): Tracing;
48+
49+
/**
50+
* Stop tracing.
51+
*
52+
*/
2853
stop(): void;
54+
55+
/**
56+
* Registers an exporter to send the collected traces to.
57+
* @param exporter The exporter to send the traces to.
58+
*/
2959
registerExporter(exporter: Exporter): Tracing;
3060
}
3161

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const DEFAULT_BUFFER_SIZE = 3;
2727
const DEFAULT_BUFFER_TIMEOUT = 20000; // time in milliseconds
2828
const tracer = new TracerImpl();
2929

30+
const defaultBufferConfig = {
31+
bufferSize: DEFAULT_BUFFER_SIZE,
32+
bufferTimeout: DEFAULT_BUFFER_TIMEOUT
33+
};
3034

3135
describe('Buffer', () => {
3236
/**
@@ -35,8 +39,7 @@ describe('Buffer', () => {
3539
*/
3640
describe('new Buffer()', () => {
3741
it('should create a Buffer instance', () => {
38-
const buffer =
39-
new Buffer(exporter, DEFAULT_BUFFER_SIZE, DEFAULT_BUFFER_TIMEOUT);
42+
const buffer = new Buffer(exporter, defaultBufferConfig);
4043
assert.ok(buffer instanceof Buffer);
4144
});
4245
});
@@ -46,7 +49,7 @@ describe('Buffer', () => {
4649
*/
4750
describe('setBufferSize', () => {
4851
it('should return the Buffer instance', () => {
49-
const buffer = new Buffer(exporter);
52+
const buffer = new Buffer(exporter, defaultBufferConfig);
5053
const bufferResize = buffer.setBufferSize(DEFAULT_BUFFER_SIZE);
5154
assert.ok(bufferResize instanceof Buffer);
5255
});
@@ -57,7 +60,7 @@ describe('Buffer', () => {
5760
*/
5861
describe('addToBuffer', () => {
5962
it('should return the Buffer instance', () => {
60-
const buffer = new Buffer(exporter);
63+
const buffer = new Buffer(exporter, defaultBufferConfig);
6164
const rootSpan = new RootSpanImpl(tracer);
6265
const bufferAdd = buffer.addToBuffer(rootSpan);
6366
assert.ok(bufferAdd instanceof Buffer);
@@ -69,7 +72,7 @@ describe('Buffer', () => {
6972
*/
7073
describe('addToBuffer force flush ', () => {
7174
it('should return the Buffer instance', () => {
72-
const buffer = new Buffer(exporter);
75+
const buffer = new Buffer(exporter, defaultBufferConfig);
7376
const bufferResize = buffer.setBufferSize(0);
7477
const rootSpan = new RootSpanImpl(tracer);
7578
const bufferAdd = bufferResize.addToBuffer(rootSpan);
@@ -82,7 +85,8 @@ describe('Buffer', () => {
8285
*/
8386
describe('addToBuffer force flush by timeout ', () => {
8487
it('should return the Buffer instance', () => {
85-
const buffer = new Buffer(exporter, DEFAULT_BUFFER_SIZE, 0);
88+
const buffer = new Buffer(
89+
exporter, {bufferSize: DEFAULT_BUFFER_SIZE, bufferTimeout: 0});
8690
const rootSpan = new RootSpanImpl(tracer);
8791
let bufferAdd = buffer.addToBuffer(rootSpan);
8892
bufferAdd = buffer.addToBuffer(rootSpan);

0 commit comments

Comments
 (0)