@sap-ux/telemetry 0.2.0

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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +27 -0
  3. package/dist/base/client/azure-appinsight-client.d.ts +88 -0
  4. package/dist/base/client/azure-appinsight-client.js +195 -0
  5. package/dist/base/client/client.d.ts +24 -0
  6. package/dist/base/client/client.js +33 -0
  7. package/dist/base/client/index.d.ts +24 -0
  8. package/dist/base/client/index.js +38 -0
  9. package/dist/base/config-state.d.ts +12 -0
  10. package/dist/base/config-state.js +26 -0
  11. package/dist/base/decorator/index.d.ts +23 -0
  12. package/dist/base/decorator/index.js +41 -0
  13. package/dist/base/interceptor/config.d.ts +19 -0
  14. package/dist/base/interceptor/config.js +54 -0
  15. package/dist/base/interceptor/index.d.ts +10 -0
  16. package/dist/base/interceptor/index.js +90 -0
  17. package/dist/base/performance/api.d.ts +74 -0
  18. package/dist/base/performance/api.js +120 -0
  19. package/dist/base/performance/entries.d.ts +42 -0
  20. package/dist/base/performance/entries.js +53 -0
  21. package/dist/base/performance/types.d.ts +35 -0
  22. package/dist/base/performance/types.js +17 -0
  23. package/dist/base/types/event-header.d.ts +28 -0
  24. package/dist/base/types/event-header.js +38 -0
  25. package/dist/base/types/event-name.d.ts +6 -0
  26. package/dist/base/types/event-name.js +10 -0
  27. package/dist/base/types/index.d.ts +5 -0
  28. package/dist/base/types/index.js +21 -0
  29. package/dist/base/types/project-info.d.ts +5 -0
  30. package/dist/base/types/project-info.js +3 -0
  31. package/dist/base/types/sample-rate.d.ts +6 -0
  32. package/dist/base/types/sample-rate.js +10 -0
  33. package/dist/base/utils/azure-client-config.d.ts +9 -0
  34. package/dist/base/utils/azure-client-config.js +21 -0
  35. package/dist/base/utils/date.d.ts +2 -0
  36. package/dist/base/utils/date.js +9 -0
  37. package/dist/base/utils/index.d.ts +6 -0
  38. package/dist/base/utils/index.js +24 -0
  39. package/dist/base/utils/logger.d.ts +6 -0
  40. package/dist/base/utils/logger.js +10 -0
  41. package/dist/base/utils/param-processing.d.ts +46 -0
  42. package/dist/base/utils/param-processing.js +103 -0
  43. package/dist/base/utils/reporting.d.ts +3 -0
  44. package/dist/base/utils/reporting.js +101 -0
  45. package/dist/index.d.ts +12 -0
  46. package/dist/index.js +35 -0
  47. package/dist/tooling-telemetry/config-state.d.ts +4 -0
  48. package/dist/tooling-telemetry/config-state.js +7 -0
  49. package/dist/tooling-telemetry/data-processor.d.ts +23 -0
  50. package/dist/tooling-telemetry/data-processor.js +354 -0
  51. package/dist/tooling-telemetry/index.d.ts +5 -0
  52. package/dist/tooling-telemetry/index.js +23 -0
  53. package/dist/tooling-telemetry/telemetry-client.d.ts +65 -0
  54. package/dist/tooling-telemetry/telemetry-client.js +118 -0
  55. package/dist/tooling-telemetry/telemetry-settings.d.ts +22 -0
  56. package/dist/tooling-telemetry/telemetry-settings.js +180 -0
  57. package/dist/tooling-telemetry/types.d.ts +92 -0
  58. package/dist/tooling-telemetry/types.js +40 -0
  59. package/package.json +60 -0
