@shellicar/winston-azure-application-insights 6.0.4 → 6.0.5

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.
@@ -0,0 +1,454 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/private/ApplicationInsightsTransport.ts
5
+ var _winstontransport = require('winston-transport'); var _winstontransport2 = _interopRequireDefault(_winstontransport);
6
+
7
+ // src/public/enums.ts
8
+ var TelemetrySeverity = /* @__PURE__ */ ((TelemetrySeverity2) => {
9
+ TelemetrySeverity2["Verbose"] = "Verbose";
10
+ TelemetrySeverity2["Information"] = "Information";
11
+ TelemetrySeverity2["Warning"] = "Warning";
12
+ TelemetrySeverity2["Error"] = "Error";
13
+ TelemetrySeverity2["Critical"] = "Critical";
14
+ return TelemetrySeverity2;
15
+ })(TelemetrySeverity || {});
16
+ var ApplicationInsightsVersion = /* @__PURE__ */ ((ApplicationInsightsVersion2) => {
17
+ ApplicationInsightsVersion2["V2"] = "2.x";
18
+ ApplicationInsightsVersion2["V3"] = "3.x";
19
+ return ApplicationInsightsVersion2;
20
+ })(ApplicationInsightsVersion || {});
21
+
22
+ // src/private/consts.ts
23
+ var defaultSeverityMapping = {
24
+ error: "Error" /* Error */,
25
+ warn: "Warning" /* Warning */,
26
+ info: "Information" /* Information */,
27
+ verbose: "Verbose" /* Verbose */
28
+ };
29
+
30
+ // src/private/extractErrorsStep.ts
31
+ var _triplebeam = require('triple-beam');
32
+
33
+ // src/private/convertNullPrototypeToRegularObject.ts
34
+ var convertNullPrototypeToRegularObject = /* @__PURE__ */ __name((value) => {
35
+ if (value != null && typeof value === "object" && value.constructor === void 0) {
36
+ return { ...value };
37
+ }
38
+ return value;
39
+ }, "convertNullPrototypeToRegularObject");
40
+
41
+ // src/private/extractErrorsStep.ts
42
+ var extractErrorProperties = /* @__PURE__ */ __name((error, ...additionalIgnore) => {
43
+ const ignore = ["message", "name", "stack", ...additionalIgnore];
44
+ const properties = {};
45
+ for (const key of Object.keys(error)) {
46
+ if (!ignore.includes(key)) {
47
+ const value = error[key];
48
+ properties[key] = convertNullPrototypeToRegularObject(value);
49
+ }
50
+ }
51
+ return properties;
52
+ }, "extractErrorProperties");
53
+ var extractErrorsStep = /* @__PURE__ */ __name((info, isError2) => {
54
+ const exceptions = [];
55
+ if (isError2(info)) {
56
+ exceptions.push({
57
+ exception: info,
58
+ properties: extractErrorProperties(info, "level")
59
+ });
60
+ }
61
+ const splat = info[_triplebeam.SPLAT];
62
+ if (splat != null) {
63
+ for (const item of splat) {
64
+ if (isError2(item)) {
65
+ exceptions.push({
66
+ exception: item,
67
+ properties: extractErrorProperties(item)
68
+ });
69
+ }
70
+ }
71
+ }
72
+ return exceptions;
73
+ }, "extractErrorsStep");
74
+
75
+ // src/private/extractMessageStep.ts
76
+
77
+ var getMessageAsString = /* @__PURE__ */ __name((info) => {
78
+ let messageAsString = String(info.message);
79
+ const splat = _nullishCoalesce(info[_triplebeam.SPLAT], () => ( []));
80
+ const meta = splat[0];
81
+ if (_optionalChain([meta, 'optionalAccess', _ => _.message]) !== void 0) {
82
+ const expectedSuffix = ` ${meta.message}`;
83
+ if (messageAsString.endsWith(expectedSuffix)) {
84
+ messageAsString = messageAsString.slice(0, -expectedSuffix.length);
85
+ }
86
+ }
87
+ return { messageAsString, splat };
88
+ }, "getMessageAsString");
89
+ var extractMessageStepInternal = /* @__PURE__ */ __name((info) => {
90
+ const { messageAsString, splat } = getMessageAsString(info);
91
+ const strings = splat.filter((x) => typeof x === "string");
92
+ return [messageAsString, ...strings].join(" ");
93
+ }, "extractMessageStepInternal");
94
+ var extractMessageStep = /* @__PURE__ */ __name((info) => {
95
+ const result = extractMessageStepInternal(info);
96
+ return result;
97
+ }, "extractMessageStep");
98
+
99
+ // src/private/extractPropertiesStep.ts
100
+
101
+
102
+ // src/private/isPlainObject.ts
103
+ var isPlainObject = /* @__PURE__ */ __name((obj) => {
104
+ if (obj == null || typeof obj !== "object") {
105
+ return false;
106
+ }
107
+ const proto = Object.getPrototypeOf(obj);
108
+ return proto === Object.prototype || proto === null;
109
+ }, "isPlainObject");
110
+
111
+ // src/private/extractPropertiesStep.ts
112
+ var extractNonSymbolProps = /* @__PURE__ */ __name((obj) => {
113
+ const entries = Object.entries(obj);
114
+ if (entries.length === 0) {
115
+ return null;
116
+ }
117
+ const result = {};
118
+ for (const [key, value] of entries) {
119
+ result[key] = convertNullPrototypeToRegularObject(value);
120
+ }
121
+ return result;
122
+ }, "extractNonSymbolProps");
123
+ var extractDefaultMeta = /* @__PURE__ */ __name((info, isError2) => {
124
+ if (isError2(info)) {
125
+ const { level: level2, message: message2, ...rest2 } = info;
126
+ return extractNonSymbolProps(rest2);
127
+ }
128
+ const { level, name, message, stack, cause, ...rest } = info;
129
+ return extractNonSymbolProps(rest);
130
+ }, "extractDefaultMeta");
131
+ var extractPropertiesStep = /* @__PURE__ */ __name((info, isError2 = (x) => x instanceof Error) => {
132
+ const defaultMeta = extractDefaultMeta(info, isError2);
133
+ const splat = info[_triplebeam.SPLAT];
134
+ if (splat == null) {
135
+ return _nullishCoalesce(defaultMeta, () => ( {}));
136
+ }
137
+ const nonErrorItems = splat.filter((item) => !isError2(item));
138
+ const firstObject = nonErrorItems[0];
139
+ if (firstObject != null && isPlainObject(firstObject)) {
140
+ return { ...defaultMeta, ...firstObject };
141
+ }
142
+ return _nullishCoalesce(defaultMeta, () => ( {}));
143
+ }, "extractPropertiesStep");
144
+
145
+ // src/private/extractSeverityStep.ts
146
+ var extractSeverityStep = /* @__PURE__ */ __name((info, severityMapping, levels) => {
147
+ const directMapping = severityMapping[info.level];
148
+ if (directMapping != null) {
149
+ return directMapping;
150
+ }
151
+ if (levels != null) {
152
+ const currentPriority = levels[info.level];
153
+ if (currentPriority != null) {
154
+ const sortedLevels = Object.entries(levels).map((x) => ({ levelName: x[0], priority: x[1] })).filter((x) => currentPriority < x.priority).sort((a, b) => a.priority - b.priority);
155
+ for (const { levelName } of sortedLevels) {
156
+ const severity = severityMapping[levelName];
157
+ if (severity) {
158
+ return severity;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return "Verbose" /* Verbose */;
164
+ }, "extractSeverityStep");
165
+
166
+ // src/private/isError.ts
167
+ var isError = /* @__PURE__ */ __name((item) => item instanceof Error, "isError");
168
+
169
+ // src/private/ApplicationInsightsTransport.ts
170
+ var ApplicationInsightsTransport = class extends _winstontransport2.default {
171
+ static {
172
+ __name(this, "ApplicationInsightsTransport");
173
+ }
174
+
175
+
176
+
177
+ constructor(options) {
178
+ super({
179
+ level: options.level
180
+ });
181
+ this.options = {
182
+ telemetryHandler: options.telemetryHandler,
183
+ severityMapping: _nullishCoalesce(options.severityMapping, () => ( defaultSeverityMapping)),
184
+ isError: _nullishCoalesce(options.isError, () => ( isError)),
185
+ traceFilter: _nullishCoalesce(options.traceFilter, () => ( (() => true))),
186
+ exceptionFilter: _nullishCoalesce(options.exceptionFilter, () => ( (() => true)))
187
+ };
188
+ this.telemetryHandler = options.telemetryHandler;
189
+ }
190
+ log(info, next) {
191
+ const exceptions = this.getExceptions(info);
192
+ const trace = this.getTrace(info, exceptions);
193
+ this.telemetryHandler.handleTelemetry({
194
+ trace,
195
+ exceptions
196
+ });
197
+ next();
198
+ }
199
+ getTrace(info, filteredExceptions) {
200
+ const trace = this.extractTrace(info, filteredExceptions);
201
+ if (trace != null && this.options.traceFilter(trace)) {
202
+ return trace;
203
+ }
204
+ return null;
205
+ }
206
+ getExceptions(info) {
207
+ const exceptions = extractErrorsStep(info, this.options.isError);
208
+ const filtered = exceptions.filter(this.options.exceptionFilter);
209
+ return filtered;
210
+ }
211
+ extractTrace(info, errors) {
212
+ const shouldSendOnlyException = errors.length > 0 && this.options.isError(info);
213
+ if (shouldSendOnlyException) {
214
+ return null;
215
+ }
216
+ const message = extractMessageStep(info);
217
+ const properties = extractPropertiesStep(info, this.options.isError);
218
+ const severity = extractSeverityStep(info, this.options.severityMapping, this.levels);
219
+ return {
220
+ message,
221
+ properties,
222
+ severity
223
+ };
224
+ }
225
+ };
226
+
227
+ // src/private/ApplicationInsightsV2TelemetryHandler.ts
228
+ var ApplicationInsightsV2TelemetryHandler = (_class = class {
229
+ static {
230
+ __name(this, "ApplicationInsightsV2TelemetryHandler");
231
+ }
232
+
233
+ __init() {this.severityMapping = {
234
+ ["Verbose" /* Verbose */]: 0 /* Verbose */,
235
+ ["Information" /* Information */]: 1 /* Information */,
236
+ ["Warning" /* Warning */]: 2 /* Warning */,
237
+ ["Error" /* Error */]: 3 /* Error */,
238
+ ["Critical" /* Critical */]: 4 /* Critical */
239
+ }}
240
+ constructor(options) {;_class.prototype.__init.call(this);
241
+ this.client = options.client;
242
+ }
243
+ handleTelemetry(telemetry) {
244
+ if (telemetry.trace != null) {
245
+ const trace = {
246
+ message: telemetry.trace.message,
247
+ severity: this.mapSeverity(telemetry.trace.severity),
248
+ properties: telemetry.trace.properties
249
+ };
250
+ this.client.trackTrace(trace);
251
+ }
252
+ for (const error of telemetry.exceptions) {
253
+ const exceptionTelemetry = {
254
+ exception: error.exception,
255
+ properties: error.properties
256
+ };
257
+ this.client.trackException(exceptionTelemetry);
258
+ }
259
+ }
260
+ mapSeverity(severity) {
261
+ return this.severityMapping[severity];
262
+ }
263
+ }, _class);
264
+
265
+ // src/private/ApplicationInsightsV3TelemetryHandler.ts
266
+ var _applicationinsightsv3 = require('applicationinsightsv3');
267
+ var ApplicationInsightsV3TelemetryHandler = (_class2 = class {
268
+ static {
269
+ __name(this, "ApplicationInsightsV3TelemetryHandler");
270
+ }
271
+
272
+ __init2() {this.severityMapping = {
273
+ ["Verbose" /* Verbose */]: _applicationinsightsv3.KnownSeverityLevel.Verbose,
274
+ ["Information" /* Information */]: _applicationinsightsv3.KnownSeverityLevel.Information,
275
+ ["Warning" /* Warning */]: _applicationinsightsv3.KnownSeverityLevel.Warning,
276
+ ["Error" /* Error */]: _applicationinsightsv3.KnownSeverityLevel.Error,
277
+ ["Critical" /* Critical */]: _applicationinsightsv3.KnownSeverityLevel.Critical
278
+ }}
279
+ constructor(options) {;_class2.prototype.__init2.call(this);
280
+ this.client = options.client;
281
+ }
282
+ handleTelemetry(telemetry) {
283
+ if (telemetry.trace != null) {
284
+ const trace = {
285
+ message: telemetry.trace.message,
286
+ severity: this.mapSeverity(telemetry.trace.severity),
287
+ properties: telemetry.trace.properties
288
+ };
289
+ this.client.trackTrace(trace);
290
+ }
291
+ for (const error of telemetry.exceptions) {
292
+ const exceptionTelemetry = {
293
+ exception: error.exception,
294
+ properties: error.properties
295
+ };
296
+ this.client.trackException(exceptionTelemetry);
297
+ }
298
+ }
299
+ mapSeverity(severity) {
300
+ return this.severityMapping[severity];
301
+ }
302
+ }, _class2);
303
+
304
+ // src/public/createTelemetryHandler.ts
305
+ var createTelemetryHandler = /* @__PURE__ */ __name((options) => {
306
+ switch (options.version) {
307
+ case "2.x" /* V2 */: {
308
+ return new ApplicationInsightsV2TelemetryHandler({
309
+ client: options.client
310
+ });
311
+ }
312
+ case "3.x" /* V3 */: {
313
+ return new ApplicationInsightsV3TelemetryHandler({
314
+ client: options.client
315
+ });
316
+ }
317
+ default: {
318
+ return options.telemetryHandler;
319
+ }
320
+ }
321
+ }, "createTelemetryHandler");
322
+
323
+ // src/public/createApplicationInsightsTransport.ts
324
+ var createApplicationInsightsTransport = /* @__PURE__ */ __name((options) => {
325
+ const telemetryHandler = createTelemetryHandler(options);
326
+ const transport = new ApplicationInsightsTransport({
327
+ telemetryHandler,
328
+ severityMapping: options.severityMapping,
329
+ exceptionFilter: options.exceptionFilter,
330
+ traceFilter: options.traceFilter,
331
+ isError: options.isError,
332
+ level: options.level
333
+ });
334
+ return transport;
335
+ }, "createApplicationInsightsTransport");
336
+
337
+ // src/public/createWinstonLogger.ts
338
+ var _winston = require('winston'); var _winston2 = _interopRequireDefault(_winston);
339
+
340
+ // src/private/createWinstonFormat.ts
341
+
342
+
343
+ var unescapeColorCodes = /* @__PURE__ */ __name((info) => {
344
+ const message = info[_triplebeam.MESSAGE];
345
+ return message.replaceAll(/\\u001b/g, "\x1B");
346
+ }, "unescapeColorCodes");
347
+ var unescapeColorCodesFormat = /* @__PURE__ */ __name(() => _winston2.default.format.printf(unescapeColorCodes), "unescapeColorCodesFormat");
348
+ var createWinstonFormat = /* @__PURE__ */ __name((config) => {
349
+ if (Array.isArray(config)) {
350
+ return _winston2.default.format.combine(...config);
351
+ }
352
+ const formats = [];
353
+ if (config.timestamp === true) {
354
+ formats.push(_winston2.default.format.timestamp());
355
+ } else if (typeof config.timestamp === "object") {
356
+ formats.push(_winston2.default.format.timestamp(config.timestamp));
357
+ }
358
+ if (config.errors === true) {
359
+ formats.push(_winston2.default.format.errors({ stack: true }));
360
+ } else if (typeof config.errors === "object") {
361
+ formats.push(_winston2.default.format.errors(config.errors));
362
+ }
363
+ if (config.colorize === true) {
364
+ formats.push(_winston2.default.format.colorize({ all: true }));
365
+ } else if (typeof config.colorize === "object") {
366
+ formats.push(_winston2.default.format.colorize(config.colorize));
367
+ }
368
+ if (config.output === "simple") {
369
+ formats.push(_winston2.default.format.simple());
370
+ }
371
+ if (config.output === "json") {
372
+ formats.push(_winston2.default.format.json());
373
+ if (config.colorize === true || typeof config.colorize === "object") {
374
+ formats.push(unescapeColorCodesFormat());
375
+ }
376
+ }
377
+ return _winston2.default.format.combine(...formats);
378
+ }, "createWinstonFormat");
379
+
380
+ // src/public/isRunningInAzure.ts
381
+ var _nodeprocess = require('node:process');
382
+ var isRunningInAzure = /* @__PURE__ */ __name(() => {
383
+ return _nodeprocess.env.WEBSITE_INSTANCE_ID !== void 0;
384
+ }, "isRunningInAzure");
385
+
386
+ // src/public/isRunningLocally.ts
387
+ var isRunningLocally = /* @__PURE__ */ __name(() => {
388
+ return !isRunningInAzure();
389
+ }, "isRunningLocally");
390
+
391
+ // src/public/createWinstonLogger.ts
392
+ var createWinstonLogger = /* @__PURE__ */ __name((options) => {
393
+ const { severityMapping, exceptionFilter, traceFilter, isError: isError2, ...rest } = options.insights;
394
+ const telemetryHandler = createTelemetryHandler(rest);
395
+ const transports = [];
396
+ const consoleEnabled = _nullishCoalesce(_optionalChain([options, 'access', _2 => _2.winston, 'optionalAccess', _3 => _3.console, 'optionalAccess', _4 => _4.enabled]), () => ( isRunningLocally()));
397
+ if (consoleEnabled) {
398
+ let consoleFormatConfig;
399
+ if (Array.isArray(_optionalChain([options, 'access', _5 => _5.winston, 'optionalAccess', _6 => _6.console, 'optionalAccess', _7 => _7.format]))) {
400
+ consoleFormatConfig = options.winston.console.format;
401
+ } else {
402
+ const userFormat = _nullishCoalesce(_optionalChain([options, 'access', _8 => _8.winston, 'optionalAccess', _9 => _9.console, 'optionalAccess', _10 => _10.format]), () => ( {}));
403
+ consoleFormatConfig = {
404
+ output: _nullishCoalesce(userFormat.output, () => ( "json")),
405
+ timestamp: _nullishCoalesce(userFormat.timestamp, () => ( true)),
406
+ errors: _nullishCoalesce(userFormat.errors, () => ( { stack: true })),
407
+ colorize: _nullishCoalesce(userFormat.colorize, () => ( true))
408
+ };
409
+ }
410
+ const consoleFormat = createWinstonFormat(consoleFormatConfig);
411
+ transports.push(
412
+ new _winston2.default.transports.Console({
413
+ format: consoleFormat,
414
+ level: _optionalChain([options, 'access', _11 => _11.winston, 'optionalAccess', _12 => _12.console, 'optionalAccess', _13 => _13.level]),
415
+ stderrLevels: ["error", "crit", "alert", "emerg"],
416
+ consoleWarnLevels: ["warn", "warning"]
417
+ })
418
+ );
419
+ }
420
+ const insightsEnabled = _nullishCoalesce(_optionalChain([options, 'access', _14 => _14.winston, 'optionalAccess', _15 => _15.insights, 'optionalAccess', _16 => _16.enabled]), () => ( true));
421
+ if (insightsEnabled) {
422
+ const transport = createApplicationInsightsTransport({
423
+ telemetryHandler,
424
+ severityMapping,
425
+ exceptionFilter,
426
+ traceFilter,
427
+ isError: isError2,
428
+ level: _optionalChain([options, 'access', _17 => _17.winston, 'optionalAccess', _18 => _18.insights, 'optionalAccess', _19 => _19.level])
429
+ });
430
+ transports.push(transport);
431
+ }
432
+ const level = _nullishCoalesce(_optionalChain([options, 'access', _20 => _20.winston, 'optionalAccess', _21 => _21.defaults, 'optionalAccess', _22 => _22.level]), () => ( "info"));
433
+ const levels = _nullishCoalesce(_optionalChain([options, 'access', _23 => _23.winston, 'optionalAccess', _24 => _24.levels]), () => ( _winston2.default.config.npm.levels));
434
+ const globalFormats = _nullishCoalesce(_optionalChain([options, 'access', _25 => _25.winston, 'optionalAccess', _26 => _26.defaults, 'optionalAccess', _27 => _27.format]), () => ( []));
435
+ const format = _winston2.default.format.combine(...globalFormats);
436
+ return _winston2.default.createLogger({
437
+ ..._optionalChain([options, 'access', _28 => _28.winston, 'optionalAccess', _29 => _29.options]),
438
+ level,
439
+ levels,
440
+ format,
441
+ transports,
442
+ defaultMeta: _optionalChain([options, 'access', _30 => _30.winston, 'optionalAccess', _31 => _31.defaults, 'optionalAccess', _32 => _32.defaultMeta])
443
+ });
444
+ }, "createWinstonLogger");
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+ exports.ApplicationInsightsVersion = ApplicationInsightsVersion; exports.TelemetrySeverity = TelemetrySeverity; exports.createApplicationInsightsTransport = createApplicationInsightsTransport; exports.createTelemetryHandler = createTelemetryHandler; exports.createWinstonLogger = createWinstonLogger; exports.isRunningInAzure = isRunningInAzure; exports.isRunningLocally = isRunningLocally;
454
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/ecosystem/ecosystem/packages/winston-azure-application-insights/dist/cjs/index.cjs","../../src/private/ApplicationInsightsTransport.ts","../../src/public/enums.ts","../../src/private/consts.ts","../../src/private/extractErrorsStep.ts","../../src/private/convertNullPrototypeToRegularObject.ts","../../src/private/extractMessageStep.ts","../../src/private/extractPropertiesStep.ts","../../src/private/isPlainObject.ts","../../src/private/extractSeverityStep.ts","../../src/private/isError.ts","../../src/private/ApplicationInsightsV2TelemetryHandler.ts","../../src/private/ApplicationInsightsV3TelemetryHandler.ts","../../src/public/createTelemetryHandler.ts","../../src/public/createApplicationInsightsTransport.ts","../../src/public/createWinstonLogger.ts","../../src/private/createWinstonFormat.ts","../../src/public/isRunningInAzure.ts","../../src/public/isRunningLocally.ts"],"names":["TelemetrySeverity","ApplicationInsightsVersion","isError","SPLAT","message","winston"],"mappings":"AAAA,8yBAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,OAAO,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;AACxF;AACA;ACHA,yHAA4B;ADK5B;AACA;AENO,IAAK,kBAAA,kBAAL,CAAA,CAAKA,kBAAAA,EAAAA,GAAL;AACL,EAAAA,kBAAAA,CAAA,SAAA,EAAA,EAAU,SAAA;AACV,EAAAA,kBAAAA,CAAA,aAAA,EAAA,EAAc,aAAA;AACd,EAAAA,kBAAAA,CAAA,SAAA,EAAA,EAAU,SAAA;AACV,EAAAA,kBAAAA,CAAA,OAAA,EAAA,EAAQ,OAAA;AACR,EAAAA,kBAAAA,CAAA,UAAA,EAAA,EAAW,UAAA;AALD,EAAA,OAAAA,kBAAAA;AAAA,CAAA,CAAA,CAAA,kBAAA,GAAA,CAAA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IAAA;AACF,EAAA;AAGyC,EAAA;AACpB,EAAA;AACD,IAAA;AAChB,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACAF,MAAAA;AACkC,MAAA;AACnC,IAAA;AACwB,IAAA;AAC3B,EAAA;AAGyC,EAAA;AACCG,EAAAA;AACH,EAAA;AAEE,EAAA;AAEb,EAAA;AACN,IAAA;AACpB,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACwC,IAAA;AACzC,EAAA;AA/DgC;AfobS;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/ecosystem/ecosystem/packages/winston-azure-application-insights/dist/cjs/index.cjs","sourcesContent":[null,"import TransportStream from 'winston-transport';\nimport type { TelemetryDataException, TelemetryHandler, WinstonLevels } from '../public/types';\nimport { defaultSeverityMapping } from './consts';\nimport { extractErrorsStep } from './extractErrorsStep';\nimport { extractMessageStep } from './extractMessageStep';\nimport { extractPropertiesStep } from './extractPropertiesStep';\nimport { extractSeverityStep } from './extractSeverityStep';\nimport { isError } from './isError';\nimport type { ApplicationInsightsTransportOptions, RequiredOptions, WinstonInfo } from './types';\n\nexport class ApplicationInsightsTransport extends TransportStream {\n private readonly telemetryHandler: TelemetryHandler;\n private readonly options: RequiredOptions;\n\n public levels?: WinstonLevels;\n\n constructor(options: ApplicationInsightsTransportOptions) {\n super({\n level: options.level,\n });\n this.options = {\n telemetryHandler: options.telemetryHandler,\n severityMapping: options.severityMapping ?? defaultSeverityMapping,\n isError: options.isError ?? isError,\n traceFilter: options.traceFilter ?? (() => true),\n exceptionFilter: options.exceptionFilter ?? (() => true),\n };\n this.telemetryHandler = options.telemetryHandler;\n }\n\n public override log(info: WinstonInfo, next: () => void) {\n const exceptions = this.getExceptions(info);\n const trace = this.getTrace(info, exceptions);\n\n this.telemetryHandler.handleTelemetry({\n trace,\n exceptions,\n });\n\n next();\n }\n\n private getTrace(info: WinstonInfo, filteredExceptions: TelemetryDataException[]) {\n const trace = this.extractTrace(info, filteredExceptions);\n if (trace != null && this.options.traceFilter(trace)) {\n return trace;\n }\n return null;\n }\n\n private getExceptions(info: WinstonInfo) {\n const exceptions = extractErrorsStep(info, this.options.isError);\n const filtered = exceptions.filter(this.options.exceptionFilter);\n return filtered;\n }\n\n private extractTrace(info: WinstonInfo, errors: TelemetryDataException[]) {\n const shouldSendOnlyException = errors.length > 0 && this.options.isError(info);\n\n if (shouldSendOnlyException) {\n return null;\n }\n\n const message = extractMessageStep(info);\n const properties = extractPropertiesStep(info, this.options.isError);\n const severity = extractSeverityStep(info, this.options.severityMapping, this.levels);\n\n return {\n message: message,\n properties,\n severity,\n };\n }\n}\n","export enum TelemetrySeverity {\n Verbose = 'Verbose',\n Information = 'Information',\n Warning = 'Warning',\n Error = 'Error',\n Critical = 'Critical',\n}\n\nexport enum ApplicationInsightsVersion {\n V2 = '2.x',\n V3 = '3.x',\n}\n","import { TelemetrySeverity } from '../public/enums';\nimport type { SeverityMapping } from '../public/types';\n\nexport const defaultSeverityMapping: SeverityMapping = {\n error: TelemetrySeverity.Error,\n warn: TelemetrySeverity.Warning,\n info: TelemetrySeverity.Information,\n verbose: TelemetrySeverity.Verbose,\n};\n","import { SPLAT } from 'triple-beam';\nimport type { IsError, TelemetryDataException } from '../public/types';\nimport { convertNullPrototypeToRegularObject } from './convertNullPrototypeToRegularObject';\nimport type { WinstonInfo } from './types';\n\nconst extractErrorProperties = (error: Error, ...additionalIgnore: string[]): Record<string, unknown> => {\n const ignore = ['message', 'name', 'stack', ...additionalIgnore];\n const properties: Record<string, unknown> = {};\n for (const key of Object.keys(error) as (keyof Error)[]) {\n if (!ignore.includes(key)) {\n const value = error[key];\n properties[key] = convertNullPrototypeToRegularObject(value);\n }\n }\n return properties;\n};\n\nexport const extractErrorsStep = (info: WinstonInfo, isError: IsError): TelemetryDataException[] => {\n const exceptions: TelemetryDataException[] = [];\n\n if (isError(info)) {\n exceptions.push({\n exception: info,\n properties: extractErrorProperties(info, 'level'),\n });\n }\n\n const splat = info[SPLAT];\n if (splat != null) {\n for (const item of splat) {\n if (isError(item)) {\n exceptions.push({\n exception: item,\n properties: extractErrorProperties(item),\n });\n }\n }\n }\n\n return exceptions;\n};\n","/**\n * Ensures that the object returned has a constructor to avoid a {@link TypeError} from the `applicationinsights` library.\n * @param value\n * @returns\n */\nexport const convertNullPrototypeToRegularObject = (value: unknown): unknown => {\n if (value != null && typeof value === 'object' && value.constructor === undefined) {\n return { ...value };\n }\n return value;\n};\n","import { SPLAT } from 'triple-beam';\nimport type { WinstonInfo } from './types';\n\nconst getMessageAsString = (info: WinstonInfo) => {\n let messageAsString = String(info.message);\n const splat = info[SPLAT] ?? [];\n const meta = splat[0] as { message?: unknown };\n\n if (meta?.message !== undefined) {\n const expectedSuffix = ` ${meta.message}`;\n if (messageAsString.endsWith(expectedSuffix)) {\n messageAsString = messageAsString.slice(0, -expectedSuffix.length);\n }\n }\n\n return { messageAsString, splat };\n};\n\nconst extractMessageStepInternal = (info: WinstonInfo): string => {\n const { messageAsString, splat } = getMessageAsString(info);\n const strings = splat.filter((x) => typeof x === 'string');\n return [messageAsString, ...strings].join(' ');\n};\n\nexport const extractMessageStep = (info: WinstonInfo): string => {\n const result = extractMessageStepInternal(info);\n return result;\n};\n","import { SPLAT } from 'triple-beam';\nimport type { IsError, TelemetryDataProperties } from '../public/types';\nimport { convertNullPrototypeToRegularObject } from './convertNullPrototypeToRegularObject';\nimport { isPlainObject } from './isPlainObject';\nimport type { WinstonInfo } from './types';\n\nconst extractNonSymbolProps = (obj: Record<string | symbol, unknown>): Record<string, unknown> | null => {\n const entries = Object.entries(obj);\n if (entries.length === 0) {\n return null;\n }\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of entries) {\n result[key] = convertNullPrototypeToRegularObject(value);\n }\n return result;\n};\n\nconst extractDefaultMeta = (info: WinstonInfo, isError: IsError): Record<string, unknown> | null => {\n if (isError(info)) {\n const { level, message, ...rest } = info;\n return extractNonSymbolProps(rest);\n }\n const { level, name, message, stack, cause, ...rest } = info;\n return extractNonSymbolProps(rest);\n};\n\nexport const extractPropertiesStep = (info: WinstonInfo, isError: IsError = (x) => x instanceof Error): TelemetryDataProperties => {\n const defaultMeta = extractDefaultMeta(info, isError);\n\n const splat = info[SPLAT];\n if (splat == null) {\n return defaultMeta ?? {};\n }\n\n const nonErrorItems = splat.filter((item) => !isError(item));\n const firstObject = nonErrorItems[0];\n if (firstObject != null && isPlainObject(firstObject)) {\n return { ...defaultMeta, ...firstObject };\n }\n return defaultMeta ?? {};\n};\n","export const isPlainObject = (obj: unknown): obj is Record<string, unknown> => {\n if (obj == null || typeof obj !== 'object') {\n return false;\n }\n const proto = Object.getPrototypeOf(obj);\n return proto === Object.prototype || proto === null;\n};\n","import { TelemetrySeverity } from '../public/enums';\nimport type { SeverityMapping, WinstonLevels } from '../public/types';\nimport type { WinstonInfo } from './types';\n\nexport const extractSeverityStep = (info: WinstonInfo, severityMapping: SeverityMapping, levels?: WinstonLevels): TelemetrySeverity => {\n const directMapping = severityMapping[info.level];\n if (directMapping != null) {\n return directMapping;\n }\n\n if (levels != null) {\n const currentPriority = levels[info.level];\n\n if (currentPriority != null) {\n const sortedLevels = Object.entries(levels)\n .map((x) => ({ levelName: x[0], priority: x[1] }))\n .filter((x) => currentPriority < x.priority)\n .sort((a, b) => a.priority - b.priority);\n\n for (const { levelName } of sortedLevels) {\n const severity = severityMapping[levelName];\n if (severity) {\n return severity;\n }\n }\n }\n }\n\n return TelemetrySeverity.Verbose;\n};\n","export const isError = (item: unknown): item is Error => item instanceof Error;\n","import type { ExceptionTelemetry, TraceTelemetry } from 'applicationinsightsv2/out/Declarations/Contracts';\nimport { TelemetrySeverity } from '../public/enums';\nimport type { ITelemetryClientV2 } from '../public/ITelemetryClientV2';\nimport type { TelemetryData, TelemetryHandler } from '../public/types';\n\n// From application insights\n// Declare locally to avoid importing the library\nenum SeverityLevel {\n Verbose = 0,\n Information = 1,\n Warning = 2,\n Error = 3,\n Critical = 4,\n}\n\nexport interface ApplicationInsightsV2TelemetryHandlerOptions {\n client: ITelemetryClientV2;\n}\n\nexport class ApplicationInsightsV2TelemetryHandler implements TelemetryHandler {\n private readonly client: ITelemetryClientV2;\n private readonly severityMapping: Record<TelemetrySeverity, SeverityLevel> = {\n [TelemetrySeverity.Verbose]: SeverityLevel.Verbose,\n [TelemetrySeverity.Information]: SeverityLevel.Information,\n [TelemetrySeverity.Warning]: SeverityLevel.Warning,\n [TelemetrySeverity.Error]: SeverityLevel.Error,\n [TelemetrySeverity.Critical]: SeverityLevel.Critical,\n };\n\n constructor(options: ApplicationInsightsV2TelemetryHandlerOptions) {\n this.client = options.client;\n }\n\n public handleTelemetry(telemetry: TelemetryData): void {\n if (telemetry.trace != null) {\n const trace: TraceTelemetry = {\n message: telemetry.trace.message,\n severity: this.mapSeverity(telemetry.trace.severity),\n properties: telemetry.trace.properties,\n };\n this.client.trackTrace(trace);\n }\n\n for (const error of telemetry.exceptions) {\n const exceptionTelemetry = {\n exception: error.exception,\n properties: error.properties,\n } satisfies ExceptionTelemetry;\n\n this.client.trackException(exceptionTelemetry);\n }\n }\n\n private mapSeverity(severity: TelemetrySeverity): SeverityLevel {\n return this.severityMapping[severity];\n }\n}\n","import type { ExceptionTelemetry, TraceTelemetry } from 'applicationinsightsv3';\nimport { KnownSeverityLevel } from 'applicationinsightsv3';\nimport { TelemetrySeverity } from '../public/enums';\nimport type { ITelemetryClientV3 } from '../public/ITelemetryClientV3';\nimport type { TelemetryData, TelemetryHandler } from '../public/types';\n\nexport interface ApplicationInsightsV3TelemetryHandlerOptions {\n client: ITelemetryClientV3;\n}\n\nexport class ApplicationInsightsV3TelemetryHandler implements TelemetryHandler {\n private readonly client: ITelemetryClientV3;\n private readonly severityMapping: Record<TelemetrySeverity, KnownSeverityLevel> = {\n [TelemetrySeverity.Verbose]: KnownSeverityLevel.Verbose,\n [TelemetrySeverity.Information]: KnownSeverityLevel.Information,\n [TelemetrySeverity.Warning]: KnownSeverityLevel.Warning,\n [TelemetrySeverity.Error]: KnownSeverityLevel.Error,\n [TelemetrySeverity.Critical]: KnownSeverityLevel.Critical,\n };\n\n constructor(options: ApplicationInsightsV3TelemetryHandlerOptions) {\n this.client = options.client;\n }\n\n public handleTelemetry(telemetry: TelemetryData): void {\n if (telemetry.trace != null) {\n const trace: TraceTelemetry = {\n message: telemetry.trace.message,\n severity: this.mapSeverity(telemetry.trace.severity),\n properties: telemetry.trace.properties,\n };\n this.client.trackTrace(trace);\n }\n\n for (const error of telemetry.exceptions) {\n const exceptionTelemetry = {\n exception: error.exception,\n properties: error.properties,\n } satisfies ExceptionTelemetry;\n\n this.client.trackException(exceptionTelemetry);\n }\n }\n\n private mapSeverity(severity: TelemetrySeverity): KnownSeverityLevel {\n return this.severityMapping[severity];\n }\n}\n","import { ApplicationInsightsV2TelemetryHandler } from '../private/ApplicationInsightsV2TelemetryHandler';\nimport { ApplicationInsightsV3TelemetryHandler } from '../private/ApplicationInsightsV3TelemetryHandler';\nimport { ApplicationInsightsVersion } from './enums';\nimport type { CreateTelemetryHandlerOptions, TelemetryHandler } from './types';\n\nexport const createTelemetryHandler = (options: CreateTelemetryHandlerOptions): TelemetryHandler => {\n switch (options.version) {\n case ApplicationInsightsVersion.V2: {\n return new ApplicationInsightsV2TelemetryHandler({\n client: options.client,\n });\n }\n case ApplicationInsightsVersion.V3: {\n return new ApplicationInsightsV3TelemetryHandler({\n client: options.client,\n });\n }\n default: {\n return options.telemetryHandler;\n }\n }\n};\n","import type TransportStream from 'winston-transport';\nimport { ApplicationInsightsTransport } from '../private/ApplicationInsightsTransport';\nimport { createTelemetryHandler } from './createTelemetryHandler';\nimport type { CreateApplicationInsightsTransportOptions } from './types';\n\nexport const createApplicationInsightsTransport = (options: CreateApplicationInsightsTransportOptions): TransportStream => {\n const telemetryHandler = createTelemetryHandler(options);\n\n const transport = new ApplicationInsightsTransport({\n telemetryHandler,\n severityMapping: options.severityMapping,\n exceptionFilter: options.exceptionFilter,\n traceFilter: options.traceFilter,\n isError: options.isError,\n level: options.level,\n });\n\n return transport;\n};\n","import winston from 'winston';\nimport type TransportStream from 'winston-transport';\nimport { type CreateWinstonFormatOptions, createWinstonFormat } from '../private/createWinstonFormat';\nimport { createApplicationInsightsTransport } from './createApplicationInsightsTransport';\nimport { createTelemetryHandler } from './createTelemetryHandler';\nimport { isRunningLocally } from './isRunningLocally';\nimport type { CreateWinstonLoggerOptions } from './types';\n\nexport const createWinstonLogger = (options: CreateWinstonLoggerOptions): winston.Logger => {\n const { severityMapping, exceptionFilter, traceFilter, isError, ...rest } = options.insights;\n\n const telemetryHandler = createTelemetryHandler(rest);\n\n const transports: TransportStream[] = [];\n\n const consoleEnabled = options.winston?.console?.enabled ?? isRunningLocally();\n if (consoleEnabled) {\n let consoleFormatConfig: CreateWinstonFormatOptions | undefined;\n\n if (Array.isArray(options.winston?.console?.format)) {\n consoleFormatConfig = options.winston.console.format;\n } else {\n const userFormat = options.winston?.console?.format ?? {};\n consoleFormatConfig = {\n output: userFormat.output ?? 'json',\n timestamp: userFormat.timestamp ?? true,\n errors: userFormat.errors ?? { stack: true },\n colorize: userFormat.colorize ?? true,\n };\n }\n\n const consoleFormat = createWinstonFormat(consoleFormatConfig);\n\n transports.push(\n new winston.transports.Console({\n format: consoleFormat,\n level: options.winston?.console?.level,\n stderrLevels: ['error', 'crit', 'alert', 'emerg'],\n consoleWarnLevels: ['warn', 'warning'],\n }),\n );\n }\n\n // Insights transport\n const insightsEnabled = options.winston?.insights?.enabled ?? true;\n if (insightsEnabled) {\n const transport = createApplicationInsightsTransport({\n telemetryHandler,\n severityMapping,\n exceptionFilter,\n traceFilter,\n isError,\n level: options.winston?.insights?.level,\n });\n transports.push(transport);\n }\n\n // Merge defaults with logger-level options\n const level = options.winston?.defaults?.level ?? 'info';\n const levels = options.winston?.levels ?? winston.config.npm.levels;\n const globalFormats = options.winston?.defaults?.format ?? [];\n\n const format = winston.format.combine(...globalFormats);\n\n return winston.createLogger({\n ...options.winston?.options,\n level,\n levels,\n format,\n transports,\n defaultMeta: options.winston?.defaults?.defaultMeta,\n });\n};\n","import type { ColorizeOptions, Format, TimestampOptions, TransformableInfo } from 'logform';\nimport { MESSAGE } from 'triple-beam';\nimport winston from 'winston';\n\n/**\n * Converts escaped ANSI color codes back to actual ANSI escape sequences.\n * Specifically converts `\\\\u001b` (escaped) to `\\u001b` (ESC character, ^[ or 0x1B).\n * @see https://github.com/winstonjs/logform#colorize\n */\nconst unescapeColorCodes = (info: TransformableInfo) => {\n const message = info[MESSAGE] as string;\n return message.replaceAll(/\\\\u001b/g, '\\u001b');\n};\n\nconst unescapeColorCodesFormat = () => winston.format.printf(unescapeColorCodes);\n\nexport type CreateWinstonFormatOptions =\n | Format[]\n | {\n output: 'json' | 'simple';\n errors: boolean | { stack?: boolean };\n timestamp: boolean | TimestampOptions;\n colorize: boolean | ColorizeOptions;\n };\n\nexport const createWinstonFormat = (config: CreateWinstonFormatOptions): Format => {\n if (Array.isArray(config)) {\n return winston.format.combine(...config);\n }\n\n const formats: Format[] = [];\n\n if (config.timestamp === true) {\n formats.push(winston.format.timestamp());\n } else if (typeof config.timestamp === 'object') {\n formats.push(winston.format.timestamp(config.timestamp));\n }\n\n if (config.errors === true) {\n formats.push(winston.format.errors({ stack: true }));\n } else if (typeof config.errors === 'object') {\n formats.push(winston.format.errors(config.errors));\n }\n\n if (config.colorize === true) {\n formats.push(winston.format.colorize({ all: true }));\n } else if (typeof config.colorize === 'object') {\n formats.push(winston.format.colorize(config.colorize));\n }\n\n if (config.output === 'simple') {\n formats.push(winston.format.simple());\n }\n if (config.output === 'json') {\n formats.push(winston.format.json());\n\n if (config.colorize === true || typeof config.colorize === 'object') {\n formats.push(unescapeColorCodesFormat());\n }\n }\n\n return winston.format.combine(...formats);\n};\n","import { env } from 'node:process';\n\nexport const isRunningInAzure = () => {\n return env.WEBSITE_INSTANCE_ID !== undefined;\n};\n","import { isRunningInAzure } from './isRunningInAzure';\n\nexport const isRunningLocally = () => {\n return !isRunningInAzure();\n};\n"]}