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

Commit 4a9731a

Browse files
eduardoemerysilva-fabio
authored andcommitted
refactor: add jsdoc to core package
1 parent fc92980 commit 4a9731a

14 files changed

Lines changed: 325 additions & 213 deletions

File tree

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import {Exporter} from './types';
2424
import {Config, BufferConfig} from '../trace/config/types';
2525

2626

27-
/**
28-
* Controls the sending of traces to exporters
29-
*/
27+
/** Controls the sending of traces to exporters. */
3028
export class Buffer {
29+
/** The service to send the collected spans. */
3130
private exporter: Exporter;
31+
/** Maximum size of a buffer. */
3232
private bufferSize: number;
3333
/** Trace queue of a buffer */
3434
private queue: RootSpan[] = [];
@@ -39,6 +39,11 @@ export class Buffer {
3939
/** Indicates when the buffer timeout is running */
4040
private bufferTimeoutInProgress = false;
4141

42+
/**
43+
* Constructs a new Buffer instance.
44+
* @param exporter The service to send the collected spans.
45+
* @param config A buffer configuration object to create a buffer.
46+
*/
4247
constructor(exporter: Exporter, config: BufferConfig) {
4348
this.exporter = exporter;
4449
this.bufferSize = config.bufferSize;
@@ -47,17 +52,17 @@ export class Buffer {
4752
}
4853

4954
/**
50-
* Set the buffer size value
51-
* @param bufferSize The new buffer size
55+
* Set the buffer size value.
56+
* @param bufferSize The new buffer size.
5257
*/
5358
setBufferSize(bufferSize: number) {
5459
this.bufferSize = bufferSize;
5560
return this;
5661
}
5762

5863
/**
59-
* Add a trace (rootSpan) in the buffer
60-
* @param trace RootSpan to be added in the buffer
64+
* Add a trace (rootSpan) in the buffer.
65+
* @param trace RootSpan to be added in the buffer.
6166
*/
6267
addToBuffer(trace: RootSpan) {
6368
this.queue.push(trace);

packages/opencensus-core/src/exporters/console-exporter.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {RootSpan} from '../trace/model/types';
1919
import {Buffer} from './buffer';
2020

2121

22-
2322
/** Do not send span data */
2423
export class NoopExporter implements Exporter {
2524
onEndSpan(root: RootSpan) {}
@@ -28,12 +27,22 @@ export class NoopExporter implements Exporter {
2827

2928
/** Format and sends span data to the console. */
3029
export class ConsoleLogExporter implements Exporter {
30+
/** Buffer object to store the spans. */
3131
private buffer: Buffer;
3232

33+
/**
34+
* Constructs a new ConsoleLogExporter instance.
35+
* @param config Exporter configuration object to create a console log
36+
* exporter.
37+
*/
3338
constructor(config: ExporterConfig) {
3439
this.buffer = new Buffer(this, config);
3540
}
3641

42+
/**
43+
* Event called when a span is ended.
44+
* @param root Ended span.
45+
*/
3746
onEndSpan(root: RootSpan) {
3847
this.buffer.addToBuffer(root);
3948
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616

1717

1818
import {OnEndSpanEventListener, RootSpan} from '../trace/model/types';
19-
import { BufferConfig } from '../trace/config/types';
19+
import {BufferConfig} from '../trace/config/types';
2020

21+
/** Defines an exporter interface. */
2122
export interface Exporter extends OnEndSpanEventListener {
23+
24+
/**
25+
* Sends a list of root spans to the service.
26+
* @param rootSpans A list of root spans to publish.
27+
*/
2228
publish(rootSpans: RootSpan[]);
2329
}
2430

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

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

17+
/** Defines a Clock. */
1718
export class Clock {
18-
private endedLocal: boolean;
19+
/** Indicates if the clock is endend. */
20+
private endedLocal = false;
21+
/** Indicates the clock's start time. */
1922
private startTimeLocal: Date;
23+
/** The time in high resolution in a [seconds, nanoseconds]. */
2024
private hrtimeLocal: [number, number];
21-
private diff: [number, number];
25+
/** The duration between start and end of the clock. */
26+
private diff: [number, number] = null;
2227

28+
/** Constructs a new SamplerImpl instance. */
2329
constructor() {
24-
this.endedLocal = false;
2530
this.startTimeLocal = new Date();
2631
this.hrtimeLocal = process.hrtime();
27-
this.diff = null;
2832
}
2933

34+
/** Ends the clock. */
3035
end(): void {
3136
if (this.endedLocal) {
3237
return;
@@ -35,6 +40,7 @@ export class Clock {
3540
this.endedLocal = true;
3641
}
3742

43+
/** Gets the duration of the clock. */
3844
get duration(): number {
3945
if (!this.endedLocal) {
4046
return null;
@@ -43,21 +49,31 @@ export class Clock {
4349
return ns / 1e6;
4450
}
4551

52+
/**
53+
* Compares clock with another one.
54+
* @param timer A clock object to compare.
55+
*/
4656
offset(timer: Clock): number {
4757
const a = timer.hrtime;
4858
const b = this.hrtime;
4959
const ns = (b[0] - a[0]) * 1e9 + (b[1] - a[1]);
5060
return ns / 1e6;
5161
}
5262

63+
/** Gets the time in high definition. */
5364
get hrtime(): [number, number] {
5465
return this.hrtimeLocal;
5566
}
5667

68+
/** Starts the clock. */
5769
get startTime(): Date {
5870
return this.startTimeLocal;
5971
}
6072

73+
/**
74+
* Gets the time so far.
75+
* @returns A Date object with the current duration.
76+
*/
6177
get endTime(): Date {
6278
let result: Date = null;
6379
if (this.ended) {
@@ -66,6 +82,7 @@ export class Clock {
6682
return result;
6783
}
6884

85+
/** Indicates if the clock was ended. */
6986
get ended(): boolean {
7087
return this.endedLocal;
7188
}

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
11
import {Exporter} from '../../exporters/types';
22
import {PluginNames} from '../instrumentation/types';
33

4-
/**
5-
* This interface represent the probability of a tracer.
6-
*/
4+
/** This interface represent the probability of a tracer. */
75
export interface Sampler {
8-
96
/**
10-
* Set idUpperBound with MAX_NUMBER that is equivalent the probability be 1
11-
* @returns a Sampler object
7+
* Sets idUpperBound with MAX_NUMBER that is equivalent the probability be 1.
8+
* @returns a Sampler object.
129
*/
13-
1410
always(): Sampler;
11+
1512
/**
16-
* Set idUpperBound with MIN_NUMBER that is equivalent the probability be 0
17-
* @returns a Sampler object
13+
* Sets idUpperBound with MIN_NUMBER that is equivalent the probability be 0.
14+
* @returns a Sampler object.
1815
*/
19-
2016
never(): Sampler;
2117

2218
/**
23-
* Set idUpperBound with the probability. If probability
19+
* Sets idUpperBound with the probability. If probability
2420
* parameter is bigger then 1 set always. If probability parameter less
2521
* than 0, set never.
26-
* @param probability probability between 0 and 1
27-
* @returns a Sampler object
22+
* @param probability probability between 0 and 1.
23+
* @returns a Sampler object.
2824
*/
2925
probability(probability: number): Sampler;
3026

3127
/**
3228
* Checks if trace belong the sample.
33-
* @param traceId Used to check the probability
29+
* @param traceId Used to check the probability.
3430
* @returns a boolean. True if the traceId is in probability
3531
* False if the traceId is not in probability.
3632
*/
3733
shouldSample(traceId: string): boolean;
3834
}
3935

40-
/**
41-
* Interface configuration for a buffer
42-
*/
36+
/** Interface configuration for a buffer. */
4337
export interface BufferConfig {
4438
bufferSize?: number;
4539
bufferTimeout?: number;

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

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,28 @@
1616
import * as shimmer from 'shimmer';
1717
import {Tracer} from '../model/types';
1818

19-
/**
20-
* This class represent the base to patch plugin
21-
*/
19+
/** This class represent the base to patch plugin. */
2220
export abstract class BasePlugin {
21+
/** The service to send the collected traces */
2322
// tslint:disable:no-any
2423
exporter: any;
24+
/** The module name */
2525
moduleName: string;
26+
/** A tracer object. */
2627
tracer: Tracer;
28+
/** The module version. */
2729
version: string;
2830

31+
/**
32+
* Constructs a new BasePlugin instance.
33+
* @param moduleName The module name.
34+
*/
2935
constructor(moduleName: string) {
3036
this.moduleName = moduleName;
3137
}
38+
3239
/**
33-
* Set modified plugin to the context.
40+
* Sets modified plugin to the context.
3441
* @param exporter object module to set on context
3542
* @param tracer tracer relating to context
3643
* @param version module version description
@@ -42,21 +49,42 @@ export abstract class BasePlugin {
4249
this.version = version;
4350
}
4451

52+
/**
53+
* Wraps a function.
54+
* @param nodule The module.
55+
* @param name The function name.
56+
* @param wrapper The wrapper.
57+
*/
4558
protected wrap(nodule, name, wrapper) {
4659
shimmer.wrap(nodule, name, wrapper);
4760
}
4861

62+
/**
63+
* Unwraps a function.
64+
* @param nodule The module.
65+
* @param name The function name.
66+
*/
4967
protected unwrap(nodule, name) {
5068
shimmer.unwrap(nodule, name);
5169
}
5270

71+
/**
72+
* Wraps one or more funcitons.
73+
* @param nodule The module.
74+
* @param names A list of function names.
75+
* @param wrapper The wrapper.
76+
*/
5377
protected massWrap(nodule,names, wrapper) {
5478
shimmer.massWrap(nodule, names, wrapper);
5579
}
5680

81+
/**
82+
* Unwraps one or more functions.
83+
* @param nodule The module.
84+
* @param names The list of function names.
85+
*/
5786
protected massUnwrap(nodule,names) {
5887
shimmer.massUnwrap(nodule, names);
5988
}
6089

61-
6290
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
import {Tracer} from "../model/types";
1818

19-
/**
20-
* Interface Plugin to apply patch.
21-
*/
19+
/** Interface Plugin to apply patch. */
2220
export interface Plugin {
2321
// tslint:disable:no-any
2422
applyPatch(module: {}, tracer: Tracer, version: string): any;

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@ import {OnEndSpanEventListener, RootSpan, Span, TraceContext, TraceOptions, Trac
2626

2727
/** Defines a root span */
2828
export class RootSpanImpl extends SpanBaseModel implements RootSpan {
29+
/** A tracer object */
2930
private tracer: Tracer;
31+
/** A list of child spans. */
3032
private spansLocal: Span[];
33+
/** It's trace ID. */
3134
private traceIdLocal: string;
3235

33-
// TODO - improve root name setup
36+
/**
37+
* Constructs a new RootSpanImpl instance.
38+
* @param tracer A tracer object.
39+
* @param context A trace options object to build the root span.
40+
*/
3441
constructor(tracer: Tracer, context?: TraceOptions) {
3542
super();
3643
this.tracer = tracer;
@@ -45,25 +52,25 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
4552
this.spansLocal = [];
4653
}
4754

48-
/** Get span list from rootspan instance */
55+
/** Gets span list from rootspan instance. */
4956
get spans(): Span[] {
5057
return this.spansLocal;
5158
}
5259

53-
/** Get trace id from rootspan instance */
60+
/** Gets trace id from rootspan instance. */
5461
get traceId(): string {
5562
return this.traceIdLocal;
5663
}
5764

58-
/** Start a rootspan instance */
65+
/** Starts a rootspan instance. */
5966
start() {
6067
super.start();
6168
debug(
6269
'starting %s %o', this.className,
6370
{traceId: this.traceId, id: this.id, parentSpanId: this.parentSpanId});
6471
}
6572

66-
/** End a rootspan instance */
73+
/** Ends a rootspan instance. */
6774
end() {
6875
super.end();
6976

@@ -78,8 +85,8 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
7885
}
7986

8087
/**
81-
* Event called when a span ended
82-
* @param span Span ended
88+
* Event called when a span is ended.
89+
* @param span Span ended.
8390
*/
8491
onEndSpan(span: Span) {
8592
debug('ending span %o', {
@@ -93,10 +100,10 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
93100
}
94101

95102
/**
96-
* Start a new span linked with the rootspan
97-
* @param name Span name
98-
* @param type Span type
99-
* @param parentSpanId Span parent ID
103+
* Starts a new child span in the root span.
104+
* @param name Span name.
105+
* @param type Span type.
106+
* @param parentSpanId Span parent ID.
100107
*/
101108
startSpan(name: string, type: string, parentSpanId?: string) {
102109
if (this.ended) {

0 commit comments

Comments
 (0)