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

Commit d01e0f4

Browse files
luanamartinssantossilva-fabio
authored andcommitted
refactor: remove Impl classes suffixes and use module namespace for types
1 parent 81f9dfb commit d01e0f4

15 files changed

Lines changed: 165 additions & 175 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ export * from './trace/sampler/types';
2121
export * from './trace/instrumentation/types';
2222
export * from './exporters/types';
2323
export * from './common/types';
24-

packages/opencensus-core/src/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ export * from './trace/instrumentation/types';
2424
export * from './exporters/types';
2525
export * from './common/types';
2626

27-
// domain models impls
28-
export * from './trace/model/root-span';
29-
export * from './trace/model/span';
30-
export * from './trace/model/tracer';
31-
export * from './common/console-logger';
32-
33-
// sampler impl
34-
export * from './trace/sampler/sampler';
35-
3627
// base instrumetation class
3728
export * from './trace/instrumentation/base-plugin';
3829

@@ -41,4 +32,7 @@ export * from './exporters/buffer';
4132
export * from './exporters/console-exporter';
4233

4334
// util
44-
export * from './internal/util';
35+
export * from './internal/util';
36+
37+
import * as types from './index-types';
38+
export {types};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* limitations under the License.
1515
*/
1616
import * as shimmer from 'shimmer';
17-
import {Plugin} from './types';
17+
import * as types from './types';
1818
import {Tracer} from '../model/types';
1919

