@shellicar/winston-azure-application-insights 5.0.1 → 5.0.2
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.d.mts +43 -0
- package/dist/index.d.ts +26 -11
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -7
- package/dist/index.cjs +0 -69
- package/dist/index.cjs.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as winston from 'winston';
|
|
2
|
+
import { Format } from 'logform';
|
|
3
|
+
import TransportStream from 'winston-transport';
|
|
4
|
+
import { TraceTelemetry as TraceTelemetry$1 } from 'applicationinsightsv2/out/Declarations/Contracts';
|
|
5
|
+
import { TelemetryClient as TelemetryClient$1 } from 'applicationinsightsv2';
|
|
6
|
+
import { TraceTelemetry, TelemetryClient, ExceptionTelemetry } from 'applicationinsightsv3';
|
|
7
|
+
|
|
8
|
+
type PlainObject = Record<string, any>;
|
|
9
|
+
type AzureInsightsClientOptions = {
|
|
10
|
+
version: 2;
|
|
11
|
+
client: TelemetryClient$1;
|
|
12
|
+
filters?: ITelemetryFilterV2[];
|
|
13
|
+
} | {
|
|
14
|
+
version: 3;
|
|
15
|
+
client: TelemetryClient;
|
|
16
|
+
filters?: ITelemetryFilterV3[];
|
|
17
|
+
};
|
|
18
|
+
declare abstract class ITelemetryFilterV3 {
|
|
19
|
+
filterTrace(trace: TraceTelemetry, client: TelemetryClient): boolean;
|
|
20
|
+
filterException(trace: ExceptionTelemetry, client: TelemetryClient): boolean;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class ITelemetryFilterV2 {
|
|
23
|
+
filterTrace(trace: TraceTelemetry$1, client: TelemetryClient$1): boolean;
|
|
24
|
+
filterException(trace: ExceptionTelemetry, client: TelemetryClient$1): boolean;
|
|
25
|
+
}
|
|
26
|
+
type AzureApplicationInsightsLoggerOptions = AzureInsightsClientOptions & {
|
|
27
|
+
level?: string;
|
|
28
|
+
silent?: boolean;
|
|
29
|
+
sendErrorsAsExceptions?: boolean;
|
|
30
|
+
};
|
|
31
|
+
declare class AzureApplicationInsightsLogger extends TransportStream {
|
|
32
|
+
private readonly options;
|
|
33
|
+
sendErrorsAsExceptions: boolean;
|
|
34
|
+
readonly name: string;
|
|
35
|
+
constructor(options: AzureApplicationInsightsLoggerOptions);
|
|
36
|
+
private handleTrace;
|
|
37
|
+
private handleException;
|
|
38
|
+
log(info: PlainObject, callback: () => void): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare const createWinstonLogger: (options: AzureApplicationInsightsLoggerOptions, ...fmt: Format[]) => winston.Logger;
|
|
42
|
+
|
|
43
|
+
export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions, ITelemetryFilterV2, ITelemetryFilterV3, createWinstonLogger };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
import * as winston from 'winston';
|
|
2
2
|
import { Format } from 'logform';
|
|
3
|
-
import { TelemetryClient } from 'applicationinsightsv2';
|
|
4
|
-
import { TelemetryClient as TelemetryClient$1 } from 'applicationinsightsv3';
|
|
5
3
|
import TransportStream from 'winston-transport';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare const createWinstonLogger: (client: NodeClient, ...fmt: Format[]) => winston.Logger;
|
|
4
|
+
import { TraceTelemetry as TraceTelemetry$1 } from 'applicationinsightsv2/out/Declarations/Contracts';
|
|
5
|
+
import { TelemetryClient as TelemetryClient$1 } from 'applicationinsightsv2';
|
|
6
|
+
import { TraceTelemetry, TelemetryClient, ExceptionTelemetry } from 'applicationinsightsv3';
|
|
10
7
|
|
|
11
8
|
type PlainObject = Record<string, any>;
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
type AzureInsightsClientOptions = {
|
|
10
|
+
version: 2;
|
|
11
|
+
client: TelemetryClient$1;
|
|
12
|
+
filters?: ITelemetryFilterV2[];
|
|
13
|
+
} | {
|
|
14
|
+
version: 3;
|
|
15
|
+
client: TelemetryClient;
|
|
16
|
+
filters?: ITelemetryFilterV3[];
|
|
17
|
+
};
|
|
18
|
+
declare abstract class ITelemetryFilterV3 {
|
|
19
|
+
filterTrace(trace: TraceTelemetry, client: TelemetryClient): boolean;
|
|
20
|
+
filterException(trace: ExceptionTelemetry, client: TelemetryClient): boolean;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class ITelemetryFilterV2 {
|
|
23
|
+
filterTrace(trace: TraceTelemetry$1, client: TelemetryClient$1): boolean;
|
|
24
|
+
filterException(trace: ExceptionTelemetry, client: TelemetryClient$1): boolean;
|
|
25
|
+
}
|
|
26
|
+
type AzureApplicationInsightsLoggerOptions = AzureInsightsClientOptions & {
|
|
14
27
|
level?: string;
|
|
15
28
|
silent?: boolean;
|
|
16
29
|
sendErrorsAsExceptions?: boolean;
|
|
17
|
-
}
|
|
30
|
+
};
|
|
18
31
|
declare class AzureApplicationInsightsLogger extends TransportStream {
|
|
19
|
-
readonly
|
|
32
|
+
private readonly options;
|
|
20
33
|
sendErrorsAsExceptions: boolean;
|
|
21
34
|
readonly name: string;
|
|
22
35
|
constructor(options: AzureApplicationInsightsLoggerOptions);
|
|
@@ -25,4 +38,6 @@ declare class AzureApplicationInsightsLogger extends TransportStream {
|
|
|
25
38
|
log(info: PlainObject, callback: () => void): void;
|
|
26
39
|
}
|
|
27
40
|
|
|
28
|
-
|
|
41
|
+
declare const createWinstonLogger: (options: AzureApplicationInsightsLoggerOptions, ...fmt: Format[]) => winston.Logger;
|
|
42
|
+
|
|
43
|
+
export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions, ITelemetryFilterV2, ITelemetryFilterV3, createWinstonLogger };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("winston");function t(e){return e&&e.__esModule?e:{default:e}}var r=t(require("winston-transport")),s=Object.defineProperty,o=(e,t)=>s(e,"name",{value:t,configurable:!0}),i={0:"Verbose",1:"Information",2:"Warning",3:"Error",4:"Critical"},n={0:0,1:1,2:2,3:3,4:4},c=o((e=>({emerg:4,alert:4,crit:4,error:3,warning:2,warn:2,notice:1,info:1,verbose:0,debug:0,silly:0}[e]??1)),"getMessageLevel"),l=o((e=>e instanceof Error),"isErrorLike"),a=o((e=>null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype),"isPlainObject"),p=o((e=>"object"!=typeof e||a(e)?e:Object.assign({},e)),"convertToPlainObject"),f=o((e=>{const t=["level","message"];return Object.keys(e).filter((e=>!t.includes(e))).reduce(((t,r)=>{const s=e[r];return t[r]=p(s),t}),{})}),"extractPropsFromInfo"),g=o((e=>{const t={message:e.message};for(const[r,s]of Object.entries(e))"stack"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=p(s));return t}),"extractErrorPropsForTrace"),h=class{static{o(this,"ITelemetryFilterV3")}filterTrace(e,t){return!0}filterException(e,t){return!0}},u=class{static{o(this,"ITelemetryFilterV2")}filterTrace(e,t){return!0}filterException(e,t){return!0}},m=class extends r.default{constructor(e){super({level:e.level??"info",silent:e.silent??!1}),this.options=e,this.name="applicationinsightslogger",this.sendErrorsAsExceptions=e.sendErrorsAsExceptions??!0}static{o(this,"AzureApplicationInsightsLogger")}sendErrorsAsExceptions;name;handleTrace(e,t,r,s){const o=f(t);let c;if(l(t)?c=t:l(r)?c=r:l(s)&&(c=s),c&&Object.assign(o,g(c)),s!==c&&Object.assign(o,s),3===this.options.version){const t={message:String(r),severity:i[e],properties:o};for(const e of this.options.filters??[])if(!e.filterTrace(t,this.options.client))return;this.options.client.trackTrace(t)}else{const t={message:String(r),severity:n[e],properties:o};for(const e of this.options.filters??[])if(!e.filterTrace(t,this.options.client))return;this.options.client.trackTrace(t)}}handleException(e,t,r){const s={};let o;if(l(e))o=e;else if(l(t))o=t;else{if(!l(r))return void console.log("RETURNING",{message:t});o=r}"string"==typeof t&&o.message!==t&&(s.message=t),o!==r&&Object.assign(s,r);const i={exception:o,properties:s};if(2===this.options.version){for(const e of this.options.filters??[])if(!e.filterException(i,this.options.client))return}else for(const e of this.options.filters??[])if(!e.filterException(i,this.options.client))return;this.options.client.trackException({exception:o,properties:s})}log(e,t){const{level:r,message:s}=e,o=c(r),i=Reflect.get(e,Symbol.for("splat"))??[],n=i.length?i[0]:{};this.handleTrace(o,e,s,n),this.sendErrorsAsExceptions&&o>=3&&this.handleException(e,s,n),t()}},E=o(((t,...r)=>{const s=[new m(t)];return void 0===process.env.WEBSITE_INSTANCE_ID&&s.push(new e.transports.Console({format:e.format.json(),stderrLevels:["error","crit","alert","emerg"],consoleWarnLevels:["warn","warning"]})),e.format.combine(...r,e.format.json()),e.createLogger({transports:s})}),"createWinstonLogger");exports.AzureApplicationInsightsLogger=m,exports.ITelemetryFilterV2=u,exports.ITelemetryFilterV3=h,exports.createWinstonLogger=E;//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/winston-azure-application-insights.ts","../src/helpers.ts"],"names":["TransportStream","transports","format","createLogger"],"mappings":";;;;;;;;;;;AAeA,IAAM,gBAAgE,GAAA;AAAA,EACpE,CAAC,kBAAwB,SAAA;AAAA,EACzB,CAAC,sBAA4B,aAAA;AAAA,EAC7B,CAAC,kBAAwB,SAAA;AAAA,EACzB,CAAC,gBAAsB,OAAA;AAAA,EACvB,CAAC,mBAAyB,UAAA;AAC5B,CAAA,CAAA;AACA,IAAM,gBAAgE,GAAA;AAAA,EACpE,CAAC,kBAAwB,CAAA;AAAA,EACzB,CAAC,sBAA4B,CAAA;AAAA,EAC7B,CAAC,kBAAwB,CAAA;AAAA,EACzB,CAAC,gBAAsB,CAAA;AAAA,EACvB,CAAC,mBAAyB,CAAA;AAC5B,CAAA,CAAA;AAEA,IAAM,eAAA,2BAAmB,YAAwC,KAAA;AAC/D,EAAA,MAAM,MAAwC,GAAA;AAAA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AAA,EAAA;AACjD,IAAY,WAAA,CAAA,IAAA;AAAA,MACV,IAAIC,mBAAW,OAAQ,CAAA;AAAA;AAAA;AAAA;AAAA,QAIrB,MAAA,EAAQC,eAAO,IAAK,EAAA;AAAA,QACpB,YAAc,EAAA,CAAC,OAAS,EAAA,MAAA,EAAQ,SAAS,OAAO,CAAA;AAAA,QAChD,iBAAA,EAAmB,CAAC,MAAA,EAAQ,SAAS,CAAA;AAAA,OACtC,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AAEA,EAAgBA,cAAO,CAAA,OAAA,CAAQ,GAAG,GAAK,EAAAA,cAAA,CAAO,MAAM,EAAA;AAEpD,EAAA,OAAOC,oBAAa,CAAA;AAAA;AAAA,IAElB,UAAY,EAAA,WAAA;AAAA,GACb,CAAA,CAAA;AACH,CAxBmC,EAAA,qBAAA","file":"index.js","sourcesContent":["import TransportStream from 'winston-transport';\nimport type { SeverityLevel as KnownSeverityLevelV2, TraceTelemetry as TraceTelemetryV2 } from 'applicationinsightsv2/out/Declarations/Contracts';\nimport type { TelemetryClient as TelemetryClientV2 } from 'applicationinsightsv2';\nimport type { TelemetryClient as TelemetryClientV3, KnownSeverityLevel as KnownSeverityLevelV3, TraceTelemetry as TraceTelemetryV3, ExceptionTelemetry } from 'applicationinsightsv3';\n\ntype PlainObject = Record<string, any>;\n\nenum SeverityLevel {\n Verbose = 0,\n Information = 1,\n Warning = 2,\n Error = 3,\n Critical = 4,\n}\n\nconst severityLevelsV3: Record<SeverityLevel, KnownSeverityLevelV3> = {\n [SeverityLevel.Verbose]: 'Verbose' as KnownSeverityLevelV3,\n [SeverityLevel.Information]: 'Information' as KnownSeverityLevelV3,\n [SeverityLevel.Warning]: 'Warning' as KnownSeverityLevelV3,\n [SeverityLevel.Error]: 'Error' as KnownSeverityLevelV3,\n [SeverityLevel.Critical]: 'Critical' as KnownSeverityLevelV3,\n};\nconst severityLevelsV2: Record<SeverityLevel, KnownSeverityLevelV2> = {\n [SeverityLevel.Verbose]: 0,\n [SeverityLevel.Information]: 1,\n [SeverityLevel.Warning]: 2,\n [SeverityLevel.Error]: 3,\n [SeverityLevel.Critical]: 4,\n};\n\nconst getMessageLevel = (winstonLevel: string): SeverityLevel => {\n const levels: Record<string, SeverityLevel> = {\n emerg: SeverityLevel.Critical,\n alert: SeverityLevel.Critical,\n crit: SeverityLevel.Critical,\n error: SeverityLevel.Error,\n warning: SeverityLevel.Warning,\n warn: SeverityLevel.Warning,\n notice: SeverityLevel.Information,\n info: SeverityLevel.Information,\n verbose: SeverityLevel.Verbose,\n debug: SeverityLevel.Verbose,\n silly: SeverityLevel.Verbose,\n } as const;\n\n return levels[winstonLevel] ?? SeverityLevel.Information;\n};\n\nconst isErrorLike = (obj: unknown): obj is Error => {\n return obj instanceof Error;\n};\n\nconst isPlainObject = (obj: unknown): obj is PlainObject => {\n return obj !== null && typeof obj === 'object' && Object.getPrototypeOf(obj) === Object.prototype;\n};\n\nconst convertToPlainObject = (obj: any): PlainObject => {\n if (typeof obj !== 'object') {\n return obj;\n }\n if (isPlainObject(obj)) {\n return obj;\n }\n return Object.assign({}, obj);\n};\n\nconst extractPropsFromInfo = (info: PlainObject): PlainObject => {\n const exclude = ['level', 'message'];\n\n return Object.keys(info)\n .filter((key) => !exclude.includes(key))\n .reduce<PlainObject>((props, key) => {\n const value = info[key];\n props[key] = convertToPlainObject(value);\n return props;\n }, {});\n};\n\nconst extractErrorPropsForTrace = (errorLike: Error): PlainObject => {\n const properties: PlainObject = {\n message: errorLike.message,\n };\n for (const [key, value] of Object.entries(errorLike)) {\n if (key !== 'stack' && Object.prototype.hasOwnProperty.call(errorLike, key)) {\n properties[key] = convertToPlainObject(value);\n }\n }\n return properties;\n};\n\ntype AzureInsightsClientOptions = {\n version: 2;\n client: TelemetryClientV2;\n filters?: ITelemetryFilterV2[];\n} | {\n version: 3;\n client: TelemetryClientV3;\n filters?: ITelemetryFilterV3[];\n}\n\nexport type FilterTraceArgs = {\n message: string;\n severity: SeverityLevel;\n properties: PlainObject;\n}\n\nexport abstract class ITelemetryFilterV3 {\n public filterTrace(trace: TraceTelemetryV3, client: TelemetryClientV3): boolean { return true; }\n public filterException(trace: ExceptionTelemetry, client: TelemetryClientV3): boolean { return true; }\n}\nexport abstract class ITelemetryFilterV2 {\n public filterTrace(trace: TraceTelemetryV2, client: TelemetryClientV2): boolean { return true; }\n public filterException(trace: ExceptionTelemetry, client: TelemetryClientV2): boolean { return true; }\n}\n\n\nexport type AzureApplicationInsightsLoggerOptions = AzureInsightsClientOptions & {\n level?: string;\n silent?: boolean;\n sendErrorsAsExceptions?: boolean;\n}\n\nexport class AzureApplicationInsightsLogger extends TransportStream {\n public sendErrorsAsExceptions: boolean;\n readonly name: string;\n\n constructor(private readonly options: AzureApplicationInsightsLoggerOptions) {\n super({ level: options.level ?? 'info', silent: options.silent ?? false });\n this.name = 'applicationinsightslogger';\n this.sendErrorsAsExceptions = options.sendErrorsAsExceptions ?? true;\n }\n\n private handleTrace(severity: SeverityLevel, info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const traceProps = extractPropsFromInfo(info);\n let errorArg: Error | undefined;\n\n if (isErrorLike(info)) {\n errorArg = info;\n } else if (isErrorLike(message)) {\n errorArg = message as unknown as Error;\n } else if (isErrorLike(logMeta)) {\n errorArg = logMeta;\n }\n\n if (errorArg) {\n Object.assign(traceProps, extractErrorPropsForTrace(errorArg));\n }\n\n if (logMeta !== errorArg) {\n Object.assign(traceProps, logMeta);\n }\n\n if (this.options.version === 3) {\n const telemetry: TraceTelemetryV3 = {\n message: String(message),\n severity: severityLevelsV3[severity],\n properties: traceProps,\n };\n for (const f of this.options.filters ?? []) {\n if (!f.filterTrace(telemetry, this.options.client)) {\n return;\n }\n }\n this.options.client.trackTrace(telemetry);\n } else {\n const telemetry: TraceTelemetryV2 = {\n message: String(message),\n severity: severityLevelsV2[severity],\n properties: traceProps,\n };\n for (const f of this.options.filters ?? []) {\n if (!f.filterTrace(telemetry, this.options.client)) {\n return;\n }\n }\n this.options.client.trackTrace(telemetry);\n }\n }\n\n private handleException(info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const exceptionProps: PlainObject = {};\n let exception: Error | undefined;\n\n if (isErrorLike(info)) {\n exception = info;\n } else if (isErrorLike(message)) {\n exception = message as unknown as Error;\n } else if (isErrorLike(logMeta)) {\n exception = logMeta;\n } else {\n console.log('RETURNING', { message });\n return;\n }\n\n if (typeof message === 'string' && exception.message !== message) {\n exceptionProps.message = message;\n }\n\n if (exception !== logMeta) {\n Object.assign(exceptionProps, logMeta);\n }\n\n const telemetry: ExceptionTelemetry = { exception, properties: exceptionProps };\n if (this.options.version === 2) {\n for (const f of this.options.filters ?? []) {\n if (!f.filterException(telemetry, this.options.client)) {\n return;\n }\n }\n } else { \n for (const f of this.options.filters ?? []) {\n if (!f.filterException(telemetry, this.options.client)) {\n return;\n }\n }\n }\n this.options.client.trackException({ exception, properties: exceptionProps });\n }\n\n override log(info: PlainObject, callback: () => void): void {\n const { level, message } = info;\n const severity = getMessageLevel(level);\n const splat = Reflect.get(info, Symbol.for('splat')) ?? [];\n const logMeta = splat.length ? splat[0] : {};\n\n this.handleTrace(severity, info, message, logMeta);\n\n if (this.sendErrorsAsExceptions && severity >= SeverityLevel.Error) {\n this.handleException(info, message, logMeta);\n }\n\n callback();\n }\n}\n","import type { Format } from 'logform';\nimport { createLogger, format, transports } from 'winston';\nimport type TransportStream from 'winston-transport';\nimport { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions } from './winston-azure-application-insights';\n\nexport const isRunningInAzure = () => {\n return process.env.WEBSITE_INSTANCE_ID !== undefined;\n};\nexport const isRunningLocally = () => {\n return !isRunningInAzure();\n};\n\nexport const createWinstonLogger = (options: AzureApplicationInsightsLoggerOptions, ...fmt: Format[]) => {\n const _transports: TransportStream[] = [\n new AzureApplicationInsightsLogger(options),\n ];\n\n if (process.env.WEBSITE_INSTANCE_ID === undefined) {\n _transports.push(\n new transports.Console({\n // format: format.combine(\n // format.errors({ stack: true }),\n // format.json()),\n format: format.json(),\n stderrLevels: ['error', 'crit', 'alert', 'emerg'],\n consoleWarnLevels: ['warn', 'warning'],\n }),\n );\n }\n\n const _format = format.combine(...fmt, format.json());\n\n return createLogger({\n // format: _format,\n transports: _transports,\n });\n};\n"]}
|