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

Commit 4707152

Browse files
committed
refactor: rework according to review follow up
1 parent b90d44c commit 4707152

8 files changed

Lines changed: 29 additions & 70 deletions

File tree

packages/opencensus-core/src/common/console-logger.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@ export class ConsoleLogger implements types.Logger {
3030
static LEVELS = ['silent', 'error', 'warn', 'info', 'debug', 'silly'];
3131
level: string;
3232

33+
34+
// TODO: reevaluate options to accept numbers as a parameter
35+
3336
/**
3437
* Constructs a new ConsoleLogger instance
3538
* @param options A logger configuration object.
3639
*/
37-
constructor(options?: types.LoggerOptions|string) {
40+
constructor(options?: types.LoggerOptions|string|number) {
3841
let opt: types.LoggerOptions = {};
39-
if (typeof options === 'string') {
42+
if (typeof options === 'number') {
43+
if (options < 0) {
44+
options = 0;
45+
} else if (options > ConsoleLogger.LEVELS.length) {
46+
options = ConsoleLogger.LEVELS.length - 1;
47+
}
48+
opt = {level: ConsoleLogger.LEVELS[options]};
49+
} else if (typeof options === 'string') {
4050
opt = {level: options};
4151
} else {
4252
opt = options || {};
@@ -98,24 +108,15 @@ export class ConsoleLogger implements types.Logger {
98108
}
99109

100110

111+
// TODO: reevaluate the need to create a new logger instance on every call to
112+
// logger();
113+
101114
/**
102115
* Function logger exported to others classes.
103116
* @param options A logger options or strig to logger in console
104117
*/
105118
const logger = (options?: types.LoggerOptions|string|number) => {
106-
let opt: types.LoggerOptions|string;
107-
if (typeof options === 'number') {
108-
if (options < 0) {
109-
options = 0;
110-
} else if (options > ConsoleLogger.LEVELS.length) {
111-
options = ConsoleLogger.LEVELS.length - 1;
112-
}
113-
opt = {level: ConsoleLogger.LEVELS[options]};
114-
} else {
115-
opt = options;
116-
}
117-
118-
const aLogger = new ConsoleLogger(opt);
119+
const aLogger = new ConsoleLogger(options);
119120
logger['logger'] = aLogger;
120121
return aLogger;
121122
};

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -53,43 +53,6 @@ export abstract class BasePlugin implements types.Plugin {
5353
this.version = version;
5454
}
5555

56-
/**
57-
* Wraps a function.
58-
* @param nodule The module.
59-
* @param name The function name.
60-
* @param wrapper The wrapper.
61-
*/
62-
protected wrap(nodule, name, wrapper) {
63-
shimmer.wrap(nodule, name, wrapper);
64-
}
65-
66-
/**
67-
* Unwraps a function.
68-
* @param nodule The module.
69-
* @param name The function name.
70-
*/
71-
protected unwrap(nodule, name) {
72-
shimmer.unwrap(nodule, name);
73-
}
74-
75-
/**
76-
* Wraps one or more funcitons.
77-
* @param nodule The module.
78-
* @param names A list of function names.
79-
* @param wrapper The wrapper.
80-
*/
81-
protected massWrap(nodule, names, wrapper) {
82-
shimmer.massWrap(nodule, names, wrapper);
83-
}
84-
85-
/**
86-
* Unwraps one or more functions.
87-
* @param nodule The module.
88-
* @param names The list of function names.
89-
*/
90-
protected massUnwrap(nodule, names) {
91-
shimmer.massUnwrap(nodule, names);
92-
}
9356

9457
// TODO: review this implementation
9558
// From the perspective of an instrumentation module author,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,13 @@ export class Tracer implements types.Tracer {
181181
* @param type The span type.
182182
* @param parentSpanId The parent span ID.
183183
*/
184-
startChildSpan(name?: string, type?: string, parentSpanId?: string):
185-
types.Span {
184+
startChildSpan(name?: string, type?: string): types.Span {
186185
let newSpan: types.Span = null;
187186
if (!this.currentRootSpan) {
188187
this.logger.debug(
189188
'no current trace found - must start a new root span first');
190189
} else {
191-
newSpan = this.currentRootSpan.startChildSpan(name, type, parentSpanId);
190+
newSpan = this.currentRootSpan.startChildSpan(name, type);
192191
}
193192
return newSpan;
194193
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export interface RootSpan extends Span {
207207
end(): void;
208208

209209
/** Starts a new Span instance in the RootSpan instance */
210-
startChildSpan(name: string, type: string, parentSpanId?: string): Span;
210+
startChildSpan(name: string, type: string): Span;
211211
}
212212

213213

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ import * as mocha from 'mocha';
2020
import * as logger from '../src/common/console-logger';
2121
import {ConsoleLogger} from '../src/common/console-logger';
2222
import {Logger} from '../src/common/types';
23-
import {ConsoleExporter} from '../src/exporters/console-exporter';
24-
import {ExporterBuffer} from '../src/exporters/exporter-buffer';
25-
import {BufferConfig, TracerConfig} from '../src/trace/config/types';
26-
import {RootSpan} from '../src/trace/model/root-span';
27-
import {Tracer} from '../src/trace/model/tracer';
28-
import {TraceOptions} from '../src/trace/model/types';
23+
2924

3025
const LEVELS = ['silent', 'error', 'warn', 'info', 'debug', 'silly'];
3126
let consoleTxt = '';

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ describe('ExporterBuffer', () => {
6767
describe('setBufferSize', () => {
6868
it('should set BufferSize', () => {
6969
const buffer = new ExporterBuffer(exporter, defaultBufferConfig);
70-
const bufferResize = buffer.setBufferSize(DEFAULT_BUFFER_SIZE);
70+
const newBufferSize = DEFAULT_BUFFER_SIZE + 10;
71+
const bufferResize = buffer.setBufferSize(newBufferSize);
7172
assert.ok(bufferResize instanceof ExporterBuffer);
72-
assert.strictEqual(bufferResize.getBufferSize(), DEFAULT_BUFFER_SIZE);
73+
assert.strictEqual(bufferResize.getBufferSize(), newBufferSize);
7374
});
7475
});
7576

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ describe('Sampler', () => {
3535
const samplerShouldSampler = sampler.shouldSample(root.traceId);
3636
assert.ok(samplerShouldSampler);
3737
});
38-
it('should return a always sampler', () => {
38+
it('should return a always sampler for 1', () => {
3939
const root = new RootSpan(tracer);
4040
const sampler = new Sampler().probability(1);
4141
const samplerShouldSampler = sampler.shouldSample(root.traceId);
4242
assert.strictEqual(sampler.description, 'always');
4343
assert.ok(samplerShouldSampler);
4444
});
45-
it('should return a always sampler', () => {
45+
it('should return a always sampler for >1', () => {
4646
const root = new RootSpan(tracer);
4747
const sampler = new Sampler().probability(100);
4848
const samplerShouldSampler = sampler.shouldSample(root.traceId);
@@ -61,14 +61,14 @@ describe('Sampler', () => {
6161
const samplerShouldSampler = sampler.shouldSample(root.traceId);
6262
assert.ok(!samplerShouldSampler);
6363
});
64-
it('should return a never sampler', () => {
64+
it('should return a never sampler for 0', () => {
6565
const root = new RootSpan(tracer);
6666
const sampler = new Sampler().probability(0);
6767
const samplerShouldSampler = sampler.shouldSample(root.traceId);
6868
assert.strictEqual(sampler.description, 'never');
6969
assert.ok(!samplerShouldSampler);
7070
});
71-
it('should return a never sampler', () => {
71+
it('should return a never sampler for negative value', () => {
7272
const root = new RootSpan(tracer);
7373
const sampler = new Sampler().probability(-1);
7474
const samplerShouldSampler = sampler.shouldSample(root.traceId);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe('Tracer', () => {
199199
} as types.SpanContext;
200200

201201

202-
it('should reate the new RootSpan with propagation', () => {
202+
it('should create the new RootSpan with propagation', () => {
203203
const tracer = new Tracer();
204204
tracer.start(defaultConfig);
205205
traceOptions.spanContext = spanContextPropagated;
@@ -212,7 +212,7 @@ describe('Tracer', () => {
212212
});
213213
});
214214

215-
it('should reate the new RootSpan with no propagation', () => {
215+
it('should create the new RootSpan with no propagation', () => {
216216
const tracer = new Tracer();
217217
tracer.start(defaultConfig);
218218
traceOptions.spanContext.options = 0x0;

0 commit comments

Comments
 (0)