2020
/** This class represent the base to patch plugin. */
21-
export abstract class BasePlugin implements Plugin {
21+
export abstract class BasePlugin implements types.Plugin {
22+
2223
/** The service to send the collected traces */
2324
// tslint:disable:no-any
2425
protected exporter: any;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import * as uuid from 'uuid';
1919
import {Clock} from '../../internal/clock';
2020
import {debug} from '../../internal/util';
2121

22-
import {SpanImpl} from './span';
22+
import {Span} from './span';
2323
import {SpanBaseModel} from './span-base-model';
24-
import {TracerImpl} from './tracer';
25-
import {OnEndSpanEventListener, RootSpan, Span, TraceContext, TraceOptions, Tracer} from './types';
24+
import {Tracer} from './tracer';
2625

2726
import * as logger from '../../common/console-logger';
27+
import * as types from './types';
2828

2929
/** Defines a root span */
30-
export class RootSpanImpl extends SpanBaseModel implements RootSpan {
30+
export class RootSpan extends SpanBaseModel implements types.RootSpan {
3131
/** A tracer object */
3232
private tracer: Tracer;
3333
/** A list of child spans. */
@@ -40,7 +40,7 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
4040
* @param tracer A tracer object.
4141
* @param context A trace options object to build the root span.
4242
*/
43-
constructor(tracer: Tracer, context?: TraceOptions) {
43+
constructor(tracer: Tracer, context?: types.TraceOptions) {
4444
super();
4545
this.tracer = tracer;
4646
this.traceIdLocal =
@@ -113,15 +113,15 @@ export class RootSpanImpl extends SpanBaseModel implements RootSpan {
113113
this.logger.debug(
114114
'calling %s.startSpan() on ended %s %o', this.className,
115115
this.className, {id: this.id, name: this.name, type: this.type});
116-
return;
116+
return null;
117117
}
118118
if (!this.started) {
119119
this.logger.debug(
120120
'calling %s.startSpan() on un-started %s %o', this.className,
121121
this.className, {id: this.id, name: this.name, type: this.type});
122-
return;
122+
return null;
123123
}
124-
const newSpan = new SpanImpl(this);
124+
const newSpan = new Span(this);
125125
if (name) {
126126
newSpan.name = name;
127127
}

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

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

17+
import {Logger} from '../../common/types';
1718
import {Clock} from '../../internal/clock';
1819
import {debug, randomSpanId} from '../../internal/util';
19-
import {Sampler} from '../sampler/types';
20-
21-
import {Annotation, Attributes, Link, MessageEvent, Span, TraceContext} from './types';
22-
import {Logger} from '../../common/types';
20+
import * as types from './types';
2321

2422
/** Defines a base model for spans. */
25-
export abstract class SpanBaseModel implements Span {
23+
export abstract class SpanBaseModel implements types.Span {
2624
protected className: string;
2725
/** The clock used to mesure the beginning and ending of a span */
2826
private clock: Clock = null;
@@ -37,13 +35,13 @@ export abstract class SpanBaseModel implements Span {
3735
/** An object to log information to */
3836
logger: Logger;
3937
/** A set of attributes, each in the format [KEY]:[VALUE] */
40-
attributes: Attributes = {};
38+
attributes: types.Attributes = {};
4139
/** A text annotation with a set of attributes. */
42-
annotations: Annotation[] = [];
40+
annotations: types.Annotation[] = [];
4341
/** An event describing a message sent/received between Spans */
44-
messageEvents: MessageEvent[] = [];
42+
messageEvents: types.MessageEvent[] = [];
4543
/** Pointers from the current span to another span */
46-
links: Link[] = [];
44+
links: types.Link[] = [];
4745
/** If the parent span is in another process. */
4846
remoteParent: boolean;
4947
/** The span ID of this span's parent. If it's a root span, must be empty */
@@ -115,12 +113,12 @@ export abstract class SpanBaseModel implements Span {
115113
}
116114

117115
/** Gives the TraceContext of the span. */
118-
get traceContext(): TraceContext {
116+
get traceContext(): types.TraceContext {
119117
return {
120118
traceId: this.traceId.toString(),
121119
spanId: this.id.toString(),
122120
parentSpanId: this.parentSpanId
123-
} as TraceContext;
121+
} as types.TraceContext;
124122
}
125123

126124
/**
@@ -139,12 +137,12 @@ export abstract class SpanBaseModel implements Span {
139137
* @param attributes A set of attributes on the annotation.
140138
*/
141139
addAnnotation(
142-
description: string, timestamp: number, attributes?: Attributes) {
140+
description: string, timestamp: number, attributes?: types.Attributes) {
143141
this.annotations.push({
144142
'description': description,
145143
'timestamp': timestamp,
146144
'attributes': attributes,
147-
} as Annotation);
145+
} as types.Annotation);
148146
}
149147

150148
/**
@@ -155,13 +153,13 @@ export abstract class SpanBaseModel implements Span {
155153
* @param attributes A set of attributes on the link.
156154
*/
157155
addLink(
158-
traceId: string, spanId: string, type: string, attributes?: Attributes) {
156+
traceId: string, spanId: string, type: string, attributes?: types.Attributes) {
159157
this.links.push({
160158
'traceId': traceId,
161159
'spanId': spanId,
162160
'type': type,
163161
'attributes': attributes
164-
} as Link);
162+
} as types.Link);
165163
}
166164

167165
/**
@@ -173,7 +171,7 @@ export abstract class SpanBaseModel implements Span {
173171
this.messageEvents.push({
174172
'type': type,
175173
'id': id,
176-
} as MessageEvent);
174+
} as types.MessageEvent);
177175
}
178176

179177
/** Starts the span. */

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
import {debug, randomSpanId} from '../../internal/util';
1818

19-
import {RootSpanImpl} from './root-span';
19+
import {RootSpan} from './root-span';
2020
import {SpanBaseModel} from './span-base-model';
21-
import {RootSpan, Span, TraceContext} from './types';
2221

2322
import * as logger from '../../common/console-logger';
23+
import * as types from './types';
2424

2525
/** Defines a Span. */
26-
export class SpanImpl extends SpanBaseModel implements Span {
26+
export class Span extends SpanBaseModel implements types.Span {
2727
private root: RootSpan;
2828

2929
/**
@@ -42,7 +42,7 @@ export class SpanImpl extends SpanBaseModel implements Span {
4242
}
4343

4444
/** Gets trace context of span. */
45-
get traceContext(): TraceContext {
45+
get traceContext(): types.TraceContext {
4646
return {
4747
traceId: this.traceId.toString(),
4848
spanId: this.id.toString(),

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@
1616

1717
import * as cls from '../../internal/cls';
1818
import {debug} from '../../internal/util';
19-
import {SamplerImpl} from '../sampler/sampler';
19+
import {Sampler} from '../sampler/sampler';
2020
import {TracerConfig} from '../config/types';
21-
import {Sampler} from '../sampler/types';
2221

2322
import {Config} from '../config/types';
2423

25-
import {RootSpanImpl} from './root-span';
26-
import {SpanImpl} from './span';
27-
import {RootSpan, Span} from './types';
28-
import {TraceOptions, Tracer} from './types';
24+
import {RootSpan} from './root-span';
25+
import {Span} from './span';
26+
import {TraceOptions} from './types';
2927
import {Func, OnEndSpanEventListener} from './types';
3028
import {Logger} from '../../common/types';
29+
import * as types from './types';
3130

3231
import * as logger from '../../common/console-logger';
3332

3433
/**
3534
* This class represent a tracer.
3635
*/
37-
export class TracerImpl implements Tracer {
36+
export class Tracer implements types.Tracer {
3837
/** Indicates if the tracer is active */
3938
private activeLocal: boolean;
4039
/** TODO */
@@ -75,7 +74,7 @@ export class TracerImpl implements Tracer {
7574
this.activeLocal = true;
7675
this.config = config;
7776
this.logger = this.config.logger || logger.logger();
78-
this.sampler = new SamplerImpl().probability(config.samplingRate);
77+
this.sampler = new Sampler().probability(config.samplingRate);
7978
return this;
8079
}
8180

@@ -103,7 +102,7 @@ export class TracerImpl implements Tracer {
103102
return this.contextManager.runAndReturn((root) => {
104103
let newRoot = null;
105104
if (this.active) {
106-
newRoot = new RootSpanImpl(this, options);
105+
newRoot = new RootSpan(this, options);
107106
if (this.sampler.shouldSample(newRoot.traceId)) {
108107
newRoot.start();
109108
this.currentRootSpan = newRoot;

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

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

1717
import {debug, randomSpanId} from '../../internal/util';
18-
import {Sampler} from './types';
18+
import * as types from './types';
1919

2020
const MIN_NUMBER = 1e-4;
2121
const MAX_NUMBER = 0xffffffffffffffff;
2222

2323
/** This class represent the probability of a tracer. */
24-
export class SamplerImpl implements Sampler {
24+
export class Sampler implements types.Sampler {
2525
private idUpperBound: number;
2626

2727
/**

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import * as mocha from 'mocha';
1919

2020
import {Buffer} from '../src/exporters/buffer';
2121
import {NoopExporter} from '../src/exporters/console-exporter';
22-
import {RootSpanImpl} from '../src/trace/model/root-span';
23-
import {TracerImpl} from '../src/trace/model/tracer';
22+
import {RootSpan} from '../src/trace/model/root-span';
23+
import {Tracer} from '../src/trace/model/tracer';
2424

2525
const exporter = new NoopExporter();
2626
const DEFAULT_BUFFER_SIZE = 3;
2727
const DEFAULT_BUFFER_TIMEOUT = 20000; // time in milliseconds
28-
const tracer = new TracerImpl();
28+
const tracer = new Tracer();
2929

3030
const defaultBufferConfig = {
3131
bufferSize: DEFAULT_BUFFER_SIZE,
@@ -61,7 +61,7 @@ describe('Buffer', () => {
6161
describe('addToBuffer', () => {
6262
it('should return the Buffer instance', () => {
6363
const buffer = new Buffer(exporter, defaultBufferConfig);
64-
const rootSpan = new RootSpanImpl(tracer);
64+
const rootSpan = new RootSpan(tracer);
6565
const bufferAdd = buffer.addToBuffer(rootSpan);
6666
assert.ok(bufferAdd instanceof Buffer);
6767
});
@@ -74,7 +74,7 @@ describe('Buffer', () => {
7474
it('should return the Buffer instance', () => {
7575
const buffer = new Buffer(exporter, defaultBufferConfig);
7676
const bufferResize = buffer.setBufferSize(0);
77-
const rootSpan = new RootSpanImpl(tracer);
77+
const rootSpan = new RootSpan(tracer);
7878
const bufferAdd = bufferResize.addToBuffer(rootSpan);
7979
assert.ok(bufferAdd instanceof Buffer);
8080
});
@@ -87,7 +87,7 @@ describe('Buffer', () => {
8787
it('should return the Buffer instance', () => {
8888
const buffer = new Buffer(
8989
exporter, {bufferSize: DEFAULT_BUFFER_SIZE, bufferTimeout: 0});
90-
const rootSpan = new RootSpanImpl(tracer);
90+
const rootSpan = new RootSpan(tracer);
9191
let bufferAdd = buffer.addToBuffer(rootSpan);
9292
bufferAdd = buffer.addToBuffer(rootSpan);
9393
assert.ok(bufferAdd instanceof Buffer);

packages/opencensus-core/test/test-console-exporter.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ import * as mocha from 'mocha';
1919

2020
import {Buffer} from '../src/exporters/buffer';
2121
import {ConsoleExporter, NoopExporter} from '../src/exporters/console-exporter';
22-
import {RootSpanImpl} from '../src/trace/model/root-span';
23-
import {TracerImpl} from '../src/trace/model/tracer';
24-
import {RootSpan} from '../src/trace/model/types';
22+
import {RootSpan} from '../src/trace/model/root-span';
23+
import {Tracer} from '../src/trace/model/tracer';
2524

26-
const tracer = new TracerImpl();
25+
const tracer = new Tracer();
2726
const DEFAULT_BUFFER_SIZE = 3;
2827
const DEFAULT_BUFFER_TIMEOUT = 20000; // time in milliseconds
2928
const defaultBufferConfig = {
@@ -36,7 +35,7 @@ describe('NoopExporter', () => {
3635
describe('onEndSpan()', () => {
3736
it('should do anything', () => {
3837
const exporter = new NoopExporter();
39-
const rootSpan = new RootSpanImpl(tracer);
38+
const rootSpan = new RootSpan(tracer);
4039
exporter.onEndSpan(rootSpan);
4140
assert.ok(true);
4241
});
@@ -46,7 +45,7 @@ describe('NoopExporter', () => {
4645
describe('publish()', () => {
4746
it('should do anything', () => {
4847
const exporter = new NoopExporter();
49-
const rootSpan = new RootSpanImpl(tracer);
48+
const rootSpan = new RootSpan(tracer);
5049
const queue: RootSpan[] = [];
5150
queue.push(rootSpan);
5251

@@ -61,7 +60,7 @@ describe('ConsoleLogExporter', () => {
6160
describe('onEndSpan()', () => {
6261
it('should end a span', () => {
6362
const exporter = new ConsoleExporter(defaultBufferConfig);
64-
const rootSpan = new RootSpanImpl(tracer);
63+
const rootSpan = new RootSpan(tracer);
6564
exporter.onEndSpan(rootSpan);
6665
assert.ok(true);
6766
});
@@ -71,7 +70,7 @@ describe('ConsoleLogExporter', () => {
7170
describe('publish()', () => {
7271
it('should publish the rootspans in queue', () => {
7372
const exporter = new ConsoleExporter(defaultBufferConfig);
74-
const rootSpan = new RootSpanImpl(tracer);
73+
const rootSpan = new RootSpan(tracer);
7574
rootSpan.startSpan('name', 'type', rootSpan.traceId);
7675
const queue: RootSpan[] = [];
7776
queue.push(rootSpan);

0 commit comments

Comments
 (0)