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

Commit fccd268

Browse files
committed
refactor: type, classes overall refactoring
1 parent f7a6019 commit fccd268

23 files changed

Lines changed: 811 additions & 517 deletions

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"types": "build/src/index.d.js",
77
"repository": "census-instrumentation/opencensus-node",
88
"scripts": {
9-
"postinstall": "scripts/update_lerna_modules_links.sh"
9+
"postinstall": "npm run bootstrap;npm run build;",
10+
"build" : "node_modules/.bin/lerna run build",
11+
"bootstrap": "node_modules/.bin/lerna bootstrap",
12+
"bump": "node_modules/.bin/lerna publish"
1013
},
1114
"keywords": [
1215
"opencensus",

packages/opencensus-core/package-lock.json

Lines changed: 335 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-core/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"repository": "census-instrumentation/opencensus-node",
88
"scripts": {
99
"build": "node_modules/.bin/tsc --declaration",
10-
"test": "npm run script run-unit-tests",
10+
"test": "node_modules/.bin/mocha 'build/test/**/*.js' --reporter spec",
1111
"clean": "rimraf build/*"
1212
},
1313
"keywords": [
@@ -38,6 +38,7 @@
3838
"@types/mocha": "^2.2.48",
3939
"@types/node": "^9.4.7",
4040
"@types/semver": "^5.5.0",
41+
"@types/shimmer": "^1.0.1",
4142
"@types/uuid": "^3.4.3",
4243
"gts": "^0.5.1",
4344
"mocha": "^5.0.4",
@@ -50,6 +51,7 @@
5051
"continuation-local-storage": "^3.2.1",
5152
"debug": "^3.1.0",
5253
"semver": "^5.5.0",
54+
"shimmer": "^1.2.0",
5355
"uuid": "^3.2.1"
5456
}
5557
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import * as uuidv4 from 'uuid/v4';
1818

1919
import {debug} from '../internal/util';
20-
import {RootSpan} from '../trace/types';
21-
import {OnEndSpanEventListener} from '../trace/types';
20+
import {RootSpan} from '../trace/model/types';
21+
import {OnEndSpanEventListener} from '../trace/model/types';
2222

23-
import {Exporter} from './exporter';
24-
import {ExporterOptions} from './exporterOptions';
23+
import {Exporter} from './types';
24+
import {ExporterOptions} from './types';
2525

2626
// TODO: Implement default size based on application size
2727
const DEFAULT_BUFFER_SIZE = 3;

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

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

17+
import { RootSpan } from '../trace/model/types';
18+
import { Exporter, ExporterOptions } from '../exporters/types';
1719

18-
import {RootSpan} from '../trace/types';
19-
import {OnEndSpanEventListener} from '../trace/types';
20-
import {ExporterOptions} from './exporterOptions';
21-
22-
export interface Exporter { publish(rootSpans: RootSpan[]); }
2320

2421
/** Do not send span data */
2522
export class NoopExporter implements Exporter {
26-
publish(rootSpans: RootSpan[]) {}
23+
publish(rootSpans: RootSpan[]) { }
2724
}
2825

2926
/** Format and sends span data to the console. */

packages/opencensus-core/src/exporters/exporterOptions.ts renamed to packages/opencensus-core/src/exporters/types.ts

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

17+
18+
import {RootSpan} from '../trace/model/types';
19+
20+
export interface Exporter { publish(rootSpans: RootSpan[]); }
21+
1722
/**
1823
* TODO: Interface to exporters options
1924
*/

packages/opencensus-core/src/index.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Copyright 2018 Google Inc. All Rights Reserved.
43
*
@@ -15,15 +14,28 @@
1514
* limitations under the License.
1615
*/
1716

18-
export * from './exporters/buffer';
19-
export * from './exporters/exporter';
20-
export * from './exporters/exporterOptions';
21-
export * from './internal/clock';
22-
export * from './internal/util';
23-
export * from './trace/config/sampler';
17+
18+
// opencensus core api interfaces
19+
export * from './trace/types';
20+
export * from './trace/model/types';
21+
export * from './trace/config/types';
2422
export * from './trace/instrumentation/types';
23+
export * from './exporters/types';
24+
25+
// domain models impls
2526
export * from './trace/model/rootspan';
2627
export * from './trace/model/span';
2728
export * from './trace/model/tracer';
28-
export * from './trace/types';
2929

30+
// sampler impl
31+
export * from './trace/config/sampler';
32+
33+
// base instrumetation class
34+
export * from './trace/instrumentation/baseplugin';
35+
36+
// console exporter and buffer impls
37+
export * from './exporters/buffer';
38+
export * from './exporters/consolelog-exporter';
39+
40+
// util
41+
export * from './internal/util';
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* This interface represent the probability of a tracer.
19+
*/
20+
export interface Sampler {
21+
22+
/**
23+
* Set idUpperBound with MAX_NUMBER that is equivalent the probability be 1
24+
* @returns a Sampler object
25+
*/
26+
27+
always(): Sampler;
28+
/**
29+
* Set idUpperBound with MIN_NUMBER that is equivalent the probability be 0
30+
* @returns a Sampler object
31+
*/
32+
33+
never(): Sampler;
34+
35+
/**
36+
* Set idUpperBound with the probability. If probability
37+
* parameter is bigger then 1 set always. If probability parameter less
38+
* than 0, set never.
39+
* @param probability probability between 0 and 1
40+
* @returns a Sampler object
41+
*/
42+
probability(probability: number): Sampler;
43+
44+
/**
45+
* Checks if trace belong the sample.
46+
* @param traceId Used to check the probability
47+
* @returns a boolean. True if the traceId is in probability
48+
* False if the traceId is not in probability.
49+
*/
50+
shouldSample(traceId: string): boolean;
51+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import * as shimmer from 'shimmer';
17+
import {Tracer} from '../model/types';
18+
19+
/**
20+
* This class represent the base to patch plugin
21+
*/
22+
export abstract class BasePlugin {
23+
exporter: any;
24+
moduleName: string;
25+
tracer: Tracer;
26+
version: string;
27+
28+
constructor(moduleName: string) {
29+
this.moduleName = moduleName;
30+
}
31+
/**
32+
* Set modified plugin to the context.
33+
* @param exporter object module to set on context
34+
* @param tracer tracer relating to context
35+
* @param version module version description
36+
*/
37+
protected setPluginContext(exporter: any, tracer: Tracer, version: string) {
38+
this.exporter = exporter;
39+
this.tracer = tracer;
40+
this.version = version;
41+
}
42+
43+
protected wrap(nodule, name, wrapper ) {
44+
shimmer.wrap(nodule, name, wrapper )
45+
}
46+
47+
protected unwrap(nodule, name) {
48+
shimmer.unwrap(nodule, name);
49+
}
50+
51+
protected massWrap(nodule,names, wrapper) {
52+
shimmer.massWrap(nodule, names, wrapper);
53+
}
54+
55+
protected massUnwrap(nodule,names) {
56+
shimmer.massUnwrap(nodule, names);
57+
}
58+
59+
60+
}

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

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

17+
import {Tracer} from "../model/types";
18+
1719
/**
1820
* Interface Plugin to apply patch.
1921
*/
20-
export interface Plugin<T> {
21-
applyPatch(module: {}, tracer: T, version: string): void;
22+
export interface Plugin {
23+
applyPatch(module: {}, tracer: Tracer, version: string): any;
24+
applyUnpatch(): void;
2225
}
23-
/**
24-
* This class represent the base to patch plugin
25-
*/
26-
export abstract class BasePlugin<T> {
27-
module: {};
28-
moduleName: string;
29-
tracer: T;
30-
version: string;
31-
32-
constructor(moduleName: string) {
33-
this.moduleName = moduleName;
34-
}
35-
/**
36-
* Set modified plugin to the context.
37-
* @param http object module to set on context
38-
* @param tracer tracer relating to context
39-
* @param version module version description
40-
*/
41-
setPluginContext(http: {}, tracer: T, version: string) {
42-
this.module = http;
43-
this.tracer = tracer;
44-
this.version = version;
45-
}
46-
}

0 commit comments

Comments
 (0)