@ms-cloudpack/external-telemetry 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.
- package/README.md +18 -0
- package/lib/getAppName.d.ts +1 -0
- package/lib/getAppName.js +10 -0
- package/lib/getAppName.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/reportExternalTelemetryEvent.d.ts +6 -0
- package/lib/reportExternalTelemetryEvent.js +26 -0
- package/lib/reportExternalTelemetryEvent.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/types.d.ts +22 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @ms-cloudpack/external-telemetry
|
|
2
|
+
|
|
3
|
+
A library for report external telemetry data important to Cloudpack workflows. Data will be reported to Application Insights using Open Telemetry standards and show up on our internal dashboards for monitoring the changes in timings and usage of existing scenarios as we migrate to new Cloudpack-powered workflows.
|
|
4
|
+
|
|
5
|
+
## Example usage
|
|
6
|
+
|
|
7
|
+
1. Create a client:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { reportExternalTelemetryEvent } from '@ms-cloudpack/external-telemetry';
|
|
11
|
+
|
|
12
|
+
await reportExternalTelemetryEvent({
|
|
13
|
+
eventName: 'LEGACY-START',
|
|
14
|
+
attributes: {
|
|
15
|
+
'my-attribute': 'value',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAppName(): Promise<string | undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PackageDefinitions } from '@ms-cloudpack/package-utilities';
|
|
2
|
+
export async function getAppName() {
|
|
3
|
+
const appPath = process.cwd();
|
|
4
|
+
const definition = await PackageDefinitions.getInstance().get(appPath);
|
|
5
|
+
if (!definition) {
|
|
6
|
+
throw new Error(`There was no package.json located at "${appPath}".`);
|
|
7
|
+
}
|
|
8
|
+
return definition.name;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=getAppName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAppName.js","sourceRoot":"","sources":["../src/getAppName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9B,MAAM,UAAU,GAAG,MAAM,kBAAkB,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAEvE,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,yCAAyC,OAAO,IAAI,CAAC,CAAC;KACvE;IAED,OAAO,UAAU,CAAC,IAAI,CAAC;AACzB,CAAC","sourcesContent":["import { PackageDefinitions } from '@ms-cloudpack/package-utilities';\n\nexport async function getAppName() {\n const appPath = process.cwd();\n const definition = await PackageDefinitions.getInstance().get(appPath);\n\n if (!definition) {\n throw new Error(`There was no package.json located at \"${appPath}\".`);\n }\n\n return definition.name;\n}\n"]}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC","sourcesContent":["export { reportExternalTelemetryEvent } from './reportExternalTelemetryEvent.js';\nexport type { ReportTelemetryOptions } from './types.js';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReportTelemetryOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Report an external telemetry event to the CloudPack telemetry service.
|
|
4
|
+
* @param options - The options for reporting the event.
|
|
5
|
+
*/
|
|
6
|
+
export declare function reportExternalTelemetryEvent(options: ReportTelemetryOptions): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readConfig } from '@ms-cloudpack/config';
|
|
2
|
+
import { createTelemetryClient } from '@ms-cloudpack/telemetry';
|
|
3
|
+
import { getVersion } from '@ms-cloudpack/package-utilities';
|
|
4
|
+
import { getAppName } from './getAppName.js';
|
|
5
|
+
const external = 'EXTERNAL';
|
|
6
|
+
/**
|
|
7
|
+
* Report an external telemetry event to the CloudPack telemetry service.
|
|
8
|
+
* @param options - The options for reporting the event.
|
|
9
|
+
*/
|
|
10
|
+
export async function reportExternalTelemetryEvent(options) {
|
|
11
|
+
const { telemetry } = await readConfig();
|
|
12
|
+
const instrumentationKey = telemetry?.instrumentationKey || process.env.CLOUDPACK_TELEMETRY_INSTRUMENTATION_KEY;
|
|
13
|
+
const telemetryClient = await createTelemetryClient({
|
|
14
|
+
productVersion: getVersion(import.meta.url),
|
|
15
|
+
serviceName: 'external-telemetry',
|
|
16
|
+
serviceNamespace: 'cloudpack',
|
|
17
|
+
instrumentationKey: instrumentationKey,
|
|
18
|
+
logLevel: options.logLevel,
|
|
19
|
+
});
|
|
20
|
+
telemetryClient.setSharedSpanAttribute('appName', options.appName || (await getAppName()) || '<unknown>');
|
|
21
|
+
const externalTelemetrySpan = telemetryClient.getTracer().startSpan(external);
|
|
22
|
+
externalTelemetrySpan.addEvent(`${external}-${options.eventName}`, options.attributes);
|
|
23
|
+
externalTelemetrySpan.end();
|
|
24
|
+
await telemetryClient.shutdown();
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=reportExternalTelemetryEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reportExternalTelemetryEvent.js","sourceRoot":"","sources":["../src/reportExternalTelemetryEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,OAA+B;IAChF,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,UAAU,EAAE,CAAC;IACzC,MAAM,kBAAkB,GAAG,SAAS,EAAE,kBAAkB,IAAI,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC;IAEhH,MAAM,eAAe,GAAG,MAAM,qBAAqB,CAAC;QAClD,cAAc,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3C,WAAW,EAAE,oBAAoB;QACjC,gBAAgB,EAAE,WAAW;QAC7B,kBAAkB,EAAE,kBAAkB;QACtC,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC,CAAC;IAEH,eAAe,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,MAAM,UAAU,EAAE,CAAC,IAAI,WAAW,CAAC,CAAC;IAE1G,MAAM,qBAAqB,GAAG,eAAe,CAAC,SAAS,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAE9E,qBAAqB,CAAC,QAAQ,CAAC,GAAG,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvF,qBAAqB,CAAC,GAAG,EAAE,CAAC;IAE5B,MAAM,eAAe,CAAC,QAAQ,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { readConfig } from '@ms-cloudpack/config';\nimport { createTelemetryClient } from '@ms-cloudpack/telemetry';\nimport { getVersion } from '@ms-cloudpack/package-utilities';\nimport { getAppName } from './getAppName.js';\nimport type { ReportTelemetryOptions } from './types.js';\n\nconst external = 'EXTERNAL';\n\n/**\n * Report an external telemetry event to the CloudPack telemetry service.\n * @param options - The options for reporting the event.\n */\nexport async function reportExternalTelemetryEvent(options: ReportTelemetryOptions) {\n const { telemetry } = await readConfig();\n const instrumentationKey = telemetry?.instrumentationKey || process.env.CLOUDPACK_TELEMETRY_INSTRUMENTATION_KEY;\n\n const telemetryClient = await createTelemetryClient({\n productVersion: getVersion(import.meta.url),\n serviceName: 'external-telemetry',\n serviceNamespace: 'cloudpack',\n instrumentationKey: instrumentationKey,\n logLevel: options.logLevel,\n });\n\n telemetryClient.setSharedSpanAttribute('appName', options.appName || (await getAppName()) || '<unknown>');\n\n const externalTelemetrySpan = telemetryClient.getTracer().startSpan(external);\n\n externalTelemetrySpan.addEvent(`${external}-${options.eventName}`, options.attributes);\n\n externalTelemetrySpan.end();\n\n await telemetryClient.shutdown();\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.34.4"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for external telemetry.
|
|
3
|
+
*/
|
|
4
|
+
export interface ReportTelemetryOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Event name to be reported into application insights.
|
|
7
|
+
* "EXTERNAL-" prefix will be added by cloudpack.
|
|
8
|
+
*/
|
|
9
|
+
eventName: string;
|
|
10
|
+
/**
|
|
11
|
+
* Application name to be reported into application insights.
|
|
12
|
+
*/
|
|
13
|
+
appName?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Additional attributes to be reported into application insights.
|
|
16
|
+
*/
|
|
17
|
+
attributes?: Record<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Log level to be used by application insights.
|
|
20
|
+
*/
|
|
21
|
+
logLevel?: 'debug' | 'verbose';
|
|
22
|
+
}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options for external telemetry.\n */\nexport interface ReportTelemetryOptions {\n /**\n * Event name to be reported into application insights.\n * \"EXTERNAL-\" prefix will be added by cloudpack.\n */\n eventName: string;\n\n /**\n * Application name to be reported into application insights.\n */\n appName?: string;\n\n /**\n * Additional attributes to be reported into application insights.\n */\n attributes?: Record<string, string>;\n\n /**\n * Log level to be used by application insights.\n */\n logLevel?: 'debug' | 'verbose';\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ms-cloudpack/external-telemetry",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Reporting external telemetry which is not about of cloudpack internals.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"import": "./lib/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@ms-cloudpack/telemetry": "^0.2.2",
|
|
17
|
+
"@ms-cloudpack/config": "^0.4.0",
|
|
18
|
+
"@ms-cloudpack/package-utilities": "^2.4.0",
|
|
19
|
+
"@ms-cloudpack/path-utilities": "^2.2.1",
|
|
20
|
+
"@ms-cloudpack/json-utilities": "^0.0.6",
|
|
21
|
+
"@ms-cloudpack/bundler-types": "^0.12.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@ms-cloudpack/eslint-config-base": "*",
|
|
25
|
+
"@ms-cloudpack/scripts": "*"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"api:update": "cloudpack-scripts api-update",
|
|
29
|
+
"api": "cloudpack-scripts api",
|
|
30
|
+
"build:watch": "cloudpack-scripts build-watch",
|
|
31
|
+
"build": "cloudpack-scripts build",
|
|
32
|
+
"lint:update": "cloudpack-scripts lint-update",
|
|
33
|
+
"lint": "cloudpack-scripts lint"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"lib/**/!(*.test.*)"
|
|
37
|
+
]
|
|
38
|
+
}
|