@microsoft/metrics-ts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.eslintrc.js +3 -0
  2. package/.prettierrc.js +3 -0
  3. package/LICENSE +23 -0
  4. package/build/capability/index.d.ts +2 -0
  5. package/build/capability/index.d.ts.map +1 -0
  6. package/build/capability/index.js +6 -0
  7. package/build/capability/index.js.map +1 -0
  8. package/build/capability/timer.d.ts +2 -0
  9. package/build/capability/timer.d.ts.map +1 -0
  10. package/build/capability/timer.js +88 -0
  11. package/build/capability/timer.js.map +1 -0
  12. package/build/index.d.ts +4 -0
  13. package/build/index.d.ts.map +1 -0
  14. package/build/index.js +7 -0
  15. package/build/index.js.map +1 -0
  16. package/build/rawData.d.ts +19 -0
  17. package/build/rawData.d.ts.map +1 -0
  18. package/build/rawData.js +10 -0
  19. package/build/rawData.js.map +1 -0
  20. package/build/reporter/index.d.ts +1 -0
  21. package/build/reporter/index.d.ts.map +1 -0
  22. package/build/reporter/index.js +2 -0
  23. package/build/reporter/index.js.map +1 -0
  24. package/build/reporter/json.d.ts +1 -0
  25. package/build/reporter/json.d.ts.map +1 -0
  26. package/build/reporter/json.js +2 -0
  27. package/build/reporter/json.js.map +1 -0
  28. package/build/tracing.d.ts +5 -0
  29. package/build/tracing.d.ts.map +1 -0
  30. package/build/tracing.js +20 -0
  31. package/build/tracing.js.map +1 -0
  32. package/build/transformer.d.ts +16 -0
  33. package/build/transformer.d.ts.map +1 -0
  34. package/build/transformer.js +77 -0
  35. package/build/transformer.js.map +1 -0
  36. package/build/writer.d.ts +4 -0
  37. package/build/writer.d.ts.map +1 -0
  38. package/build/writer.js +24 -0
  39. package/build/writer.js.map +1 -0
  40. package/package.json +63 -0
  41. package/sample/package.json +17 -0
  42. package/sample/src/index.ts +31 -0
  43. package/sample/tsconfig.json +26 -0
  44. package/src/capability/index.ts +1 -0
  45. package/src/capability/timer.ts +88 -0
  46. package/src/index.ts +5 -0
  47. package/src/rawData.ts +23 -0
  48. package/src/reporter/index.ts +0 -0
  49. package/src/reporter/json.ts +0 -0
  50. package/src/tracing.ts +15 -0
  51. package/src/transformer.ts +109 -0
  52. package/src/writer.ts +22 -0
  53. package/tsconfig.json +25 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ["../eslint-config"],
