@appland/telemetry 1.1.0 → 1.1.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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@appland/telemetry-v1.1.1](https://github.com/getappmap/appmap-js/compare/@appland/telemetry-v1.1.0...@appland/telemetry-v1.1.1) (2025-10-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Make sure application insights telemetry quits gracefully ([a5ffd12](https://github.com/getappmap/appmap-js/commit/a5ffd12333561be117254587ace8f32553e00983))
|
|
7
|
+
|
|
1
8
|
# [@appland/telemetry-v1.1.0](https://github.com/getappmap/appmap-js/compare/@appland/telemetry-v1.0.0...@appland/telemetry-v1.1.0) (2025-10-07)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { ApplicationInsightsBackendConfiguration, FlushCallback, TelemetryBackend, TelemetryData } from '../types';
|
|
1
|
+
import type { ApplicationInsightsBackendConfiguration, FlushCallback, TelemetryBackend, TelemetryData } from '../types';
|
|
2
2
|
export declare class ApplicationInsightsBackend implements TelemetryBackend {
|
|
3
3
|
private readonly config;
|
|
4
|
-
private readonly
|
|
4
|
+
private readonly instrumentationKey;
|
|
5
|
+
private readonly userId;
|
|
6
|
+
private readonly sessionId;
|
|
7
|
+
private readonly productName;
|
|
8
|
+
private readonly hostname;
|
|
9
|
+
private readonly uname;
|
|
5
10
|
constructor(userId: string, sessionId: string, productName: string, config: ApplicationInsightsBackendConfiguration);
|
|
6
11
|
sendEvent(event: TelemetryData): void;
|
|
7
12
|
flush(callback?: FlushCallback): void;
|
|
13
|
+
private _post;
|
|
8
14
|
}
|
|
@@ -1,7 +1,44 @@
|
|
|
1
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.ApplicationInsightsBackend = void 0;
|
|
4
|
-
const
|
|
40
|
+
const https = __importStar(require("node:https"));
|
|
41
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
5
42
|
// This key is meant to be publically shared. However, I'm adding a simple
|
|
6
43
|
// obfuscation to mitigate key scraping bots on GitHub. The key is split on
|
|
7
44
|
// hypens and base64 encoded without padding.
|
|
@@ -9,38 +46,68 @@ const applicationinsights_1 = require("applicationinsights");
|
|
|
9
46
|
const INSTRUMENTATION_KEY = ['NTBjMWE1YzI', 'NDliNA', 'NDkxMw', 'YjdjYw', 'ODZhNzhkNDA3NDVm']
|
|
10
47
|
.map((x) => Buffer.from(x, 'base64').toString('utf8'))
|
|
11
48
|
.join('-');
|
|
49
|
+
const AI_ENDPOINT = 'dc.services.visualstudio.com';
|
|
50
|
+
const AI_PATH = '/v2/track';
|
|
12
51
|
class ApplicationInsightsBackend {
|
|
13
52
|
constructor(userId, sessionId, productName, config) {
|
|
14
53
|
this.config = config;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.setAutoCollectExceptions(false)
|
|
22
|
-
.setAutoCollectDependencies(false)
|
|
23
|
-
.setAutoCollectHeartbeat(false)
|
|
24
|
-
.setAutoDependencyCorrelation(false)
|
|
25
|
-
.setAutoCollectConsole(false)
|
|
26
|
-
.setInternalLogging(false, false)
|
|
27
|
-
.setSendLiveMetrics(false)
|
|
28
|
-
.setUseDiskRetryCaching(true);
|
|
29
|
-
const client = new applicationinsights_1.TelemetryClient(instrumentationKey);
|
|
30
|
-
client.context.tags[client.context.keys.userId] = userId;
|
|
31
|
-
client.context.tags[client.context.keys.sessionId] = sessionId;
|
|
32
|
-
client.context.tags[client.context.keys.cloudRole] = productName;
|
|
33
|
-
client.setAutoPopulateAzureProperties(false);
|
|
34
|
-
this.client = client;
|
|
54
|
+
this.instrumentationKey = this.config.instrumentationKey || INSTRUMENTATION_KEY;
|
|
55
|
+
this.userId = userId;
|
|
56
|
+
this.sessionId = sessionId;
|
|
57
|
+
this.productName = productName;
|
|
58
|
+
this.hostname = node_os_1.default.hostname();
|
|
59
|
+
this.uname = node_os_1.default.type() + ' ' + node_os_1.default.release();
|
|
35
60
|
}
|
|
36
61
|
sendEvent(event) {
|
|
37
|
-
|
|
38
|
-
|
|
62
|
+
const envelope = {
|
|
63
|
+
name: 'Microsoft.ApplicationInsights.Event',
|
|
64
|
+
time: new Date().toISOString(),
|
|
65
|
+
iKey: this.instrumentationKey,
|
|
66
|
+
tags: {
|
|
67
|
+
'ai.user.id': this.userId,
|
|
68
|
+
'ai.session.id': this.sessionId,
|
|
69
|
+
'ai.cloud.role': this.productName,
|
|
70
|
+
'ai.cloud.roleInstance': this.hostname,
|
|
71
|
+
'ai.device.osVersion': this.uname
|
|
72
|
+
},
|
|
73
|
+
data: {
|
|
74
|
+
baseType: 'EventData',
|
|
75
|
+
baseData: event,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
this._post([envelope]);
|
|
39
79
|
}
|
|
40
80
|
flush(callback) {
|
|
41
|
-
|
|
81
|
+
// No batching, so nothing to flush. Just call callback.
|
|
42
82
|
callback === null || callback === void 0 ? void 0 : callback();
|
|
43
83
|
}
|
|
84
|
+
_post(envelopes) {
|
|
85
|
+
const body = JSON.stringify(envelopes);
|
|
86
|
+
const options = {
|
|
87
|
+
hostname: AI_ENDPOINT,
|
|
88
|
+
path: AI_PATH,
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/json',
|
|
92
|
+
'Content-Length': Buffer.byteLength(body),
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
const req = https.request(options, (res) => {
|
|
96
|
+
// drain response to avoid memory leak
|
|
97
|
+
res
|
|
98
|
+
.on('data', () => { })
|
|
99
|
+
.on('end', () => {
|
|
100
|
+
if (res.statusCode && (res.statusCode < 200 || res.statusCode >= 300)) {
|
|
101
|
+
console.warn(`ApplicationInsightsBackend: Failed to send telemetry event. Status: ${res.statusCode}`);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
req.on('error', (e) => {
|
|
106
|
+
console.warn('Error sending telemetry data to Application Insights', e);
|
|
107
|
+
});
|
|
108
|
+
req.write(body);
|
|
109
|
+
req.end();
|
|
110
|
+
}
|
|
44
111
|
}
|
|
45
112
|
exports.ApplicationInsightsBackend = ApplicationInsightsBackend;
|
|
46
113
|
//# sourceMappingURL=application-insights.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-insights.js","sourceRoot":"","sources":["../../src/backends/application-insights.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"application-insights.js","sourceRoot":"","sources":["../../src/backends/application-insights.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAoC;AACpC,sDAAyB;AASzB,0EAA0E;AAC1E,2EAA2E;AAC3E,6CAA6C;AAC7C,oEAAoE;AACpE,MAAM,mBAAmB,GAAG,CAAC,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC;KAC1F,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACrD,IAAI,CAAC,GAAG,CAAC,CAAC;AAEb,MAAM,WAAW,GAAG,8BAA8B,CAAC;AACnD,MAAM,OAAO,GAAG,WAAW,CAAC;AAE5B,MAAa,0BAA0B;IAQrC,YACE,MAAc,EACd,SAAiB,EACjB,WAAmB,EACF,MAA+C;QAA/C,WAAM,GAAN,MAAM,CAAyC;QAEhE,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC,kBAAkB,IAAI,mBAAmB,CAAC;QAChF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QA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AsC;YACtC,GAAG;iBACA,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;iBACrB,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACd,IAAI,GAAG,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,EAAE,CAAC;oBACtE,OAAO,CAAC,IAAI,CAAC,uEAAuE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;gBACxG,CAAC;YACH,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACpB,OAAO,CAAC,IAAI,CAAC,sDAAsD,EAAE,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChB,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC;CACF;AA1ED,gEA0EC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appland/telemetry",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"**/*": "prettier --write --ignore-unknown"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"applicationinsights": "^2.1.4",
|
|
26
25
|
"conf": "<11",
|
|
27
26
|
"read-pkg-up": "^7.0.1"
|
|
28
27
|
},
|
|
@@ -35,6 +34,7 @@
|
|
|
35
34
|
"eslint-config-prettier": "^10.1.8",
|
|
36
35
|
"jest": "^29.5.0",
|
|
37
36
|
"lint-staged": "^10.5.4",
|
|
37
|
+
"nock": "^13.2.2",
|
|
38
38
|
"prettier": "^2.7.1",
|
|
39
39
|
"sinon": "^13.0.1",
|
|
40
40
|
"ts-jest": "^29.0.5",
|