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

Commit ef5712f

Browse files
authored
upgrade gts to 1.0 (#572)
1 parent 075bebd commit ef5712f

File tree

231 files changed

+12285
-10249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+12285
-10249
lines changed

packages/opencensus-core/package-lock.json

Lines changed: 81 additions & 143 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"@types/shimmer": "^1.0.1",
6161
"@types/uuid": "^3.4.3",
6262
"codecov": "^3.4.0",
63-
"gts": "^0.9.0",
63+
"gts": "^1.0.0",
6464
"intercept-stdout": "^0.1.2",
6565
"mocha": "^6.1.0",
6666
"nyc": "14.1.1",

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ export class ConsoleLogger implements types.Logger {
3131
* Constructs a new ConsoleLogger instance
3232
* @param options A logger configuration object.
3333
*/
34-
constructor(options?: types.LoggerOptions|string|number) {
34+
constructor(options?: types.LoggerOptions | string | number) {
3535
let opt: types.LoggerOptions = {};
3636
if (typeof options === 'number') {
3737
if (options < 0) {
3838
options = 0;
3939
} else if (options > ConsoleLogger.LEVELS.length) {
4040
options = ConsoleLogger.LEVELS.length - 1;
4141
}
42-
opt = {level: ConsoleLogger.LEVELS[options]};
42+
opt = { level: ConsoleLogger.LEVELS[options] };
4343
} else if (typeof options === 'string') {
44-
opt = {level: options};
44+
opt = { level: options };
4545
} else {
4646
opt = options || {};
4747
}
4848
if (opt.level) this.level = opt.level;
49-
this.logger =
50-
logDriver({levels: ConsoleLogger.LEVELS, level: opt.level || 'silent'});
49+
this.logger = logDriver({
50+
levels: ConsoleLogger.LEVELS,
51+
level: opt.level || 'silent',
52+
});
5153
}
5254

5355
/**
@@ -96,8 +98,10 @@ export class ConsoleLogger implements types.Logger {
9698
* https://github.com/cainus/logdriver/blob/bba1761737ca72f04d6b445629848538d038484a/index.js#L50
9799
* @param options A logger options or strig to logger in console
98100
*/
99-
const logger = (options?: types.LoggerOptions|string|number): types.Logger => {
101+
const logger = (
102+
options?: types.LoggerOptions | string | number
103+
): types.Logger => {
100104
return new ConsoleLogger(options);
101105
};
102106

103-
export {logger};
107+
export { logger };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Logger} from './types';
17+
import { Logger } from './types';
1818

1919
/** No-op implementation of Logger */
2020
class NoopLogger implements Logger {

packages/opencensus-core/src/common/time-util.ts

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

17-
import {Timestamp} from '../metrics/export/types';
17+
import { Timestamp } from '../metrics/export/types';
1818

1919
const MILLIS_PER_SECOND = 1e3;
2020
const NANOS_PER_MILLI = 1e3 * 1e3;
@@ -54,9 +54,9 @@ export function getTimestampWithProcessHRTime(): Timestamp {
5454
const nanos = hrtimeRefNanos + offsetNanos;
5555

5656
if (nanos >= NANOS_PER_SECOND) {
57-
return {seconds: seconds + 1, nanos: nanos % NANOS_PER_SECOND};
57+
return { seconds: seconds + 1, nanos: nanos % NANOS_PER_SECOND };
5858
}
59-
return {seconds, nanos};
59+
return { seconds, nanos };
6060
}
6161

6262
/**
@@ -68,13 +68,13 @@ export function getTimestampWithProcessHRTime(): Timestamp {
6868
export function timestampFromMillis(epochMilli: number): Timestamp {
6969
return {
7070
seconds: Math.floor(epochMilli / MILLIS_PER_SECOND),
71-
nanos: (epochMilli % MILLIS_PER_SECOND) * NANOS_PER_MILLI
71+
nanos: (epochMilli % MILLIS_PER_SECOND) * NANOS_PER_MILLI,
7272
};
7373
}
7474

7575
setHrtimeReference();
7676

7777
export const TEST_ONLY = {
7878
setHrtimeReference,
79-
resetHrtimeFunctionCache
79+
resetHrtimeFunctionCache,
8080
};

packages/opencensus-core/src/common/validations.ts

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

17-
import {LabelKey, LabelValue} from '../metrics/export/types';
17+
import { LabelKey, LabelValue } from '../metrics/export/types';
1818

1919
/**
2020
* Validates that an object reference passed as a parameter to the calling
@@ -38,17 +38,22 @@ export function validateNotNull<T>(reference: T, errorMessage: string): T {
3838
* @param errorMessage The exception message to use if the check fails.
3939
*/
4040
export function validateArrayElementsNotNull<T>(
41-
array: T[], errorMessage: string) {
41+
array: T[],
42+
errorMessage: string
43+
) {
4244
const areAllDefined = array.every(
43-
element => element !== null && typeof element !== 'undefined');
45+
element => element !== null && typeof element !== 'undefined'
46+
);
4447
if (!areAllDefined) {
4548
throw new Error(`${errorMessage} elements should not be a NULL`);
4649
}
4750
}
4851

4952
/** Throws an error if any of the map elements is null. */
5053
export function validateMapElementNotNull<K, V>(
51-
map: Map<K, V>, errorMessage: string) {
54+
map: Map<K, V>,
55+
errorMessage: string
56+
) {
5257
for (const [key, value] of map.entries()) {
5358
if (key == null || value == null) {
5459
throw new Error(`${errorMessage} elements should not be a NULL`);
@@ -58,11 +63,15 @@ export function validateMapElementNotNull<K, V>(
5863

5964
/** Throws an error if any of the array element present in the map. */
6065
export function validateDuplicateKeys(
61-
keys: LabelKey[], constantLabels: Map<LabelKey, LabelValue>) {
62-
const keysAndConstantKeys =
63-
new Set([...keys, ...constantLabels.keys()].map(k => k.key));
64-
if (keysAndConstantKeys.size !== (keys.length + constantLabels.size)) {
66+
keys: LabelKey[],
67+
constantLabels: Map<LabelKey, LabelValue>
68+
) {
69+
const keysAndConstantKeys = new Set(
70+
[...keys, ...constantLabels.keys()].map(k => k.key)
71+
);
72+
if (keysAndConstantKeys.size !== keys.length + constantLabels.size) {
6573
throw new Error(
66-
`The keys from LabelKeys should not be present in constantLabels or LabelKeys should not contains duplicate keys`);
74+
`The keys from LabelKeys should not be present in constantLabels or LabelKeys should not contains duplicate keys`
75+
);
6776
}
6877
}

packages/opencensus-core/src/common/version.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* Copyright 2018, OpenCensus Authors
43
*
@@ -15,9 +14,9 @@
1514
* limitations under the License.
1615
*/
1716

18-
type Package = {
17+
interface Package {
1918
version: string;
20-
};
19+
}
2120

2221
// Load the package details. Note that the `require` is performed at runtime,
2322
// which means package.json will be relative to the location of this file.

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
*/
1616

1717
import * as loggerTypes from '../common/types';
18-
import {Measurement, View} from '../stats/types';
19-
import {TagKey, TagValue} from '../tags/types';
18+
import { Measurement, View } from '../stats/types';
19+
import { TagKey, TagValue } from '../tags/types';
2020
import * as modelTypes from '../trace/model/types';
21-
import {ExporterBuffer} from './exporter-buffer';
22-
import {Exporter, ExporterConfig, StatsEventListener} from './types';
21+
import { ExporterBuffer } from './exporter-buffer';
22+
import * as logger from '../common/console-logger';
23+
import { Exporter, ExporterConfig, StatsEventListener } from './types';
2324

2425
/** Do not send span data */
2526
export class NoopExporter implements Exporter {
@@ -34,8 +35,7 @@ export class NoopExporter implements Exporter {
3435
/** Format and sends span data to the console. */
3536
export class ConsoleExporter implements Exporter {
3637
/** Buffer object to store the spans. */
37-
// @ts-ignore
38-
private logger?: loggerTypes.Logger;
38+
logger: loggerTypes.Logger;
3939
private buffer: ExporterBuffer;
4040

4141
/**
@@ -45,7 +45,7 @@ export class ConsoleExporter implements Exporter {
4545
*/
4646
constructor(config: ExporterConfig) {
4747
this.buffer = new ExporterBuffer(this, config);
48-
this.logger = config.logger;
48+
this.logger = config.logger || logger.logger();
4949
}
5050

5151
onStartSpan(span: modelTypes.Span) {}
@@ -66,17 +66,16 @@ export class ConsoleExporter implements Exporter {
6666
* @param spans A list of spans to publish.
6767
*/
6868
publish(spans: modelTypes.Span[]) {
69-
spans.map((span) => {
69+
spans.map(span => {
7070
const ROOT_STR = `RootSpan: {traceId: ${span.traceId}, spanId: ${
71-
span.id}, name: ${span.name} }`;
72-
const SPANS_STR: string[] = span.spans.map(
73-
(child) => [`\t\t{spanId: ${child.id}, name: ${child.name}}`].join(
74-
'\n'));
71+
span.id
72+
}, name: ${span.name} }`;
73+
const SPANS_STR: string[] = span.spans.map(child =>
74+
[`\t\t{spanId: ${child.id}, name: ${child.name}}`].join('\n')
75+
);
7576

7677
const result: string[] = [];
77-
result.push(
78-
ROOT_STR + '\n\tChildSpans:\n' +
79-
`${SPANS_STR.join('\n')}`);
78+
result.push(ROOT_STR + '\n\tChildSpans:\n' + `${SPANS_STR.join('\n')}`);
8079
console.log(`${result}`);
8180
});
8281
return Promise.resolve();
@@ -90,8 +89,9 @@ export class ConsoleStatsExporter implements StatsEventListener {
9089
* @param view registered view
9190
*/
9291
onRegisterView(view: View) {
93-
console.log(`View registered: ${view.name}, Measure registered: ${
94-
view.measure.name}`);
92+
console.log(
93+
`View registered: ${view.name}, Measure registered: ${view.measure.name}`
94+
);
9595
}
9696
/**
9797
* Event called when a measurement is recorded
@@ -100,7 +100,10 @@ export class ConsoleStatsExporter implements StatsEventListener {
100100
* @param tags The tags to which the value is applied
101101
*/
102102
onRecord(
103-
views: View[], measurement: Measurement, tags: Map<TagKey, TagValue>) {
103+
views: View[],
104+
measurement: Measurement,
105+
tags: Map<TagKey, TagValue>
106+
) {
104107
console.log(`Measurement recorded: ${measurement.measure.name}`);
105108
}
106109

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ export class ExporterBuffer {
4848
constructor(exporter: types.Exporter, config: configTypes.BufferConfig) {
4949
this.exporter = exporter;
5050
this.logger = config.logger || logger.logger();
51-
this.bufferSize = isNaN(Number(config.bufferSize)) ?
52-
DEFAULT_BUFFER_SIZE :
53-
Number(config.bufferSize);
54-
this.bufferTimeout = isNaN(Number(config.bufferTimeout)) ?
55-
DEFAULT_BUFFER_TIMEOUT :
56-
Number(config.bufferTimeout);
51+
this.bufferSize = isNaN(Number(config.bufferSize))
52+
? DEFAULT_BUFFER_SIZE
53+
: Number(config.bufferSize);
54+
this.bufferTimeout = isNaN(Number(config.bufferTimeout))
55+
? DEFAULT_BUFFER_TIMEOUT
56+
: Number(config.bufferTimeout);
5757
return this;
5858
}
5959

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

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

17-
import {Measurement, View} from '../stats/types';
18-
import {TagKey, TagValue} from '../tags/types';
17+
import { Measurement, View } from '../stats/types';
18+
import { TagKey, TagValue } from '../tags/types';
1919
import * as configTypes from '../trace/config/types';
2020
import * as modelTypes from '../trace/model/types';
2121

@@ -25,7 +25,7 @@ export interface Exporter extends modelTypes.SpanEventListener {
2525
* Sends a list of spans to the service.
2626
* @param spans A list of spans to publish.
2727
*/
28-
publish(spans: modelTypes.Span[]): Promise<number|string|void>;
28+
publish(spans: modelTypes.Span[]): Promise<number | string | void>;
2929
}
3030

3131
/**
@@ -48,8 +48,10 @@ export interface StatsEventListener {
4848
* @param tags The tags to which the value is applied
4949
*/
5050
onRecord(
51-
views: View[], measurement: Measurement,
52-
tags: Map<TagKey, TagValue>): void;
51+
views: View[],
52+
measurement: Measurement,
53+
tags: Map<TagKey, TagValue>
54+
): void;
5355

5456
/**
5557
* Starts the exporter that polls Metric from Metrics library and send

0 commit comments

Comments
 (0)