@shellicar/winston-azure-application-insights 5.0.1 → 5.0.3

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 CHANGED
@@ -50,6 +50,7 @@ import { AzureApplicationInsightsLogger } from '@shellicar/winston-azure-applica
50
50
  setup().start();
51
51
 
52
52
  const insightsLogger = new AzureApplicationInsightsLogger({
53
+ version: 3, // or 2 if using applicationinsights^3
53
54
  client: defaultClient,
54
55
  });
55
56
  ```
@@ -60,6 +61,7 @@ const { AzureApplicationInsightsLogger } = require('@shellicar/winston-azure-app
60
61
  setup(process.env.APPLICATIONINSIGHTS_CONNECTION_STRING).start();
61
62
 
62
63
  const insightsLogger = new AzureApplicationInsightsLogger({
64
+ version: 3,
63
65
  client: defaultClient,
64
66
  });
65
67
  ```
@@ -0,0 +1,51 @@
1
+ import * as winston from 'winston';
2
+ import { Format } from 'logform';
3
+ import { TelemetryClient as TelemetryClient$1 } from 'applicationinsightsv2';
4
+ import { TraceTelemetry as TraceTelemetry$1 } from 'applicationinsightsv2/out/Declarations/Contracts';
5
+ import { TraceTelemetry, TelemetryClient, ExceptionTelemetry } from 'applicationinsightsv3';
6
+ import TransportStream from 'winston-transport';
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
+ get client(): TelemetryClient | TelemetryClient$1;
36
+ constructor(options: AzureApplicationInsightsLoggerOptions);
37
+ private handleTrace;
38
+ private handleException;
39
+ log(info: PlainObject, callback: () => void): void;
40
+ }
41
+
42
+ declare const isRunningInAzure: () => boolean;
43
+ declare const isRunningLocally: () => boolean;
44
+ type CreateWinstonLoggerOptions = {
45
+ insights: AzureApplicationInsightsLoggerOptions;
46
+ console: boolean;
47
+ format?: Format[];
48
+ };
49
+ declare const createWinstonLogger: (options: CreateWinstonLoggerOptions) => winston.Logger;
50
+
51
+ export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions, type CreateWinstonLoggerOptions, ITelemetryFilterV2, ITelemetryFilterV3, createWinstonLogger, isRunningInAzure, isRunningLocally };
package/dist/index.d.ts CHANGED
@@ -1,28 +1,51 @@
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';
3
+ import { TelemetryClient as TelemetryClient$1 } from 'applicationinsightsv2';
4
+ import { TraceTelemetry as TraceTelemetry$1 } from 'applicationinsightsv2/out/Declarations/Contracts';
5
+ import { TraceTelemetry, TelemetryClient, ExceptionTelemetry } from 'applicationinsightsv3';
5
6
  import TransportStream from 'winston-transport';
6
7
 
7
- type NodeClient = TelemetryClient | TelemetryClient$1;
8
-
9
- declare const createWinstonLogger: (client: NodeClient, ...fmt: Format[]) => winston.Logger;
10
-
11
8
  type PlainObject = Record<string, any>;
12
- interface AzureApplicationInsightsLoggerOptions {
13
- client: NodeClient;
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 client: NodeClient;
32
+ private readonly options;
20
33
  sendErrorsAsExceptions: boolean;
21
34
  readonly name: string;
35
+ get client(): TelemetryClient | TelemetryClient$1;
22
36
  constructor(options: AzureApplicationInsightsLoggerOptions);
23
37
  private handleTrace;
24
38
  private handleException;
25
39
  log(info: PlainObject, callback: () => void): void;
26
40
  }
27
41
 
28
- export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions, createWinstonLogger };
42
+ declare const isRunningInAzure: () => boolean;
43
+ declare const isRunningLocally: () => boolean;
44
+ type CreateWinstonLoggerOptions = {
45
+ insights: AzureApplicationInsightsLoggerOptions;
46
+ console: boolean;
47
+ format?: Format[];
48
+ };
49
+ declare const createWinstonLogger: (options: CreateWinstonLoggerOptions) => winston.Logger;
50
+
51
+ export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions, type CreateWinstonLoggerOptions, ITelemetryFilterV2, ITelemetryFilterV3, createWinstonLogger, isRunningInAzure, isRunningLocally };
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;get client(){return this.options.client}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()}},b=o((t=>{const r=[new m(t.insights)];t.console&&r.push(new e.transports.Console({format:e.format.json(),stderrLevels:["error","crit","alert","emerg"],consoleWarnLevels:["warn","warning"]}));const s=e.format.combine(...t.format??[],e.format.json());return e.createLogger({format:s,transports:r})}),"createWinstonLogger");exports.AzureApplicationInsightsLogger=m,exports.ITelemetryFilterV2=u,exports.ITelemetryFilterV3=h,exports.createWinstonLogger=b;//# 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,IAC5C,KAAO,EAAA,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AA;AACnB,IAAY,WAAA,CAAA,IAAA;AAAA,MACV,IAAIC,mBAAW,OAAQ,CAAA;AAAA,QACrB,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,EAAM,MAAA,OAAA,GAAUA,cAAO,CAAA,OAAA,CAAQ,GAAI,OAAA,CAAQ,UAAU,EAAC,EAAIA,cAAO,CAAA,IAAA,EAAM,CAAA,CAAA;AAEvE,EAAA,OAAOC,oBAAa,CAAA;AAAA,IAClB,MAAQ,EAAA,OAAA;AAAA,IACR,UAAY,EAAA,WAAA;AAAA,GACb,CAAA,CAAA;AACH,CAnBmC,EAAA,qBAAA","file":"index.js","sourcesContent":["import type { TelemetryClient as TelemetryClientV2 } from 'applicationinsightsv2';\nimport type { SeverityLevel as KnownSeverityLevelV2, TraceTelemetry as TraceTelemetryV2 } from 'applicationinsightsv2/out/Declarations/Contracts';\nimport type { ExceptionTelemetry, KnownSeverityLevel as KnownSeverityLevelV3, TelemetryClient as TelemetryClientV3, TraceTelemetry as TraceTelemetryV3 } from 'applicationinsightsv3';\nimport TransportStream from 'winston-transport';\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 | {\n version: 2;\n client: TelemetryClientV2;\n filters?: ITelemetryFilterV2[];\n }\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 {\n return true;\n }\n public filterException(trace: ExceptionTelemetry, client: TelemetryClientV3): boolean {\n return true;\n }\n}\nexport abstract class ITelemetryFilterV2 {\n public filterTrace(trace: TraceTelemetryV2, client: TelemetryClientV2): boolean {\n return true;\n }\n public filterException(trace: ExceptionTelemetry, client: TelemetryClientV2): boolean {\n 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 public get client(): TelemetryClientV3 | TelemetryClientV2 {\n return this.options.client;\n }\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 type CreateWinstonLoggerOptions = {\n insights: AzureApplicationInsightsLoggerOptions;\n console: boolean;\n format?: Format[];\n};\n\nexport const createWinstonLogger = (options: CreateWinstonLoggerOptions) => {\n const _transports: TransportStream[] = [new AzureApplicationInsightsLogger(options.insights)];\n\n if (options.console) {\n _transports.push(\n new transports.Console({\n format: format.json(),\n stderrLevels: ['error', 'crit', 'alert', 'emerg'],\n consoleWarnLevels: ['warn', 'warning'],\n }),\n );\n }\n\n const _format = format.combine(...(options.format ?? []), format.json());\n\n return createLogger({\n format: _format,\n transports: _transports,\n });\n};\n"]}