@@ -0,0 +1,23 @@
1
+ import type { SampleRate } from '../types/sample-rate';
2
+ import type { ParamRecordConfig } from '../utils/param-processing';
3
+ /**
4
+ * Decorator used to log a telemetry event.
5
+ *
6
+ * @param evtName - Event names to filter data on backend, use EventNames predefined in Telemetry.EventName enumeration
7
+ * @param interceptorType - Interceptor type to apply to decorated function, use interceptorTypes predefined in Telemetry.interceptorTypes enumeration
8
+ * @param sampleRate - Sample rate for recorded data, use predefined sample rates in Telemetry.SampleRate enumeration
9
+ * @param paramsCapturingInstructions - Optional param, Should be passed when interceptor of type CAPTURE_PARAM being used. As single instance or array of instances (when multiple params should be captured or some additional sumbission data should be predefined). Allows predefine property name, value or specify paths to value to be captured (if it's element of array or nested in object)
10
+ * @returns function
11
+ */
12
+ export declare const logTelemetry: (evtName: string, interceptorType: string, sampleRate: SampleRate, paramsCapturingInstructions: ParamRecordConfig | ParamRecordConfig[]) => Function;
13
+ /**
14
+ * Decorator to log telemetry asynchronously.
15
+ *
16
+ * @param evtName - Event names to filter data on backend, use EventNames predefined in Telemetry.EventName enumeration
17
+ * @param interceptorType - Interceptor type to apply to decorated function, use interceptorTypes predefined in Telemetry.interceptorTypes enumeration
18
+ * @param sampleRate - Sample rate for recorded data, use predefined sample rates in Telemetry.SampleRate enumeration
19
+ * @param paramsCapturingInstructions - Optional param, Should be passed when interceptor of type CAPTURE_PARAM being used. As single instance or array of instances (when multiple params should be captured or some additional sumbission data should be predefined). Allows predefine property name, value or specify paths to value to be captured (if it's element of array or nested in object)
20
+ * @returns function
21
+ */
22
+ export declare const logTelemetryAsync: (evtName: string, interceptorType: string, sampleRate: SampleRate, paramsCapturingInstructions: ParamRecordConfig | ParamRecordConfig[]) => Function;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logTelemetryAsync = exports.logTelemetry = void 0;
4
+ const config_1 = require("../interceptor/config");
5
+ const decorCommon = (isAsync, target, descriptor, evtName, interceptorType, sampleRate, paramsCapturingInstructions) => {
6
+ const originalMethod = descriptor.value;
7
+ const interceptorTypesMap = isAsync ? config_1.asyncInterceptorTypesMapping : config_1.interceptorTypesMapping;
8
+ const interceptor = interceptorTypesMap.get(interceptorType);
9
+ descriptor.value = interceptor(target, originalMethod, evtName, sampleRate, paramsCapturingInstructions);
10
+ };
11
+ /**
12
+ * Decorator used to log a telemetry event.
13
+ *
14
+ * @param evtName - Event names to filter data on backend, use EventNames predefined in Telemetry.EventName enumeration
15
+ * @param interceptorType - Interceptor type to apply to decorated function, use interceptorTypes predefined in Telemetry.interceptorTypes enumeration
16
+ * @param sampleRate - Sample rate for recorded data, use predefined sample rates in Telemetry.SampleRate enumeration
17
+ * @param paramsCapturingInstructions - Optional param, Should be passed when interceptor of type CAPTURE_PARAM being used. As single instance or array of instances (when multiple params should be captured or some additional sumbission data should be predefined). Allows predefine property name, value or specify paths to value to be captured (if it's element of array or nested in object)
18
+ * @returns function
19
+ */
20
+ const logTelemetry = (evtName, interceptorType, sampleRate, paramsCapturingInstructions) => {
21
+ return (target, functionName, descriptor) => {
22
+ decorCommon(false, target, descriptor, evtName, interceptorType, sampleRate, paramsCapturingInstructions);
23
+ };
24
+ };
25
+ exports.logTelemetry = logTelemetry;
26
+ /**
27
+ * Decorator to log telemetry asynchronously.
28
+ *
29
+ * @param evtName - Event names to filter data on backend, use EventNames predefined in Telemetry.EventName enumeration
30
+ * @param interceptorType - Interceptor type to apply to decorated function, use interceptorTypes predefined in Telemetry.interceptorTypes enumeration
31
+ * @param sampleRate - Sample rate for recorded data, use predefined sample rates in Telemetry.SampleRate enumeration
32
+ * @param paramsCapturingInstructions - Optional param, Should be passed when interceptor of type CAPTURE_PARAM being used. As single instance or array of instances (when multiple params should be captured or some additional sumbission data should be predefined). Allows predefine property name, value or specify paths to value to be captured (if it's element of array or nested in object)
33
+ * @returns function
34
+ */
35
+ const logTelemetryAsync = (evtName, interceptorType, sampleRate, paramsCapturingInstructions) => {
36
+ return (target, functionName, descriptor) => {
37
+ decorCommon(true, target, descriptor, evtName, interceptorType, sampleRate, paramsCapturingInstructions);
38
+ };
39
+ };
40
+ exports.logTelemetryAsync = logTelemetryAsync;
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,19 @@
1
+ export declare enum InterceptorTypes {
2
+ /**
3
+ * Simple notification interceptor, reports certain event
4
+ * occurance and requires no data to be captured or measured.
5
+ */
6
+ NOTIFICATION = "notify",
7
+ /**
8
+ * Duration interceptor, measures and reports runtime of decorated method.
9
+ */
10
+ DURATION = "duration",
11
+ /**
12
+ * Captures specified in paramCaptureConfig parameter of decorated method.
13
+ */
14
+ CAPTURE_PARAM = "captureParam"
15
+ }
16
+ declare const interceptorTypesMapping: Map<any, any>;
17
+ declare const asyncInterceptorTypesMapping: Map<any, any>;
18
+ export { interceptorTypesMapping, asyncInterceptorTypesMapping };
19
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.asyncInterceptorTypesMapping = exports.interceptorTypesMapping = exports.InterceptorTypes = void 0;
27
+ const interceptors = __importStar(require("./index"));
28
+ var InterceptorTypes;
29
+ (function (InterceptorTypes) {
30
+ /**
31
+ * Simple notification interceptor, reports certain event
32
+ * occurance and requires no data to be captured or measured.
33
+ */
34
+ InterceptorTypes["NOTIFICATION"] = "notify";
35
+ /**
36
+ * Duration interceptor, measures and reports runtime of decorated method.
37
+ */
38
+ InterceptorTypes["DURATION"] = "duration";
39
+ /**
40
+ * Captures specified in paramCaptureConfig parameter of decorated method.
41
+ */
42
+ InterceptorTypes["CAPTURE_PARAM"] = "captureParam";
43
+ })(InterceptorTypes = exports.InterceptorTypes || (exports.InterceptorTypes = {}));
44
+ const interceptorTypesMapping = new Map();
45
+ exports.interceptorTypesMapping = interceptorTypesMapping;
46
+ interceptorTypesMapping.set(InterceptorTypes.NOTIFICATION, interceptors.notify);
47
+ interceptorTypesMapping.set(InterceptorTypes.DURATION, interceptors.duration);
48
+ interceptorTypesMapping.set(InterceptorTypes.CAPTURE_PARAM, interceptors.captureParam);
49
+ const asyncInterceptorTypesMapping = new Map();
50
+ exports.asyncInterceptorTypesMapping = asyncInterceptorTypesMapping;
51
+ asyncInterceptorTypesMapping.set(InterceptorTypes.NOTIFICATION, interceptors.notifyAsync);
52
+ asyncInterceptorTypesMapping.set(InterceptorTypes.DURATION, interceptors.durationAsync);
53
+ asyncInterceptorTypesMapping.set(InterceptorTypes.CAPTURE_PARAM, interceptors.captureParamAsync);
54
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,10 @@
1
+ import type { EventName } from '../types/event-name';
2
+ import type { SampleRate } from '../types/sample-rate';
3
+ import type { ParamRecordConfig } from '../utils/param-processing';
4
+ export declare const notify: (target: Record<string, object>, originalFn: Function, evtName: EventName, sampleRate: SampleRate) => Function;
5
+ export declare const notifyAsync: (target: Record<string, object>, originalFn: Function, evtName: EventName, sampleRate: SampleRate) => Function;
6
+ export declare const duration: (target: Record<string, object>, originalFn: Function, evtName: EventName, sampleRate: SampleRate) => Function;
7
+ export declare const durationAsync: (target: Record<string, object>, originalFn: Function, evtName: EventName, sampleRate: SampleRate) => Function;
8
+ export declare const captureParam: (target: Record<string, object>, originalFn: Function, evtName: EventName, sampleRate: SampleRate, instructions: ParamRecordConfig | ParamRecordConfig[]) => Function;
9
+ export declare const captureParamAsync: (target: Record<string, object>, originalFn: Function, evtName: EventName, sampleRate: SampleRate, instructions: ParamRecordConfig | ParamRecordConfig[]) => Function;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.captureParamAsync = exports.captureParam = exports.durationAsync = exports.duration = exports.notifyAsync = exports.notify = void 0;
13
+ const client_1 = require("../client");
14
+ const api_1 = require("../performance/api");
15
+ const param_processing_1 = require("../utils/param-processing");
16
+ const notify = (target, originalFn, evtName, sampleRate) => {
17
+ return (...args) => {
18
+ const result = originalFn.apply(target, args);
19
+ const appinsightClient = client_1.ClientFactory.getTelemetryClient();
20
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
21
+ appinsightClient.report(evtName, {}, {}, sampleRate);
22
+ return result;
23
+ };
24
+ };
25
+ exports.notify = notify;
26
+ const notifyAsync = (target, originalFn, evtName, sampleRate) => {
27
+ return (...args) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const result = yield originalFn.apply(target, args);
29
+ const appinsightClient = client_1.ClientFactory.getTelemetryClient();
30
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
31
+ appinsightClient.report(evtName, {}, {}, sampleRate);
32
+ return result;
33
+ });
34
+ };
35
+ exports.notifyAsync = notifyAsync;
36
+ const duration = (target, originalFn, evtName, sampleRate) => {
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ return (...args) => {
39
+ const markName = api_1.PerformanceMeasurementAPI.startMark('mark');
40
+ const result = originalFn.apply(target, args);
41
+ api_1.PerformanceMeasurementAPI.endMark(markName);
42
+ api_1.PerformanceMeasurementAPI.measure(markName);
43
+ const duration = api_1.PerformanceMeasurementAPI.getMeasurementDuration(markName);
44
+ const appinsightClient = client_1.ClientFactory.getTelemetryClient();
45
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
46
+ appinsightClient.report(evtName, {}, { ms: duration }, sampleRate);
47
+ return result;
48
+ };
49
+ };
50
+ exports.duration = duration;
51
+ const durationAsync = (target, originalFn, evtName, sampleRate) => {
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ return (...args) => __awaiter(void 0, void 0, void 0, function* () {
54
+ const markName = api_1.PerformanceMeasurementAPI.startMark('mark');
55
+ const result = yield originalFn.apply(target, args);
56
+ api_1.PerformanceMeasurementAPI.endMark(markName);
57
+ api_1.PerformanceMeasurementAPI.measure(markName);
58
+ const duration = api_1.PerformanceMeasurementAPI.getMeasurementDuration(markName);
59
+ const appinsightClient = client_1.ClientFactory.getTelemetryClient();
60
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
61
+ appinsightClient.report(evtName, {}, { ms: duration }, sampleRate);
62
+ return result;
63
+ });
64
+ };
65
+ exports.durationAsync = durationAsync;
66
+ const captureParam = (target, originalFn, evtName, sampleRate, instructions) => {
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ return (...args) => {
69
+ const result = originalFn.apply(target, args);
70
+ const [customDimensions, customMeasurements] = (0, param_processing_1.getParamsData)(args, instructions);
71
+ const appinsightClient = client_1.ClientFactory.getTelemetryClient();
72
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
73
+ appinsightClient.report(evtName, customDimensions, customMeasurements, sampleRate);
74
+ return result;
75
+ };
76
+ };
77
+ exports.captureParam = captureParam;
78
+ const captureParamAsync = (target, originalFn, evtName, sampleRate, instructions) => {
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ return (...args) => __awaiter(void 0, void 0, void 0, function* () {
81
+ const result = yield originalFn.apply(target, args);
82
+ const [customDimensions, customMeasurements] = (0, param_processing_1.getParamsData)(args, instructions);
83
+ const appinsightClient = client_1.ClientFactory.getTelemetryClient();
84
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
85
+ appinsightClient.report(evtName, customDimensions, customMeasurements, sampleRate);
86
+ return result;
87
+ });
88
+ };
89
+ exports.captureParamAsync = captureParamAsync;
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,74 @@
1
+ import type { EntriesArray } from './types';
2
+ import { EntryType, PerformanceMeasurement } from './types';
3
+ /**
4
+ *
5
+ */
6
+ declare class PerformanceMeasurementAPI extends PerformanceMeasurement {
7
+ static initTiming: number;
8
+ private static now;
9
+ static entries: EntriesArray;
10
+ static initialize(): void;
11
+ /**
12
+ * Create a new Mark.
13
+ *
14
+ * @param name Name of mark
15
+ * @param type type of mark
16
+ * @param timing Timestamp when mark is created, measured in ms
17
+ */
18
+ private static mark;
19
+ /**
20
+ * Create a start mark of a measurement.
21
+ *
22
+ * @param name Name of start mark
23
+ * @returns Id to track a measurement
24
+ */
25
+ static startMark(name: string): string;
26
+ /**
27
+ * Set end mark of a measurement.
28
+ *
29
+ * @param name Name of end mark
30
+ */
31
+ static endMark(name: string): void;
32
+ /**
33
+ * Measure execution time lenght of a given mark name.
34
+ *
35
+ * @param markName Name of mark
36
+ */
37
+ static measure(markName: string): void;
38
+ /**
39
+ * @returns All entries
40
+ */
41
+ static getEntries(): EntriesArray;
42
+ /**
43
+ * Get Mark/Measurement by name.
44
+ *
45
+ * @param name Name of entry
46
+ * @returns array of marks/measurements
47
+ */
48
+ static getEntriesByName(name: string): EntriesArray;
49
+ /**
50
+ * Get Mark/Measurement by name and type.
51
+ *
52
+ * @param name Name of entry
53
+ * @param type EntryType
54
+ * @returns array of marks/measurements
55
+ */
56
+ static getEntriesByNameType(name: string, type: EntryType): EntriesArray;
57
+ /**
58
+ * Get Mark/Measurement by type.
59
+ *
60
+ * @param type EntryType
61
+ * @returns array of marks/measurements
62
+ */
63
+ static getEntriesByType(type: EntryType): EntriesArray;
64
+ /**
65
+ * Get duration of a measurement.
66
+ *
67
+ * @param name Name of a measurement
68
+ * @returns time length in ms
69
+ */
70
+ static getMeasurementDuration(name: string): number;
71
+ static clearEntries(): void;
72
+ }
73
+ export { PerformanceMeasurementAPI };
74
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PerformanceMeasurementAPI = void 0;
4
+ const entries_1 = require("./entries");
5
+ const types_1 = require("./types");
6
+ const performanceNow = require("performance-now");
7
+ /**
8
+ *
9
+ */
10
+ class PerformanceMeasurementAPI extends types_1.PerformanceMeasurement {
11
+ // reported time is relative to the time the current Node process has started (inferred from process.uptime())
12
+ static initialize() {
13
+ PerformanceMeasurementAPI.initTiming = PerformanceMeasurementAPI.now();
14
+ }
15
+ /**
16
+ * Create a new Mark.
17
+ *
18
+ * @param name Name of mark
19
+ * @param type type of mark
20
+ * @param timing Timestamp when mark is created, measured in ms
21
+ */
22
+ static mark(name, type, timing) {
23
+ const entry = new entries_1.Mark(name, type, timing);
24
+ PerformanceMeasurementAPI.entries.push(entry);
25
+ }
26
+ /**
27
+ * Create a start mark of a measurement.
28
+ *
29
+ * @param name Name of start mark
30
+ * @returns Id to track a measurement
31
+ */
32
+ static startMark(name) {
33
+ const timing = PerformanceMeasurementAPI.now();
34
+ const extendedName = name + timing;
35
+ PerformanceMeasurementAPI.mark(extendedName, types_1.EntryType.START_MARK, timing);
36
+ return extendedName;
37
+ }
38
+ /**
39
+ * Set end mark of a measurement.
40
+ *
41
+ * @param name Name of end mark
42
+ */
43
+ static endMark(name) {
44
+ const timing = PerformanceMeasurementAPI.now();
45
+ PerformanceMeasurementAPI.mark(name, types_1.EntryType.END_MARK, timing);
46
+ }
47
+ /**
48
+ * Measure execution time lenght of a given mark name.
49
+ *
50
+ * @param markName Name of mark
51
+ */
52
+ static measure(markName) {
53
+ const startMark = PerformanceMeasurementAPI.getEntriesByNameType(markName, types_1.EntryType.START_MARK).slice(-1)[0];
54
+ const endMark = PerformanceMeasurementAPI.getEntriesByNameType(markName, types_1.EntryType.END_MARK).slice(-1)[0];
55
+ if (!startMark && !endMark) {
56
+ throw new Error(`Failed to execute 'measure': mark '${markName}' doesn't exist.`);
57
+ }
58
+ else if (!startMark || !endMark) {
59
+ const errMarkType = startMark ? types_1.EntryType.END_MARK : types_1.EntryType.START_MARK;
60
+ throw new Error(`Failed to execute 'measure': mark '${markName}'of type '${errMarkType}' doesn't exist.`);
61
+ }
62
+ const startTime = startMark.getStartTime();
63
+ const endTime = endMark.getStartTime();
64
+ const duration = endTime - startTime;
65
+ const measurement = new entries_1.Measurement(`${markName}`, PerformanceMeasurementAPI.now(), duration);
66
+ PerformanceMeasurementAPI.entries.push(measurement);
67
+ }
68
+ /**
69
+ * @returns All entries
70
+ */
71
+ static getEntries() {
72
+ return PerformanceMeasurementAPI.entries;
73
+ }
74
+ /**
75
+ * Get Mark/Measurement by name.
76
+ *
77
+ * @param name Name of entry
78
+ * @returns array of marks/measurements
79
+ */
80
+ static getEntriesByName(name) {
81
+ return PerformanceMeasurementAPI.entries.filter((entry) => entry.name === name);
82
+ }
83
+ /**
84
+ * Get Mark/Measurement by name and type.
85
+ *
86
+ * @param name Name of entry
87
+ * @param type EntryType
88
+ * @returns array of marks/measurements
89
+ */
90
+ static getEntriesByNameType(name, type) {
91
+ return PerformanceMeasurementAPI.entries.filter((entry) => entry.name === name && entry.type === type);
92
+ }
93
+ /**
94
+ * Get Mark/Measurement by type.
95
+ *
96
+ * @param type EntryType
97
+ * @returns array of marks/measurements
98
+ */
99
+ static getEntriesByType(type) {
100
+ return PerformanceMeasurementAPI.entries.filter((entry) => entry.type === type);
101
+ }
102
+ /**
103
+ * Get duration of a measurement.
104
+ *
105
+ * @param name Name of a measurement
106
+ * @returns time length in ms
107
+ */
108
+ static getMeasurementDuration(name) {
109
+ const entry = PerformanceMeasurementAPI.getEntriesByNameType(name, types_1.EntryType.MEASUREMENT).slice(-1)[0];
110
+ return entry.getDurationTime();
111
+ }
112
+ static clearEntries() {
113
+ PerformanceMeasurementAPI.entries = [];
114
+ }
115
+ }
116
+ exports.PerformanceMeasurementAPI = PerformanceMeasurementAPI;
117
+ PerformanceMeasurementAPI.now = performanceNow;
118
+ PerformanceMeasurementAPI.entries = [];
119
+ PerformanceMeasurementAPI.initialize();
120
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1,42 @@
1
+ import type { Measurement as IMeasurement, Mark as IMark } from './types';
2
+ import { EntryType } from './types';
3
+ /**
4
+ * Repreeents a mark during a performance measurement.
5
+ */
6
+ declare class Mark implements IMark {
7
+ readonly startTime: number;
8
+ [index: number]: string;
9
+ name: string;
10
+ type: EntryType;
11
+ /**
12
+ * @returns start time in millieseconds
13
+ */
14
+ getStartTime(): number;
15
+ /**
16
+ *
17
+ * @param name Name of mark
18
+ * @param type Mark type
19
+ * @param startTime start time in millieseconds
20
+ */
21
+ constructor(name: string, type: EntryType, startTime: number);
22
+ }
23
+ /**
24
+ * Measurement of execution time length
25
+ */
26
+ declare class Measurement extends Mark implements IMeasurement {
27
+ readonly startTime: number;
28
+ readonly duration: number;
29
+ /**
30
+ *
31
+ * @param name Name of a mark
32
+ * @param startTime start time in millieseconds
33
+ * @param duration time in millieseconds
34
+ */
35
+ constructor(name: string, startTime: number, duration: number);
36
+ /**
37
+ * @returns duration in milliseconds
38
+ */
39
+ getDurationTime(): number;
40
+ }
41
+ export { Mark, Measurement };
42
+ //# sourceMappingURL=entries.d.ts.map
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Measurement = exports.Mark = void 0;
4
+ const types_1 = require("./types");
5
+ /**
6
+ * Repreeents a mark during a performance measurement.
7
+ */
8
+ class Mark {
9
+ /**
10
+ * @returns start time in millieseconds
11
+ */
12
+ getStartTime() {
13
+ return this.startTime;
14
+ }
15
+ /**
16
+ *
17
+ * @param name Name of mark
18
+ * @param type Mark type
19
+ * @param startTime start time in millieseconds
20
+ */
21
+ constructor(name, type, startTime) {
22
+ this.startTime = startTime;
23
+ this.name = name;
24
+ this.startTime = startTime;
25
+ this.type = type;
26
+ }
27
+ }
28
+ exports.Mark = Mark;
29
+ /**
30
+ * Measurement of execution time length
31
+ */
32
+ class Measurement extends Mark {
33
+ /**
34
+ *
35
+ * @param name Name of a mark
36
+ * @param startTime start time in millieseconds
37
+ * @param duration time in millieseconds
38
+ */
39
+ constructor(name, startTime, duration) {
40
+ super(name, types_1.EntryType.MEASUREMENT, startTime);
41
+ this.startTime = startTime;
42
+ this.duration = duration;
43
+ this.duration = duration;
44
+ }
45
+ /**
46
+ * @returns duration in milliseconds
47
+ */
48
+ getDurationTime() {
49
+ return this.duration;
50
+ }
51
+ }
52
+ exports.Measurement = Measurement;
53
+ //# sourceMappingURL=entries.js.map
@@ -0,0 +1,35 @@
1
+ declare enum EntryType {
2
+ START_MARK = "START_MARK",
3
+ END_MARK = "END_MARK",
4
+ MEASUREMENT = "MEASUREMENT"
5
+ }
6
+ interface Mark {
7
+ type: EntryType;
8
+ name: string;
9
+ startTime: number;
10
+ getStartTime: () => number;
11
+ }
12
+ interface Measurement extends Mark {
13
+ readonly duration: number;
14
+ getDurationTime: () => number;
15
+ }
16
+ type EntriesArray = (Mark | Measurement)[];
17
+ /**
18
+ *
19
+ */
20
+ declare abstract class PerformanceMeasurement {
21
+ static initTiming: number;
22
+ static enteries: EntriesArray;
23
+ static initialize: () => void;
24
+ static startMark: (name: string) => string;
25
+ static endMark: (name: string) => void;
26
+ static measure: (name: string) => void;
27
+ static getEntries: () => EntriesArray;
28
+ static getEntriesByName: (name: string) => EntriesArray;
29
+ static getEntriesByType: (type: EntryType) => EntriesArray;
30
+ static getEntriesByNameType: (name: string, type: EntryType) => EntriesArray;
31
+ static getMeasurementDuration: (name: string) => number;
32
+ static clearEntries: () => void;
33
+ }
34
+ export { EntryType, Mark, Measurement, EntriesArray, PerformanceMeasurement };
35
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PerformanceMeasurement = exports.EntryType = void 0;
4
+ var EntryType;
5
+ (function (EntryType) {
6
+ EntryType["START_MARK"] = "START_MARK";
7
+ EntryType["END_MARK"] = "END_MARK";
8
+ EntryType["MEASUREMENT"] = "MEASUREMENT";
9
+ })(EntryType || (EntryType = {}));
10
+ exports.EntryType = EntryType;
11
+ /**
12
+ *
13
+ */
14
+ class PerformanceMeasurement {
15
+ }
16
+ exports.PerformanceMeasurement = PerformanceMeasurement;
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Hierarchical event name for a telemetry event submitted to Auzre Application Insights.
3
+ */
4
+ declare class EventHeader {
5
+ private extensionName;
6
+ private eventName;
7
+ /**
8
+ * Event header that is composed of two parts.
9
+ *
10
+ * @param extensionName Consumer module name
11
+ * @param eventName Telemetry event name
12
+ */
13
+ constructor(extensionName: string, eventName: string);
14
+ /**
15
+ * @returns Consumer module name
16
+ */
17
+ getExtensionName(): string;
18
+ /**
19
+ * @returns Event name
20
+ */
21
+ getEventName(): string;
22
+ /**
23
+ * @returns serialized string of event header
24
+ */
25
+ toString(): string;
26
+ }
27
+ export { EventHeader };
28
+ //# sourceMappingURL=event-header.d.ts.map
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventHeader = void 0;
4
+ /**
5
+ * Hierarchical event name for a telemetry event submitted to Auzre Application Insights.
6
+ */
7
+ class EventHeader {
8
+ /**
9
+ * Event header that is composed of two parts.
10
+ *
11
+ * @param extensionName Consumer module name
12
+ * @param eventName Telemetry event name
13
+ */
14
+ constructor(extensionName, eventName) {
15
+ this.extensionName = extensionName;
16
+ this.eventName = eventName;
17
+ }
18
+ /**
19
+ * @returns Consumer module name
20
+ */
21
+ getExtensionName() {
22
+ return this.extensionName;
23
+ }
24
+ /**
25
+ * @returns Event name
26
+ */
27
+ getEventName() {
28
+ return this.eventName;
29
+ }
30
+ /**
31
+ * @returns serialized string of event header
32
+ */
33
+ toString() {
34
+ return `${this.extensionName}/${this.eventName}`;
35
+ }
36
+ }
37
+ exports.EventHeader = EventHeader;
38
+ //# sourceMappingURL=event-header.js.map
@@ -0,0 +1,6 @@
1
+ export declare enum EventName {
2
+ Test = "test",
3
+ TELEMETRY_SETTINGS_INIT_FAILED = "TELEMETRY_SETTINGS_INIT_FAILED",
4
+ DISABLE_TELEMETRY = "DISABLE_TELEMETRY"
5
+ }
6
+ //# sourceMappingURL=event-name.d.ts.map