3
+ };
package/.prettierrc.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require("../prettier-config"),
3
+ };
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Microsoft Teams Framework (TeamsFx)
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export { MSTimer } from "./timer";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/capability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MSTimer = void 0;
4
+ var timer_1 = require("./timer");
5
+ Object.defineProperty(exports, "MSTimer", { enumerable: true, get: function () { return timer_1.MSTimer; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capability/index.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAAzB,gGAAA,OAAO,OAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const MSTimer: (fn: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../src/capability/timer.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,OAAO,OAAQ,MAAM,cAGhB,GAAG,eAAe,MAAM,cAAc,kBAAkB,uBAqEzE,CAAC"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MSTimer = void 0;
4
+ /**
5
+ * Timer - measures call-rate of a function and the distribution of the duration of all calls
6
+ */
7
+ const perf_hooks_1 = require("perf_hooks");
8
+ const rawData_1 = require("../rawData");
9
+ const tracing_1 = require("../tracing");
10
+ const writer_1 = require("../writer");
11
+ /**
12
+ * TODO: allow cutomization
13
+ * all in millsecond
14
+ */
15
+ const fast = 1;
16
+ const normal = 20;
17
+ const MSTimer = (fn) => {
18
+ /* eslint-disable @typescript-eslint/no-explicit-any */
19
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
20
+ return (target, propertyKey, descriptor) => {
21
+ const originalMethod = descriptor.value;
22
+ /**
23
+ * get essential properties
24
+ */
25
+ const data = {
26
+ traceId: (0, tracing_1.traceId)(),
27
+ file: fn,
28
+ class: target.constructor.name,
29
+ method: originalMethod.name,
30
+ timestamp: Date.now(),
31
+ };
32
+ if (originalMethod.constructor.name === "AsyncFunction") {
33
+ descriptor.value = async function (...args) {
34
+ data.args = args;
35
+ const start = perf_hooks_1.performance.now();
36
+ const result = await originalMethod.apply(this, args);
37
+ const end = perf_hooks_1.performance.now();
38
+ const duration = end - start;
39
+ let severity;
40
+ if (duration > normal) {
41
+ severity = rawData_1.TimerSeverity.Slow;
42
+ }
43
+ else if (duration > fast) {
44
+ severity = rawData_1.TimerSeverity.Normal;
45
+ }
46
+ else {
47
+ severity = rawData_1.TimerSeverity.Fast;
48
+ }
49
+ const timerData = {
50
+ duration: duration,
51
+ severity: severity,
52
+ };
53
+ data.timer = timerData;
54
+ await (0, writer_1.appendOutput)(data);
55
+ return result;
56
+ };
57
+ }
58
+ else {
59
+ descriptor.value = function (...args) {
60
+ data.args = args;
61
+ const start = perf_hooks_1.performance.now();
62
+ const result = originalMethod.apply(this, args);
63
+ const end = perf_hooks_1.performance.now();
64
+ const duration = end - start;
65
+ let severity;
66
+ if (duration > normal) {
67
+ severity = rawData_1.TimerSeverity.Slow;
68
+ }
69
+ else if (duration > fast) {
70
+ severity = rawData_1.TimerSeverity.Normal;
71
+ }
72
+ else {
73
+ severity = rawData_1.TimerSeverity.Fast;
74
+ }
75
+ const timerData = {
76
+ duration: duration,
77
+ severity: severity,
78
+ };
79
+ data.timer = timerData;
80
+ (0, writer_1.appendOutputSync)(data);
81
+ return result;
82
+ };
83
+ }
84
+ return descriptor;
85
+ };
86
+ };
87
+ exports.MSTimer = MSTimer;
88
+ //# sourceMappingURL=timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/capability/timer.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2CAAyC;AACzC,wCAAkE;AAClE,wCAAqC;AACrC,sCAA2D;AAE3D;;;GAGG;AACH,M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B,QAAQ,EAAE,QAAQ;iBACnB,CAAC;gBAEF,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;gBAEvB,MAAM,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;gBACzB,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;SACH;aAAM;YACL,UAAU,CAAC,KAAK,GAAG,UAAU,GAAG,IAAW;gBACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBAEjB,MAAM,KAAK,GAAG,wBAAW,CAAC,GAAG,EAAE,CAAC;gBAChC,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAChD,MAAM,GAAG,GAAG,wBAAW,CAAC,GAAG,EAAE,CAAC;gBAC9B,MAAM,QAAQ,GAAG,GAAG,GAAG,KAAK,CAAC;gBAC7B,IAAI,QAAuB,CAAC;gBAC5B,IAAI,QAAQ,GAAG,MAAM,EAAE;oBACrB,QAAQ,GAAG,uBAAa,CAAC,IAAI,CAAC;iBAC/B;qBAAM,IAAI,QAAQ,GAAG,IAAI,EAAE;oBAC1B,QAAQ,GAAG,uBAAa,CAAC,MAAM,CAAC;iBACjC;qBAAM;oBACL,QAAQ,GAAG,uBAAa,CAAC,IAAI,CAAC;iBAC/B;gBACD,MAAM,SAAS,GAAc;oBAC3B,QAAQ,EAAE,QAAQ;oBAClB,QAAQ,EAAE,QAAQ;iBACnB,CAAC;gBAEF,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;gBAEvB,IAAA,yBAAgB,EAAC,IAAI,CAAC,CAAC;gBACvB,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;SACH;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC,CAAC;AAxEW,QAAA,OAAO,WAwElB"}
@@ -0,0 +1,4 @@
1
+ import { default as transformer } from "./transformer";
2
+ export * from "./capability";
3
+ export default transformer;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AAEvD,cAAc,cAAc,CAAC;AAE7B,eAAe,WAAW,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const transformer_1 = tslib_1.__importDefault(require("./transformer"));
5
+ tslib_1.__exportStar(require("./capability"), exports);
6
+ exports.default = transformer_1.default;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAAuD;AAEvD,uDAA6B;AAE7B,kBAAe,qBAAW,CAAC"}
@@ -0,0 +1,19 @@
1
+ export interface tracePoint {
2
+ traceId: string;
3
+ file: string;
4
+ class: string;
5
+ timestamp: number;
6
+ method: string;
7
+ args?: any;
8
+ timer?: timerData;
9
+ }
10
+ export declare enum TimerSeverity {
11
+ Fast = "fast",
12
+ Normal = "normal",
13
+ Slow = "slow"
14
+ }
15
+ export interface timerData {
16
+ duration: number;
17
+ severity: TimerSeverity;
18
+ }
19
+ //# sourceMappingURL=rawData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawData.d.ts","sourceRoot":"","sources":["../src/rawData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;CACzB"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimerSeverity = void 0;
4
+ var TimerSeverity;
5
+ (function (TimerSeverity) {
6
+ TimerSeverity["Fast"] = "fast";
7
+ TimerSeverity["Normal"] = "normal";
8
+ TimerSeverity["Slow"] = "slow";
9
+ })(TimerSeverity = exports.TimerSeverity || (exports.TimerSeverity = {}));
10
+ //# sourceMappingURL=rawData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawData.js","sourceRoot":"","sources":["../src/rawData.ts"],"names":[],"mappings":";;;AAaA,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,8BAAa,CAAA;AACf,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reporter/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporter/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/reporter/json.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/reporter/json.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * TODO: make it safe
3
+ */
4
+ export declare function traceId(): string;
5
+ //# sourceMappingURL=tracing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,OAAO,IAAI,MAAM,CAQhC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traceId = void 0;
4
+ const process_1 = require("process");
5
+ const uuid_1 = require("uuid");
6
+ /**
7
+ * TODO: make it safe
8
+ */
9
+ function traceId() {
10
+ if (process_1.env.METAOS_TRACE_ID) {
11
+ return process_1.env.METAOS_TRACE_ID;
12
+ }
13
+ else {
14
+ const traceId = (0, uuid_1.v4)();
15
+ process_1.env.METAOS_TRACE_ID = traceId;
16
+ return traceId;
17
+ }
18
+ }
19
+ exports.traceId = traceId;
20
+ //# sourceMappingURL=tracing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":";;;AAAA,qCAA8B;AAC9B,+BAAoC;AAEpC;;GAEG;AACH,SAAgB,OAAO;IACrB,IAAI,aAAG,CAAC,eAAe,EAAE;QACvB,OAAO,aAAG,CAAC,eAAe,CAAC;KAC5B;SAAM;QACL,MAAM,OAAO,GAAG,IAAA,SAAM,GAAE,CAAC;QACzB,aAAG,CAAC,eAAe,GAAG,OAAO,CAAC;QAC9B,OAAO,OAAO,CAAC;KAChB;AACH,CAAC;AARD,0BAQC"}
@@ -0,0 +1,16 @@
1
+ import typescript from "typescript";
2
+ /**
3
+ * unused right now.
4
+ */
5
+ export declare enum Reporter {
6
+ Json = "json"
7
+ }
8
+ export declare enum Capability {
9
+ Timer = "timer"
10
+ }
11
+ export interface PluginConfig {
12
+ capabilities?: Capability[];
13
+ reporters?: Reporter[];
14
+ }
15
+ export default function (program: typescript.Program, config?: PluginConfig): (ctx: typescript.TransformationContext) => (sourceFile: typescript.SourceFile) => typescript.SourceFile;
16
+ //# sourceMappingURL=transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC;;GAEG;AACH,oBAAY,QAAQ;IAClB,IAAI,SAAS;CACd;AAED,oBAAY,UAAU;IACpB,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;IAC5B,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;CACxB;AAED,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,YAAY,SAC5D,WAAW,qBAAqB,kBACvB,WAAW,UAAU,2BAwF5C"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Capability = exports.Reporter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const typescript_1 = tslib_1.__importDefault(require("typescript"));
6
+ /**
7
+ * unused right now.
8
+ */
9
+ var Reporter;
10
+ (function (Reporter) {
11
+ Reporter["Json"] = "json";
12
+ })(Reporter = exports.Reporter || (exports.Reporter = {}));
13
+ var Capability;
14
+ (function (Capability) {
15
+ Capability["Timer"] = "timer";
16
+ })(Capability = exports.Capability || (exports.Capability = {}));
17
+ function default_1(program, config) {
18
+ return (ctx) => {
19
+ return (sourceFile) => {
20
+ let capabilities = [Capability.Timer];
21
+ if (config && config.capabilities) {
22
+ capabilities = config.capabilities;
23
+ }
24
+ const myLib = "@microsoft/metrics-ts";
25
+ const myNamespace = "metrics_9527";
26
+ /**
27
+ * find source file node and add "import" statements
28
+ * TODO: check imports,
29
+ * @see {@link https://stackoverflow.com/questions/67723545/how-to-update-or-insert-to-import-using-typescript-compiler-api}
30
+ * TODO: can't trans to commonjs is there's no import statement of source file.
31
+ * TODO: make import name unique
32
+ */
33
+ function sourfileVisitor(node) {
34
+ if (typescript_1.default.isSourceFile(node)) {
35
+ return ctx.factory.updateSourceFile(node, [
36
+ ctx.factory.createImportDeclaration(undefined /** decorators */, undefined /** modifiers */, ctx.factory.createImportClause(false, undefined /** name */, ctx.factory.createNamespaceImport(ctx.factory.createIdentifier(myNamespace))), ctx.factory.createStringLiteral(myLib)),
37
+ ...sourceFile.statements,
38
+ ]);
39
+ }
40
+ return typescript_1.default.visitEachChild(node, sourfileVisitor, ctx);
41
+ }
42
+ /**
43
+ * find all methods and add metrics decorators for them
44
+ */
45
+ function methodVisitor(node) {
46
+ if (typescript_1.default.isMethodDeclaration(node)) {
47
+ /**
48
+ * create metric decorator for function declaration
49
+ */
50
+ const metricsDecorators = [];
51
+ for (const cap of capabilities) {
52
+ metricsDecorators.push(ctx.factory.createDecorator(ctx.factory.createCallExpression(ctx.factory.createIdentifier(`${myNamespace}.${cap}`), undefined, [])));
53
+ }
54
+ /**
55
+ * aggragate existing decorators with new decorators
56
+ */
57
+ let decorators;
58
+ if (node.decorators) {
59
+ decorators = [...node.decorators, ...metricsDecorators];
60
+ }
61
+ else {
62
+ decorators = metricsDecorators;
63
+ }
64
+ /**
65
+ * just update decorators, keep everything else.
66
+ */
67
+ return ctx.factory.updateMethodDeclaration(node, decorators, node.modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body);
68
+ }
69
+ return typescript_1.default.visitEachChild(node, methodVisitor, ctx);
70
+ }
71
+ sourceFile = typescript_1.default.visitNode(sourceFile, sourfileVisitor);
72
+ return typescript_1.default.visitNode(sourceFile, methodVisitor);
73
+ };
74
+ };
75
+ }
76
+ exports.default = default_1;
77
+ //# sourceMappingURL=transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":";;;;AAAA,oEAAoC;AAEpC;;GAEG;AACH,IAAY,QAEX;AAFD,WAAY,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oint } from "./rawData";
2
+ export declare function appendOutput(data: tracePoint): Promise<void>;
3
+ export declare function appendOutputSync(data: tracePoint): void;
4
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAQvC,wBAAsB,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAKlE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAKvD"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appendOutputSync = exports.appendOutput = void 0;
4
+ const path_1 = require("path");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const os_1 = require("os");
7
+ const fs_1 = require("fs");
8
+ const metricsFolder = (0, path_1.join)((0, os_1.tmpdir)(), ".metrics");
9
+ const metricsFile = (0, path_1.join)(metricsFolder, "output.txt");
10
+ async function appendOutput(data) {
11
+ await (0, fs_extra_1.ensureDir)(metricsFolder);
12
+ await (0, fs_extra_1.ensureFile)(metricsFile);
13
+ await (0, fs_extra_1.appendFile)(metricsFile, JSON.stringify(data) + os_1.EOL);
14
+ return;
15
+ }
16
+ exports.appendOutput = appendOutput;
17
+ function appendOutputSync(data) {
18
+ (0, fs_extra_1.ensureDirSync)(metricsFolder);
19
+ (0, fs_extra_1.ensureFileSync)(metricsFile);
20
+ (0, fs_1.appendFileSync)(metricsFile, JSON.stringify(data) + os_1.EOL);
21
+ return;
22
+ }
23
+ exports.appendOutputSync = appendOutputSync;
24
+ //# sourceMappingURL=writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.js","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAE5B,uCAA4F;AAC5F,2BAAiC;AACjC,2BAAoC;AAEpC,MAAM,aAAa,GAAG,IAAA,WAAI,EAAC,IAAA,WAAM,GAAE,EAAE,UAAU,CAAC,CAAC;AACjD,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,aAAa,EAAE,YAAY,CAAC,CAAC;AAE/C,KAAK,UAAU,YAAY,CAAC,IAAgB;IACjD,MAAM,IAAA,oBAAS,EAAC,aAAa,CAAC,CAAC;IAC/B,MAAM,IAAA,qBAAU,EAAC,WAAW,CAAC,CAAC;IAC9B,MAAM,IAAA,qBAAU,EAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,QAAG,CAAC,CAAC;IAC1D,OAAO;AACT,CAAC;AALD,oCAKC;AAED,SAAgB,gBAAgB,CAAC,IAAgB;IAC/C,IAAA,wBAAa,EAAC,aAAa,CAAC,CAAC;IAC7B,IAAA,yBAAc,EAAC,WAAW,CAAC,CAAC;IAC5B,IAAA,mBAAc,EAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,QAAG,CAAC,CAAC;IACxD,OAAO;AACT,CAAC;AALD,4CAKC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@microsoft/metrics-ts",
3
+ "version": "0.0.1",
4
+ "description": "Add metrics without intruding source code",
5
+ "keywords": [
6
+ "Metrics"
7
+ ],
8
+ "author": "Long Hao<haolong@microsoft.com>",
9
+ "homepage": "https://github.com/OfficeDev/TeamsFx#readme",
10
+ "license": "MIT",
11
+ "main": "build/index.js",
12
+ "types": "build/index.d.ts",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/OfficeDev/TeamsFx.git"
16
+ },
17
+ "scripts": {
18
+ "build": "rimraf build && npx tsc -p ./",
19
+ "format-check": "echo test",
20
+ "check-sensitive": "npx eslint --plugin 'no-secrets' --cache --ignore-pattern 'package.json' --ignore-pattern 'package-lock.json'",
21
+ "precommit": "npm run check-sensitive && lint-staged",
22
+ "lint": "eslint \"**/*.ts\"",
23
+ "lint:staged": "lint-staged"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/OfficeDev/TeamsFx/issues"
27
+ },
28
+ "devDependencies": {
29
+ "@istanbuljs/nyc-config-typescript": "^1.0.1",
30
+ "@types/chai": "^4.2.21",
31
+ "@types/mocha": "^8.2.3",
32
+ "@types/node": "^16.0.0",
33
+ "@types/uuid": "^8.3.4",
34
+ "@typescript-eslint/eslint-plugin": "^4.19.0",
35
+ "@typescript-eslint/parser": "^4.19.0",
36
+ "chai": "^4.3.4",
37
+ "eslint": "^7.22.0",
38
+ "eslint-plugin-import": "^2.25.2",
39
+ "eslint-plugin-no-secrets": "^0.8.9",
40
+ "eslint-plugin-prettier": "^4.0.0",
41
+ "lint-staged": "^10.5.4",
42
+ "mocha": "^9.2.1",
43
+ "nyc": "^15.1.0",
44
+ "prettier": "^2.4.1",
45
+ "ts-node": "^10.1.0",
46
+ "tslint": "^6.1.3",
47
+ "tslint-config-prettier": "^1.18.0",
48
+ "ttypescript": "^1.5.13",
49
+ "typescript": "^4.3.5"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "lint-staged": {
55
+ "*.{js,jsx,css,ts,tsx}": [
56
+ "npx eslint --cache --fix --quiet"
57
+ ]
58
+ },
59
+ "dependencies": {
60
+ "uuid": "^8.3.2"
61
+ },
62
+ "gitHead": "e30209b171c59985670db2c18425689c7c21b58a"
63
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "transformer-sample",
3
+ "version": "0.0.1",
4
+ "main": "build/index.js",
5
+ "types": "build/index.d.ts",
6
+ "license": "MIT",
7
+ "scripts": {
8
+ "build": "npx ttsc -p ."
9
+ },
10
+ "devDependencies": {
11
+ "@microsoft/metrics-ts": "file:../",
12
+ "ts-node": "^10.8.1",
13
+ "@types/node": "^16.0.0",
14
+ "ttypescript": "^1.5.13",
15
+ "typescript": "^4.3.5"
16
+ }
17
+ }
@@ -0,0 +1,31 @@
1
+ import * as path123 from "path";
2
+ import { timer } from "@microsoft/metrics-ts";
3
+
4
+ function delay(ms: number) {
5
+ return new Promise((resolve) => setTimeout(resolve, ms));
6
+ }
7
+
8
+ class Foo {
9
+ @timer()
10
+ bar() {
11
+ const r = this.baz();
12
+ console.log(r);
13
+ console.log(r.indexOf(0));
14
+ }
15
+
16
+ @timer()
17
+ baz(): number[] {
18
+ path123.join("a", "b");
19
+ return [1];
20
+ }
21
+
22
+ @timer()
23
+ async buz(arg: string, arg2: any) {
24
+ await delay(1000);
25
+ this.bar();
26
+ }
27
+ }
28
+
29
+ process.env.METAOS_TRACE_ID = "123";
30
+ const f = new Foo();
31
+ f.buz("Hello World!", { a: 1 }).then();
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "experimentalDecorators": true,
4
+ "emitDecoratorMetadata": true,
5
+ "module": "CommonJS",
6
+ "target": "es2017",
7
+ "outDir": "build",
8
+ "lib": ["es6", "dom.iterable", "dom"],
9
+ "allowJs": true,
10
+ "importHelpers": true,
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "sourceMap": true,
15
+ "declarationMap": true,
16
+ "strict": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "moduleResolution": "node",
19
+ "resolveJsonModule": true,
20
+ "jsx": "react",
21
+ "declaration": true,
22
+ "plugins": [{ "transform": "@microsoft/metrics-ts", "capabilities": ["timer"]}]
23
+ },
24
+ "include": ["src"],
25
+ "exclude": ["node_modules", "**/tests/*"]
26
+ }
@@ -0,0 +1 @@
1
+ export { MSTimer } from "./timer";
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Timer - measures call-rate of a function and the distribution of the duration of all calls
3
+ */
4
+ import { performance } from "perf_hooks";
5
+ import { timerData, TimerSeverity, tracePoint } from "../rawData";
6
+ import { traceId } from "../tracing";
7
+ import { appendOutput, appendOutputSync } from "../writer";
8
+
9
+ /**
10
+ * TODO: allow cutomization
11
+ * all in millsecond
12
+ */
13
+ const fast = 1;
14
+ const normal = 20;
15
+
16
+ export const MSTimer = (fn: string) => {
17
+ /* eslint-disable @typescript-eslint/no-explicit-any */
18
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
19
+ return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
20
+ const originalMethod = descriptor.value;
21
+
22
+ /**
23
+ * get essential properties
24
+ */
25
+ const data: tracePoint = {
26
+ traceId: traceId(),
27
+ file: fn,
28
+ class: target.constructor.name,
29
+ method: originalMethod.name,
30
+ timestamp: Date.now(),
31
+ };
32
+
33
+ if (originalMethod.constructor.name === "AsyncFunction") {
34
+ descriptor.value = async function (...args: any[]) {
35
+ data.args = args;
36
+
37
+ const start = performance.now();
38
+ const result = await originalMethod.apply(this, args);
39
+ const end = performance.now();
40
+ const duration = end - start;
41
+ let severity: TimerSeverity;
42
+ if (duration > normal) {
43
+ severity = TimerSeverity.Slow;
44
+ } else if (duration > fast) {
45
+ severity = TimerSeverity.Normal;
46
+ } else {
47
+ severity = TimerSeverity.Fast;
48
+ }
49
+ const timerData: timerData = {
50
+ duration: duration,
51
+ severity: severity,
52
+ };
53
+
54
+ data.timer = timerData;
55
+
56
+ await appendOutput(data);
57
+ return result;
58
+ };
59
+ } else {
60
+ descriptor.value = function (...args: any[]) {
61
+ data.args = args;
62
+
63
+ const start = performance.now();
64
+ const result = originalMethod.apply(this, args);
65
+ const end = performance.now();
66
+ const duration = end - start;
67
+ let severity: TimerSeverity;
68
+ if (duration > normal) {
69
+ severity = TimerSeverity.Slow;
70
+ } else if (duration > fast) {
71
+ severity = TimerSeverity.Normal;
72
+ } else {
73
+ severity = TimerSeverity.Fast;
74
+ }
75
+ const timerData: timerData = {
76
+ duration: duration,
77
+ severity: severity,
78
+ };
79
+
80
+ data.timer = timerData;
81
+
82
+ appendOutputSync(data);
83
+ return result;
84
+ };
85
+ }
86
+ return descriptor;
87
+ };
88
+ };
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { default as transformer } from "./transformer";
2
+
3
+ export * from "./capability";
4
+
5
+ export default transformer;
package/src/rawData.ts ADDED
@@ -0,0 +1,23 @@
1
+ export interface tracePoint {
2
+ traceId: string;
3
+ //pspanId: number;
4
+ //spanId: number;
5
+ file: string;
6
+ class: string;
7
+ timestamp: number;
8
+ method: string;
9
+ /* eslint-disable @typescript-eslint/no-explicit-any */
10
+ args?: any;
11
+ timer?: timerData;
12
+ }
13
+
14
+ export enum TimerSeverity {
15
+ Fast = "fast",
16
+ Normal = "normal",
17
+ Slow = "slow",
18
+ }
19
+
20
+ export interface timerData {
21
+ duration: number;
22
+ severity: TimerSeverity;
23
+ }
File without changes
File without changes
package/src/tracing.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { env } from "process";
2
+ import { v4 as uuidv4 } from "uuid";
3
+
4
+ /**
5
+ * TODO: make it safe
6
+ */
7
+ export function traceId(): string {
8
+ if (env.METAOS_TRACE_ID) {
9
+ return env.METAOS_TRACE_ID;
10
+ } else {
11
+ const traceId = uuidv4();
12
+ env.METAOS_TRACE_ID = traceId;
13
+ return traceId;
14
+ }
15
+ }
@@ -0,0 +1,109 @@
1
+ import typescript from "typescript";
2
+
3
+ /**
4
+ * unused right now.
5
+ */
6
+ export enum Reporter {
7
+ Json = "json",
8
+ }
9
+
10
+ export enum Capability {
11
+ Timer = "timer",
12
+ }
13
+
14
+ export interface PluginConfig {
15
+ capabilities?: Capability[];
16
+ reporters?: Reporter[];
17
+ }
18
+
19
+ export default function (program: typescript.Program, config?: PluginConfig) {
20
+ return (ctx: typescript.TransformationContext) => {
21
+ return (sourceFile: typescript.SourceFile) => {
22
+ let capabilities = [Capability.Timer];
23
+ if (config && config.capabilities) {
24
+ capabilities = config.capabilities;
25
+ }
26
+
27
+ const myLib = "@microsoft/metrics-ts";
28
+ const myNamespace = "metrics_9527";
29
+ /**
30
+ * find source file node and add "import" statements
31
+ * TODO: check imports,
32
+ * @see {@link https://stackoverflow.com/questions/67723545/how-to-update-or-insert-to-import-using-typescript-compiler-api}
33
+ * TODO: can't trans to commonjs is there's no import statement of source file.
34
+ * TODO: make import name unique
35
+ */
36
+ function sourfileVisitor(node: typescript.Node): typescript.Node {
37
+ if (typescript.isSourceFile(node)) {
38
+ return ctx.factory.updateSourceFile(node as typescript.SourceFile, [
39
+ ctx.factory.createImportDeclaration(
40
+ undefined /** decorators */,
41
+ undefined /** modifiers */,
42
+ ctx.factory.createImportClause(
43
+ false,
44
+ undefined /** name */,
45
+ ctx.factory.createNamespaceImport(ctx.factory.createIdentifier(myNamespace))
46
+ ),
47
+ ctx.factory.createStringLiteral(myLib)
48
+ ),
49
+ ...sourceFile.statements,
50
+ ]);
51
+ }
52
+ return typescript.visitEachChild(node, sourfileVisitor, ctx);
53
+ }
54
+
55
+ /**
56
+ * find all methods and add metrics decorators for them
57
+ */
58
+ function methodVisitor(node: typescript.Node): typescript.Node {
59
+ if (typescript.isMethodDeclaration(node)) {
60
+ /**
61
+ * create metric decorator for function declaration
62
+ */
63
+ const metricsDecorators = [];
64
+ for (const cap of capabilities) {
65
+ metricsDecorators.push(
66
+ ctx.factory.createDecorator(
67
+ ctx.factory.createCallExpression(
68
+ ctx.factory.createIdentifier(`${myNamespace}.${cap}`),
69
+ undefined,
70
+ []
71
+ )
72
+ )
73
+ );
74
+ }
75
+
76
+ /**
77
+ * aggragate existing decorators with new decorators
78
+ */
79
+ let decorators: typescript.Decorator[];
80
+ if (node.decorators) {
81
+ decorators = [...node.decorators, ...metricsDecorators];
82
+ } else {
83
+ decorators = metricsDecorators;
84
+ }
85
+
86
+ /**
87
+ * just update decorators, keep everything else.
88
+ */
89
+ return ctx.factory.updateMethodDeclaration(
90
+ node,
91
+ decorators,
92
+ node.modifiers,
93
+ node.asteriskToken,
94
+ node.name,
95
+ node.questionToken,
96
+ node.typeParameters,
97
+ node.parameters,
98
+ node.type,
99
+ node.body
100
+ );
101
+ }
102
+ return typescript.visitEachChild(node, methodVisitor, ctx);
103
+ }
104
+
105
+ sourceFile = typescript.visitNode(sourceFile, sourfileVisitor);
106
+ return typescript.visitNode(sourceFile, methodVisitor);
107
+ };
108
+ };
109
+ }
package/src/writer.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { join } from "path";
2
+ import { tracePoint } from "./rawData";
3
+ import { appendFile, ensureDir, ensureDirSync, ensureFile, ensureFileSync } from "fs-extra";
4
+ import { EOL, tmpdir } from "os";
5
+ import { appendFileSync } from "fs";
6
+
7
+ const metricsFolder = join(tmpdir(), ".metrics");
8
+ const metricsFile = join(metricsFolder, "output.txt");
9
+
10
+ export async function appendOutput(data: tracePoint): Promise<void> {
11
+ await ensureDir(metricsFolder);
12
+ await ensureFile(metricsFile);
13
+ await appendFile(metricsFile, JSON.stringify(data) + EOL);
14
+ return;
15
+ }
16
+
17
+ export function appendOutputSync(data: tracePoint): void {
18
+ ensureDirSync(metricsFolder);
19
+ ensureFileSync(metricsFile);
20
+ appendFileSync(metricsFile, JSON.stringify(data) + EOL);
21
+ return;
22
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "experimentalDecorators": true,
4
+ "emitDecoratorMetadata": true,
5
+ "module": "CommonJS",
6
+ "target": "es2017",
7
+ "outDir": "build",
8
+ "lib": ["es6"],
9
+ "allowJs": true,
10
+ "importHelpers": true,
11
+ "skipLibCheck": true,
12
+ "esModuleInterop": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "sourceMap": true,
15
+ "declarationMap": true,
16
+ "strict": true,
17
+ "forceConsistentCasingInFileNames": true,
18
+ "moduleResolution": "node",
19
+ "resolveJsonModule": true,
20
+ "jsx": "react",
21
+ "declaration": true
22
+ },
23
+ "include": ["src"],
24
+ "exclude": ["node_modules", "tests", "sample"]
25
+ }