@mhubcloud/tms_core 3.8.0-beta.7 → 3.8.0-beta.9
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/dist/index.js +44 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
DefaultPublisher: () => defaultPublisher,
|
|
34
34
|
broker: () => broker_exports,
|
|
35
|
-
|
|
35
|
+
createRedisClient: () => createRedisClient,
|
|
36
36
|
publisher: () => publisher,
|
|
37
37
|
testUtils: () => testUtils_exports,
|
|
38
38
|
utils: () => utils_exports
|
|
@@ -77,20 +77,28 @@ var appInsights = __toESM(require("applicationinsights"));
|
|
|
77
77
|
|
|
78
78
|
// src/utils/redisClient.ts
|
|
79
79
|
var import_redis = require("redis");
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
async function createRedisClient(url, password) {
|
|
81
|
+
let client;
|
|
82
|
+
if (!url || !password) {
|
|
83
|
+
if (process.env.RedisUrl && process.env.RedisPassword) {
|
|
84
|
+
client = (0, import_redis.createClient)({
|
|
85
|
+
url: `rediss://${process.env.RedisUrl}`,
|
|
86
|
+
password: process.env.RedisPassword,
|
|
87
|
+
socket: { tls: true }
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"Redis url and password are missing with no fallback available"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
87
95
|
client = (0, import_redis.createClient)({
|
|
88
|
-
url
|
|
89
|
-
password
|
|
96
|
+
url,
|
|
97
|
+
password,
|
|
90
98
|
socket: { tls: true }
|
|
91
99
|
});
|
|
92
|
-
await client.connect();
|
|
93
100
|
}
|
|
101
|
+
await client.connect();
|
|
94
102
|
return client;
|
|
95
103
|
}
|
|
96
104
|
|
|
@@ -122,10 +130,10 @@ var EventPublisherBase = class {
|
|
|
122
130
|
}
|
|
123
131
|
};
|
|
124
132
|
async function logRedisEvent(key) {
|
|
125
|
-
|
|
126
|
-
if (!redis) {
|
|
133
|
+
if (!process.env.RedisUrl || !process.env.RedisPassword) {
|
|
127
134
|
return;
|
|
128
135
|
}
|
|
136
|
+
const redis = await createRedisClient();
|
|
129
137
|
await redis.multi().hIncrBy(key, "count", 1).expire(key, 660).exec();
|
|
130
138
|
}
|
|
131
139
|
var DestinationError = class _DestinationError extends Error {
|
|
@@ -150,11 +158,11 @@ function logAggregatedMetric({
|
|
|
150
158
|
dimensions
|
|
151
159
|
}) {
|
|
152
160
|
const windowStart = Math.floor(Date.now() / 6e4) * 6e4;
|
|
153
|
-
|
|
161
|
+
let key = "tms:";
|
|
162
|
+
key += dimensions ? `${prefix}:${windowStart}:${dimensions}:${name}` : `${prefix}:${windowStart}:${name}`;
|
|
154
163
|
void logRedisEvent(key).catch((error) => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
164
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
165
|
+
logMessage(3, `Metric log error: ${message}`);
|
|
158
166
|
});
|
|
159
167
|
}
|
|
160
168
|
function logMetric(name, value, properties) {
|
|
@@ -174,15 +182,15 @@ function logMessage(level, message, properties) {
|
|
|
174
182
|
});
|
|
175
183
|
}
|
|
176
184
|
function logEvent(publisher2, event, region, status, payload, id) {
|
|
177
|
-
if (
|
|
178
|
-
const metricRegion = process.env.DisableMetricRegionLogging ? "default" : region;
|
|
185
|
+
if (process.env.DisableMetrics !== "true" && status >= 200 && status < 400) {
|
|
186
|
+
const metricRegion = process.env.DisableMetricRegionLogging === "true" ? "default" : region;
|
|
179
187
|
logAggregatedMetric({
|
|
180
188
|
prefix: "events",
|
|
181
189
|
dimensions: `${metricRegion}:${publisher2}:${event}`,
|
|
182
190
|
name: "Dispatch"
|
|
183
191
|
});
|
|
184
192
|
}
|
|
185
|
-
if (
|
|
193
|
+
if (process.env.DisableTraces !== "true") {
|
|
186
194
|
let properties = {
|
|
187
195
|
publisher: publisher2,
|
|
188
196
|
event,
|
|
@@ -197,14 +205,14 @@ function logEvent(publisher2, event, region, status, payload, id) {
|
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
207
|
function logException(exception, publisher2, errorType = "InternalError") {
|
|
200
|
-
if (
|
|
208
|
+
if (process.env.DisableMetrics !== "true") {
|
|
201
209
|
logAggregatedMetric({
|
|
202
210
|
prefix: "errors",
|
|
203
211
|
dimensions: publisher2 ?? "Other",
|
|
204
212
|
name: errorType
|
|
205
213
|
});
|
|
206
214
|
}
|
|
207
|
-
if (
|
|
215
|
+
if (process.env.DisableTraces !== "true") {
|
|
208
216
|
aiClient?.trackException({
|
|
209
217
|
exception,
|
|
210
218
|
properties: { publisher: publisher2, errorType }
|
|
@@ -628,19 +636,6 @@ async function scheduleEvent(message, queue, options) {
|
|
|
628
636
|
}
|
|
629
637
|
}
|
|
630
638
|
|
|
631
|
-
// src/utils/testUtils.ts
|
|
632
|
-
var testUtils_exports = {};
|
|
633
|
-
__export(testUtils_exports, {
|
|
634
|
-
context: () => context
|
|
635
|
-
});
|
|
636
|
-
var context = {};
|
|
637
|
-
context.log = function log(str) {
|
|
638
|
-
console.log(str);
|
|
639
|
-
};
|
|
640
|
-
context.log.warn = function warn(str) {
|
|
641
|
-
console.warn(str);
|
|
642
|
-
};
|
|
643
|
-
|
|
644
639
|
// src/defaultPublisher.ts
|
|
645
640
|
async function defaultPublisher(azureFunctionContext, serviceBusMessage, source, platformPublisher, trigger) {
|
|
646
641
|
if (serviceBusMessage.$schema === "mhub/pingtest") {
|
|
@@ -1239,6 +1234,19 @@ var universalAnalytics = {
|
|
|
1239
1234
|
}
|
|
1240
1235
|
};
|
|
1241
1236
|
|
|
1237
|
+
// src/utils/testUtils.ts
|
|
1238
|
+
var testUtils_exports = {};
|
|
1239
|
+
__export(testUtils_exports, {
|
|
1240
|
+
context: () => context
|
|
1241
|
+
});
|
|
1242
|
+
var context = {};
|
|
1243
|
+
context.log = function log(str) {
|
|
1244
|
+
console.log(str);
|
|
1245
|
+
};
|
|
1246
|
+
context.log.warn = function warn(str) {
|
|
1247
|
+
console.warn(str);
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1242
1250
|
// src/index.ts
|
|
1243
1251
|
var publisher = {
|
|
1244
1252
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
@@ -1256,7 +1264,7 @@ var publisher = {
|
|
|
1256
1264
|
0 && (module.exports = {
|
|
1257
1265
|
DefaultPublisher,
|
|
1258
1266
|
broker,
|
|
1259
|
-
|
|
1267
|
+
createRedisClient,
|
|
1260
1268
|
publisher,
|
|
1261
1269
|
testUtils,
|
|
1262
1270
|
utils
|