@shellicar/winston-azure-application-insights 5.1.0 → 6.0.0-preview.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Stephen Hellicar
3
+ Copyright (c) 2025 Stephen Hellicar
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,149 +1,32 @@
1
- @shellicar/winston-azure-application-insights
2
- ==================================
1
+ # @shellicar/winston-azure-application-insights
3
2
 
4
- ## Update
3
+ An [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/) transport for [Winston](https://github.com/winstonjs/winston) logging library
5
4
 
6
- This has been forked as the original and other forks have not been updated in quite a while.
7
-
8
- Most of this README has been left as is, with relevant updates only.
9
-
10
- ## Intro
11
-
12
- An [Azure Application Insights][0] transport for [Winston][1] logging library.
13
-
14
- This transport is designed to make it easy to obtain a reference to a standard logging library that broadcasts to Application Insights.
15
-
16
- Your logging interface can remain familiar to standard (`logger.info`, `logger.error` etc) without intertwining any Azure-specific implementation detail.
17
-
18
- **[Read the project changelog](./CHANGELOG.md)**
19
-
20
- ## Installation
5
+ ## Installation & Quick Start
21
6
 
22
7
  ```sh
23
- pnpm install @shellicar/winston-azure-application-insights
8
+ npm install @shellicar/winston-azure-application-insights
24
9
  ```
25
10
 
26
- ## Support
27
-
28
- This library has CJS and ESM outputs.
29
-
30
- Continuous integration tests are run against the NodeJS LTS versions.
31
-
32
- ## Usage
33
-
34
- See `demo.ts` and the `examples` directory for a usage examples.
35
-
36
- **Connection String**
37
-
38
- **Note**: an connection string is required before any data can be sent. Please see the
39
- "[Connection Strings in Application Insights](https://learn.microsoft.com/en-us/azure/azure-monitor/app/sdk-connection-string?tabs=dotnet5#find-your-connection-string)"
40
- for more information.
41
-
42
- The connection string can be supplied:
43
-
44
- * Passing an initialized Application Insights client in the "client" options property:
11
+ ## Quick Example
45
12
 
46
13
  ```typescript
47
- import { setup, defaultClient } from 'applicationinsights';
48
- import { AzureApplicationInsightsLogger } from '@shellicar/winston-azure-application-insights';
14
+ import { createWinstonLogger, ApplicationInsightsVersion } from '@shellicar/winston-azure-application-insights';
15
+ import applicationinsights from 'applicationinsights';
49
16
 
50
- setup().start();
17
+ applicationinsights.setup().start();
51
18
 
52
- const insightsLogger = new AzureApplicationInsightsLogger({
53
- version: 3, // or 2 if using applicationinsights^3
54
- client: defaultClient,
19
+ const logger = createWinstonLogger({
20
+ insights: {
21
+ version: ApplicationInsightsVersion.V3,
22
+ client: applicationinsights.defaultClient
23
+ },
55
24
  });
56
- ```
57
- ```cjs
58
- const { setup, defaultClient } = require("applicationinsights");
59
- const { AzureApplicationInsightsLogger } = require('@shellicar/winston-azure-application-insights');
60
-
61
- setup(process.env.APPLICATIONINSIGHTS_CONNECTION_STRING).start();
62
-
63
- const insightsLogger = new AzureApplicationInsightsLogger({
64
- version: 3,
65
- client: defaultClient,
66
- });
67
- ```
68
-
69
- **I get an error when using this transport**
70
-
71
- If you receive the error:
72
25
 
73
- `No instrumentation key or connection string was provided to the Azure Monitor Exporter`
74
-
75
- Then you didn't specify a suitable instrumentation key. See the section above.
76
-
77
- `Error: @opentelemetry/api: Attempted duplicate registration of API: context`
78
-
79
- This may be because your environment has already (maybe implicitly) loaded applicationinsights and called `.setup()`.
80
- This happens if you are running an Azure Function App and have `APPLICATIONINSIGHTS_CONNECTION_STRING` set.
81
- The best solution to this is to load `applicationinsights` and pass in `appInsights.defaultClient` using the `client`
82
- option as per example.
83
-
84
- **I'm seeing multiple traces with similar/identical messages**
85
-
86
- `applicationinsights` deeply integrates into the `console` transports, and `winston` itself (via `diagnostic-channel`).
87
- If you are integrating this transport, it's recommended to disable `diagnostic-channel` and console auto collection:
88
-
89
- To control `diagnostic-channel`, [follow the guide in the main repository](https://github.com/Microsoft/ApplicationInsights-node.js#automatic-third-party-instrumentation).
90
-
91
- It is recommended to use _only_ this transport where your application is running in production mode and needs to
92
- stream data to Application Insights. In all other scenarios such as local debug and test suites, the console transport
93
- (or similar) should suffice. This is to avoid polluting instances/unnecessary cost.
94
-
95
- Despite this notice, to specifically disable console transport collection, use `.setAutoCollectConsole(false)`:
96
-
97
- ```js
98
- setup().setAutoCollectConsole(false);
26
+ logger.info('Hello World');
27
+ logger.error('Something went wrong', new Error('Database connection failed'));
99
28
  ```
100
29
 
101
- ## Options
102
-
103
- * **level**: lowest logging level transport to be logged (default: `info`)
104
- * **sendErrorsAsExceptions**: Boolean flag indicating whether to also track errors to the AI exceptions table.
105
- See section below for more details (default: `true`).
106
-
107
- **SDK integration options (required):**
108
-
109
- * **client**: An existing App Insights client
110
-
111
- ## Log Levels
112
-
113
- Supported log levels are:
114
-
115
- Winston Level | App Insights level
116
- ---------------|------------------
117
- error | error (3)
118
- warn | warning (2)
119
- info | informational (1)
120
- verbose | verbose (0)
121
- debug | verbose (0)
122
- silly | verbose (0)
123
-
124
- **All other possible levels, or custom levels, will default to `info`**
125
-
126
- [0]: https://azure.microsoft.com/en-us/services/application-insights/
127
- [1]: https://github.com/winstonjs/winston
128
-
129
- ## Error & Exception Logging: Exceptions vs. Traces
130
-
131
- The Application Insights "exceptions" table allows you to see more detailed error information including the stack trace.
132
- Therefore for all log events at severity level error or above, an exception is logged if the library detects that an
133
- Error object has been passed.
134
- The log event will still generate a trace with the correct severity level regardless of this setting, but please note
135
- that any Error object will have its `stack` property omitted when sent to `trackTrace`.
136
- All other properties are included.
137
-
138
- This allows you to see clearly Azure Application Insights instead of having to access trace information manually and set
139
- up alerts based on the related metrics.
140
-
141
- How it works with `sendErrorsAsExceptions: true`:
142
-
143
- * `logger.error('error message');` creates a trace with severity level 3; *no* exception is tracked
144
- * `logger.error(new Error('error message'));` creates a trace with severity level 3, *and* an exception with the Error object as argument
145
- * `logger.error('error message', new Error('error message'));` creates a trace with severity level 3, *and* an exception with the Error object as argument
146
- * `logger.error(new Error('error message'), logContext);` creates a trace and exception and logContext is set to the customDimensions (properties) track* field
147
- * `logger.info(new Error('error message'));` creates a trace with severity level 1; *no* exception is tracked
30
+ ## Documentation
148
31
 
149
- If you do not wish to track exceptions, you can set the option `sendErrorsAsExceptions: false` when configuring the transport.
32
+ For full documentation, visit the [GitHub repository](https://github.com/shellicar/winston-azure-application-insights).
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e=require("winston-transport"),t=require("triple-beam"),r=require("applicationinsightsv3"),n=require("winston"),o=require("process");function i(e){return e&&e.__esModule?e:{default:e}}var s=i(e),l=i(n),a=Object.defineProperty,c=(e,t)=>a(e,"name",{value:t,configurable:!0}),p=(e=>(e.Verbose="Verbose",e.Information="Information",e.Warning="Warning",e.Error="Error",e.Critical="Critical",e))(p||{}),u=(e=>(e.V2="2.x",e.V3="3.x",e))(u||{}),f={error:"Error",warn:"Warning",info:"Information",verbose:"Verbose"},m=c(e=>null!=e&&"object"==typeof e&&void 0===e.constructor?{...e}:e,"convertNullPrototypeToRegularObject"),v=c((e,...t)=>{const r=["message","name","stack",...t],n={};for(const t of Object.keys(e))if(!r.includes(t)){const r=e[t];n[t]=m(r)}return n},"extractErrorProperties"),y=c((e,r)=>{const n=[];r(e)&&n.push({exception:e,properties:v(e,"level")});const o=e[t.SPLAT];if(null!=o)for(const e of o)r(e)&&n.push({exception:e,properties:v(e)});return n},"extractErrorsStep"),g=c(e=>{const r=String(e.message),n=e[t.SPLAT],o=n?.[0];if(void 0!==o?.message){const e=` ${o.message}`;if(r.endsWith(e))return r.slice(0,-e.length)}return r},"extractMessageStep"),h=c(e=>{if(null==e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t},"isPlainObject"),d=c(e=>{const t=Object.entries(e);if(0===t.length)return null;const r={};for(const[e,n]of t)r[e]=m(n);return r},"extractNonSymbolProps"),x=c((e,t)=>{if(t(e)){const{level:t,message:r,...n}=e;return d(n)}const{level:r,name:n,message:o,stack:i,cause:s,...l}=e;return d(l)},"extractDefaultMeta"),b=c((e,r=e=>e instanceof Error)=>{const n=x(e,r),o=e[t.SPLAT];if(null==o)return n??{};const i=o.filter(e=>!r(e))[0];return null!=i&&h(i)?{...n,...i}:n??{}},"extractPropertiesStep"),E=c((e,t,r)=>{const n=t[e.level];if(null!=n)return n;if(null!=r){const n=r[e.level];if(null!=n){const e=Object.entries(r).map(e=>({levelName:e[0],priority:e[1]})).filter(e=>n<e.priority).sort((e,t)=>e.priority-t.priority);for(const{levelName:r}of e){const e=t[r];if(e)return e}}}return"Verbose"},"extractSeverityStep"),w=c(e=>e instanceof Error,"isError"),S=class extends s.default{static{c(this,"ApplicationInsightsTransport")}telemetryHandler;options;levels;constructor(e){super({level:e.level}),this.options={telemetryHandler:e.telemetryHandler,severityMapping:e.severityMapping??f,isError:e.isError??w,traceFilter:e.traceFilter??(()=>!0),exceptionFilter:e.exceptionFilter??(()=>!0)},this.telemetryHandler=e.telemetryHandler}log(e,t){const r=this.getExceptions(e),n=this.getTrace(e,r);this.telemetryHandler.handleTelemetry({trace:n,exceptions:r}),t()}getTrace(e,t){const r=this.extractTrace(e,t);return null!=r&&this.options.traceFilter(r)?r:null}getExceptions(e){return y(e,this.options.isError).filter(this.options.exceptionFilter)}extractTrace(e,t){if(t.length>0&&this.options.isError(e))return null;return{message:g(e),properties:b(e,this.options.isError),severity:E(e,this.options.severityMapping,this.levels)}}},T=class{static{c(this,"ApplicationInsightsV2TelemetryHandler")}client;severityMapping={Verbose:0,Information:1,Warning:2,Error:3,Critical:4};constructor(e){this.client=e.client}handleTelemetry(e){if(null!=e.trace){const t={message:e.trace.message,severity:this.mapSeverity(e.trace.severity),properties:e.trace.properties};this.client.trackTrace(t)}for(const t of e.exceptions){const e={exception:t.exception,properties:t.properties};this.client.trackException(e)}}mapSeverity(e){return this.severityMapping[e]}},A=class{static{c(this,"ApplicationInsightsV3TelemetryHandler")}client;severityMapping={Verbose:r.KnownSeverityLevel.Verbose,Information:r.KnownSeverityLevel.Information,Warning:r.KnownSeverityLevel.Warning,Error:r.KnownSeverityLevel.Error,Critical:r.KnownSeverityLevel.Critical};constructor(e){this.client=e.client}handleTelemetry(e){if(null!=e.trace){const t={message:e.trace.message,severity:this.mapSeverity(e.trace.severity),properties:e.trace.properties};this.client.trackTrace(t)}for(const t of e.exceptions){const e={exception:t.exception,properties:t.properties};this.client.trackException(e)}}mapSeverity(e){return this.severityMapping[e]}},j=c(e=>{switch(e.version){case"2.x":return new T({client:e.client});case"3.x":return new A({client:e.client});default:return e.telemetryHandler}},"createTelemetryHandler"),I=c(e=>{const t=j(e);return new S({telemetryHandler:t,severityMapping:e.severityMapping,exceptionFilter:e.exceptionFilter,traceFilter:e.traceFilter,isError:e.isError,level:e.level})},"createApplicationInsightsTransport"),M=c(e=>e[t.MESSAGE].replaceAll(/\\u001b/g,""),"unescapeColorCodes"),F=c(()=>l.default.format.printf(M),"unescapeColorCodesFormat"),L=c(e=>{if(Array.isArray(e))return l.default.format.combine(...e);const t=[];return!0===e.timestamp?t.push(l.default.format.timestamp()):"object"==typeof e.timestamp&&t.push(l.default.format.timestamp(e.timestamp)),!0===e.errors?t.push(l.default.format.errors({stack:!0})):"object"==typeof e.errors&&t.push(l.default.format.errors(e.errors)),!0===e.colorize?t.push(l.default.format.colorize({all:!0})):"object"==typeof e.colorize&&t.push(l.default.format.colorize(e.colorize)),"simple"===e.output&&t.push(l.default.format.simple()),"json"===e.output&&(t.push(l.default.format.json()),!0!==e.colorize&&"object"!=typeof e.colorize||t.push(F())),l.default.format.combine(...t)},"createWinstonFormat"),H=c(()=>void 0!==o.env.WEBSITE_INSTANCE_ID,"isRunningInAzure"),V=c(()=>!H(),"isRunningLocally"),W=c(e=>{const{severityMapping:t,exceptionFilter:r,traceFilter:n,isError:o,...i}=e.insights,s=j(i),a=[];if(e.winston?.console?.enabled??V()){let t;if(Array.isArray(e.winston?.console?.format))t=e.winston.console.format;else{const r=e.winston?.console?.format??{};t={output:r.output??"json",timestamp:r.timestamp??!0,errors:r.errors??{stack:!0},colorize:r.colorize??!0}}const r=L(t);a.push(new l.default.transports.Console({format:r,level:e.winston?.console?.level,stderrLevels:["error","crit","alert","emerg"],consoleWarnLevels:["warn","warning"]}))}if(e.winston?.insights?.enabled??!0){const i=I({telemetryHandler:s,severityMapping:t,exceptionFilter:r,traceFilter:n,isError:o,level:e.winston?.insights?.level});a.push(i)}const c=e.winston?.defaults?.level??"info",p=e.winston?.levels??l.default.config.npm.levels;return l.default.createLogger({...e.winston?.options,level:c,levels:p,transports:a,defaultMeta:e.winston?.defaults?.defaultMeta})},"createWinstonLogger");exports.ApplicationInsightsVersion=u,exports.TelemetrySeverity=p,exports.createApplicationInsightsTransport=I,exports.createTelemetryHandler=j,exports.createWinstonLogger=W,exports.isRunningInAzure=H,exports.isRunningLocally=V;//# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/public/enums.ts","../src/private/consts.ts","../src/private/convertNullPrototypeToRegularObject.ts","../src/private/extractErrorsStep.ts","../src/private/extractMessageStep.ts","../src/private/isPlainObject.ts","../src/private/extractPropertiesStep.ts","../src/private/extractSeverityStep.ts","../src/private/isError.ts","../src/private/ApplicationInsightsTransport.ts","../src/private/ApplicationInsightsV2TelemetryHandler.ts","../src/private/ApplicationInsightsV3TelemetryHandler.ts","../src/public/createTelemetryHandler.ts","../src/public/createApplicationInsightsTransport.ts","../src/private/createWinstonFormat.ts","../src/public/isRunningInAzure.ts","../src/public/isRunningLocally.ts","../src/public/createWinstonLogger.ts"],"names":["TelemetrySeverity","ApplicationInsightsVersion","isError","SPLAT","level","message","rest","TransportStream","KnownSeverityLevel","MESSAGE","winston","env"],"mappings":";;;;AAAO,IAAK,iBAAA,qBAAAA,kBAAAA,KAAL;AACL,EAAAA,mBAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,mBAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,mBAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,mBAAA,OAAA,CAAA,GAAQ,OAAA;AACR,EAAAA,mBAAA,UAAA,CAAA,GAAW,UAAA;AALD,EAAA,OAAAA,kBAAAA;AAAA,CAAA,EAAA,iBAAA,IAAA,EAAA;AAQL,IAAK,0BAAA,qBAAAC,2BAAAA,KAAL;AACL,EAAAA,4BAAA,IAAA,CAAA,GAAK,KAAA;AACL,EAAAA,4BAAA,IAAA,CAAA,GAAK,KAAA;AAFK,EAAA,OAAAA,2BAAAA;AAAA,CAAA,EAAA,0BAAA,IAAA,EAAA;;;ACLL,IAAM,sBAAA,GAA0C;AAAA,EACrD,KAAA,EAAA,OAAA;AAAA,EACA,IAAA,EAAA,SAAA;AAAA,EACA,IAAA,EAAA,aAAA;AAAA,EACA,OAAA,EAAA,SAAA;AACF,CAAA;;;ACHO,IAAM,mCAAA,2BAAuC,KAAA,KAA4B;AAC9E,EAAA,IAAI,SAAS,IAAA,IAAQ,OAAO,UAAU,QAAA,IAAY,KAAA,CAAM,gBAAgB,MAAA,EAAW;AACjF,IAAA,OAAO,EAAE,GAAG,KAAA,EAAM;AAAA,EACpB;AACA,EAAA,OAAO,KAAA;AACT,CAAA,EALmD,qCAAA,CAAA;;;ACAnD,IAAM,sBAAA,mBAAyB,MAAA,CAAA,CAAC,KAAA,EAAA,GAAiB,gBAAA,KAAwD;AACvG,EAAA,MAAM,SAAS,CAAC,SAAA,EAAW,MAAA,EAAQ,OAAA,EAAS,G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AAM,eAAA,GAAkB,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU,OAAA,IAAW,IAAA;AAC9D,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,MAAM,YAAY,kCAAA,CAAmC;AAAA,MACnD,gBAAA;AAAA,MACA,eAAA;AAAA,MACA,eAAA;AAAA,MACA,WAAA;AAAA,MACA,OAAA,EAAAR,QAAAA;AAAA,MACA,KAAA,EAAO,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU;AAAA,KACnC,CAAA;AACD,IAAA,UAAA,CAAW,KAAK,SAAS,CAAA;AAAA,EAC3B;AAGA,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU,KAAA,IAAS,MAAA;AAClD,EAAA,MAAM,SAAS,OAAA,CAAQ,OAAA,EAAS,MAAA,IAAUQ,wBAAAA,CAAQ,OAAO,GAAA,CAAI,MAAA;AAG7D,EAAA,OAAOA,yBAAQ,YAAA,CAAa;AAAA,IAC1B,GAAG,QAAQ,OAAA,EAAS,OAAA;AAAA,IACpB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA,WAAA,EAAa,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU;AAAA,GACzC,CAAA;AACH,CAAA,EA7DmC,qBAAA","file":"index.cjs","sourcesContent":["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","/**\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 { 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","import { SPLAT } from 'triple-beam';\nimport type { WinstonInfo } from './types';\n\nexport const extractMessageStep = (info: WinstonInfo): string => {\n const messageAsString = String(info.message);\n\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\n if (messageAsString.endsWith(expectedSuffix)) {\n return messageAsString.slice(0, -expectedSuffix.length);\n }\n }\n\n return messageAsString;\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 { 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","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 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","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 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","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\n // Default format for main logger (applied to all transports)\n return winston.createLogger({\n ...options.winston?.options,\n level,\n levels,\n transports,\n defaultMeta: options.winston?.defaults?.defaultMeta,\n });\n};\n"]}
@@ -0,0 +1,235 @@
1
+ import TransportStream from 'winston-transport';
2
+ import { Format, TimestampOptions, ColorizeOptions } from 'logform';
3
+ import { TraceTelemetry, ExceptionTelemetry } from 'applicationinsightsv2/out/Declarations/Contracts';
4
+ import { TraceTelemetry as TraceTelemetry$1, ExceptionTelemetry as ExceptionTelemetry$1 } from 'applicationinsightsv3';
5
+ import winston from 'winston';
6
+
7
+ declare enum TelemetrySeverity {
8
+ Verbose = "Verbose",
9
+ Information = "Information",
10
+ Warning = "Warning",
11
+ Error = "Error",
12
+ Critical = "Critical"
13
+ }
14
+ declare enum ApplicationInsightsVersion {
15
+ V2 = "2.x",
16
+ V3 = "3.x"
17
+ }
18
+
19
+ interface ITelemetryClientV2 {
20
+ trackTrace(telemetry: TraceTelemetry): void;
21
+ trackException(telemetry: ExceptionTelemetry): void;
22
+ }
23
+
24
+ interface ITelemetryClientV3 {
25
+ trackTrace(telemetry: TraceTelemetry$1): void;
26
+ trackException(telemetry: ExceptionTelemetry$1): void;
27
+ }
28
+
29
+ type TelemetryDataProperties = Record<string, unknown>;
30
+ interface TelemetryDataTrace {
31
+ message: string;
32
+ properties: TelemetryDataProperties;
33
+ severity: TelemetrySeverity;
34
+ }
35
+ interface TelemetryDataException {
36
+ exception: Error;
37
+ properties: TelemetryDataProperties;
38
+ }
39
+ interface TelemetryData {
40
+ trace: TelemetryDataTrace | null;
41
+ exceptions: TelemetryDataException[];
42
+ }
43
+ interface TelemetryHandler {
44
+ handleTelemetry: (telemetry: TelemetryData) => void;
45
+ }
46
+ interface SeverityMapping {
47
+ [level: string]: TelemetrySeverity;
48
+ }
49
+ type IsError = (obj: unknown) => obj is Error;
50
+ type ITraceTelemetryFilter = (trace: TelemetryDataTrace) => boolean;
51
+ type IExceptionTelemetryFilter = (exception: TelemetryDataException) => boolean;
52
+ /**
53
+ * Pass in either a TelemetryClient and the version of the Application Insights SDK,
54
+ * Or a TelemetryHandler.
55
+ */
56
+ type CreateTelemetryHandlerOptions = {
57
+ /**
58
+ * Telemetry client for `applicationinsights@2`
59
+ */
60
+ client: ITelemetryClientV2;
61
+ version: ApplicationInsightsVersion.V2;
62
+ } | {
63
+ /**
64
+ * Telemetry client for `applicationinsights@3`
65
+ */
66
+ client: ITelemetryClientV3;
67
+ version: ApplicationInsightsVersion.V3;
68
+ } | {
69
+ telemetryHandler: TelemetryHandler;
70
+ version?: never;
71
+ };
72
+ /**
73
+ * Configuration options for creating an Application Insights transport.
74
+ */
75
+ type CreateApplicationInsightsTransportOptions = {
76
+ /**
77
+ * Custom mapping from Winston log levels to Application Insights severity levels.
78
+ * If not provided, uses default mappings (error → Error, warn → Warning, info → Information, etc.).
79
+ * Custom levels fall back to the next available severity based on level priority.
80
+ */
81
+ severityMapping?: SeverityMapping;
82
+ /**
83
+ * Optional filter function called before sending traces to Application Insights.
84
+ * Return false to prevent the trace from being sent. Useful for filtering out verbose logs or specific patterns.
85
+ */
86
+ traceFilter?: ITraceTelemetryFilter;
87
+ /**
88
+ * Optional filter function called before sending exceptions to Application Insights.
89
+ * Return false to prevent the exception from being sent. Useful for filtering out known/expected errors.
90
+ */
91
+ exceptionFilter?: IExceptionTelemetryFilter;
92
+ /**
93
+ * Custom function to determine what objects should be treated as errors.
94
+ * Defaults to checking `obj instanceof Error`. Objects identified as errors are extracted from log
95
+ * parameters and sent as Application Insights exceptions. When the first parameter is an Error,
96
+ * only an exception is sent (no trace) to avoid duplicate telemetry.
97
+ */
98
+ isError?: IsError;
99
+ level?: string;
100
+ } & CreateTelemetryHandlerOptions;
101
+ interface WinstonLevels {
102
+ [levelName: string]: number;
103
+ }
104
+ interface WinstonColors {
105
+ [colorName: string]: string;
106
+ }
107
+ type WinstonTransportOptionsFormat = {
108
+ /**
109
+ * Output format for log messages.
110
+ * 'json' produces structured JSON output ({@link https://github.com/winstonjs/logform#json}),
111
+ * 'simple' produces human-readable text ({@link https://github.com/winstonjs/logform#simple}).
112
+ * @default 'json'
113
+ */
114
+ output?: 'json' | 'simple';
115
+ /**
116
+ * Whether to include error stack traces in log output ({@link https://github.com/winstonjs/logform#errors}).
117
+ * Use boolean for simple enable/disable, or object to control stack inclusion.
118
+ * @default { stack: true }
119
+ */
120
+ errors?: boolean | {
121
+ /**
122
+ * Whether to include stack traces when logging Error objects.
123
+ * @default true
124
+ */
125
+ stack?: boolean;
126
+ };
127
+ /**
128
+ * Whether to include timestamps in log output ({@link https://github.com/winstonjs/logform#timestamp}).
129
+ * Use boolean for default ISO format, or object to customise timestamp format.
130
+ * @default true
131
+ */
132
+ timestamp?: boolean | TimestampOptions;
133
+ /**
134
+ * Whether to colorize log output for terminal display ({@link https://github.com/winstonjs/logform#colorize}).
135
+ * When used with 'json' output, automatically unescapes ANSI color codes for proper display.
136
+ * @default true
137
+ */
138
+ colorize?: boolean | ColorizeOptions;
139
+ };
140
+ interface WinstonLoggerDefaults {
141
+ /**
142
+ * Minimum log level for the logger.
143
+ * @default 'info'
144
+ */
145
+ level?: string;
146
+ /**
147
+ * Default metadata to include with all log entries.
148
+ */
149
+ defaultMeta?: Record<string, unknown>;
150
+ }
151
+ interface WinstonBaseTransportOptions extends WinstonLoggerDefaults {
152
+ /**
153
+ * Whether this transport is enabled.
154
+ * @default true for insights transport, auto-detected for console (true locally, false in Azure)
155
+ */
156
+ enabled?: boolean;
157
+ }
158
+ interface WinstonConsoleTransportOptions extends WinstonBaseTransportOptions {
159
+ /**
160
+ * Format configuration for this transport.
161
+ * If provided as Format[] ({@link https://github.com/winstonjs/logform#formats}), it is used as-is without any additional processing.
162
+ * Use WinstonTransportOptionsFormat for simplified configuration with automatic format handling.
163
+ */
164
+ format?: Format[] | WinstonTransportOptionsFormat;
165
+ }
166
+ interface WinstonInsightsTransportOptions extends WinstonBaseTransportOptions {
167
+ }
168
+ interface WinstonLoggerOptions {
169
+ /**
170
+ * Silence the logger (no output).
171
+ * @default false
172
+ */
173
+ silent?: boolean;
174
+ /**
175
+ * Exit on error.
176
+ * @default true
177
+ */
178
+ exitOnError?: boolean | ((error: Error) => boolean);
179
+ /**
180
+ * Handle exceptions.
181
+ * @default false
182
+ */
183
+ handleExceptions?: boolean;
184
+ /**
185
+ * Handle rejections.
186
+ * @default false
187
+ */
188
+ handleRejections?: boolean;
189
+ }
190
+ type CreateWinstonLoggerOptions = {
191
+ winston?: {
192
+ /**
193
+ * Custom log levels definition.
194
+ * @default winston.config.npm.levels
195
+ */
196
+ levels?: WinstonLevels;
197
+ /**
198
+ * Custom colors for log levels.
199
+ */
200
+ colors?: WinstonColors;
201
+ /**
202
+ * Additional winston logger options.
203
+ */
204
+ options?: WinstonLoggerOptions;
205
+ /**
206
+ * Default settings applied to the logger.
207
+ */
208
+ defaults?: WinstonLoggerDefaults;
209
+ /**
210
+ * Console transport configuration.
211
+ */
212
+ console?: WinstonConsoleTransportOptions;
213
+ /**
214
+ * Application Insights transport configuration.
215
+ * Format is managed automatically and cannot be overridden.
216
+ */
217
+ insights?: WinstonInsightsTransportOptions;
218
+ };
219
+ /**
220
+ * Application Insights transport configuration (required).
221
+ */
222
+ insights: CreateApplicationInsightsTransportOptions;
223
+ };
224
+
225
+ declare const createApplicationInsightsTransport: (options: CreateApplicationInsightsTransportOptions) => TransportStream;
226
+
227
+ declare const createTelemetryHandler: (options: CreateTelemetryHandlerOptions) => TelemetryHandler;
228
+
229
+ declare const createWinstonLogger: (options: CreateWinstonLoggerOptions) => winston.Logger;
230
+
231
+ declare const isRunningInAzure: () => boolean;
232
+
233
+ declare const isRunningLocally: () => boolean;
234
+
235
+ export { ApplicationInsightsVersion, type CreateApplicationInsightsTransportOptions, type CreateTelemetryHandlerOptions, type CreateWinstonLoggerOptions, type IExceptionTelemetryFilter, type ITraceTelemetryFilter, type SeverityMapping, type TelemetryData, type TelemetryDataException, type TelemetryDataProperties, type TelemetryDataTrace, type TelemetryHandler, TelemetrySeverity, type WinstonColors, type WinstonLevels, createApplicationInsightsTransport, createTelemetryHandler, createWinstonLogger, isRunningInAzure, isRunningLocally };
package/dist/index.d.ts CHANGED
@@ -1,83 +1,235 @@
1
- import { Format } from 'logform';
2
- import * as winston from 'winston';
3
- import { config } from 'winston';
4
- import { TelemetryClient } from 'applicationinsightsv2';
5
- import { TraceTelemetry, ExceptionTelemetry } from 'applicationinsightsv2/out/Declarations/Contracts';
6
- import { TelemetryClient as TelemetryClient$1, TraceTelemetry as TraceTelemetry$1, ExceptionTelemetry as ExceptionTelemetry$1 } from 'applicationinsightsv3';
7
1
  import TransportStream from 'winston-transport';
2
+ import { Format, TimestampOptions, ColorizeOptions } from 'logform';
3
+ import { TraceTelemetry, ExceptionTelemetry } from 'applicationinsightsv2/out/Declarations/Contracts';
4
+ import { TraceTelemetry as TraceTelemetry$1, ExceptionTelemetry as ExceptionTelemetry$1 } from 'applicationinsightsv3';
5
+ import winston from 'winston';
8
6
 
9
- type PlainObject = Record<string, any>;
10
- type JsonValue = string | number | JsonObject | JsonValue[] | null;
11
- type JsonObject = {
12
- [key: string]: JsonValue;
13
- };
14
- type AzureLogLevels = {
15
- [key: string]: LogLevel;
16
- };
17
- declare enum LogLevel {
18
- Verbose = 0,
19
- Information = 1,
20
- Warning = 2,
21
- Error = 3,
22
- Critical = 4
23
- }
24
- type AzureInsightsClientOptions = {
25
- version: 2;
26
- client: TelemetryClient;
27
- filters?: ITelemetryFilterV2[];
7
+ declare enum TelemetrySeverity {
8
+ Verbose = "Verbose",
9
+ Information = "Information",
10
+ Warning = "Warning",
11
+ Error = "Error",
12
+ Critical = "Critical"
13
+ }
14
+ declare enum ApplicationInsightsVersion {
15
+ V2 = "2.x",
16
+ V3 = "3.x"
17
+ }
18
+
19
+ interface ITelemetryClientV2 {
20
+ trackTrace(telemetry: TraceTelemetry): void;
21
+ trackException(telemetry: ExceptionTelemetry): void;
22
+ }
23
+
24
+ interface ITelemetryClientV3 {
25
+ trackTrace(telemetry: TraceTelemetry$1): void;
26
+ trackException(telemetry: ExceptionTelemetry$1): void;
27
+ }
28
+
29
+ type TelemetryDataProperties = Record<string, unknown>;
30
+ interface TelemetryDataTrace {
31
+ message: string;
32
+ properties: TelemetryDataProperties;
33
+ severity: TelemetrySeverity;
34
+ }
35
+ interface TelemetryDataException {
36
+ exception: Error;
37
+ properties: TelemetryDataProperties;
38
+ }
39
+ interface TelemetryData {
40
+ trace: TelemetryDataTrace | null;
41
+ exceptions: TelemetryDataException[];
42
+ }
43
+ interface TelemetryHandler {
44
+ handleTelemetry: (telemetry: TelemetryData) => void;
45
+ }
46
+ interface SeverityMapping {
47
+ [level: string]: TelemetrySeverity;
48
+ }
49
+ type IsError = (obj: unknown) => obj is Error;
50
+ type ITraceTelemetryFilter = (trace: TelemetryDataTrace) => boolean;
51
+ type IExceptionTelemetryFilter = (exception: TelemetryDataException) => boolean;
52
+ /**
53
+ * Pass in either a TelemetryClient and the version of the Application Insights SDK,
54
+ * Or a TelemetryHandler.
55
+ */
56
+ type CreateTelemetryHandlerOptions = {
57
+ /**
58
+ * Telemetry client for `applicationinsights@2`
59
+ */
60
+ client: ITelemetryClientV2;
61
+ version: ApplicationInsightsVersion.V2;
28
62
  } | {
29
- version: 3;
30
- client: TelemetryClient$1;
31
- filters?: ITelemetryFilterV3[];
32
- };
33
- type AzureApplicationInsightsLoggerOptionsBase = AzureInsightsClientOptions & {
34
- silent?: boolean;
35
- sendErrorsAsExceptions?: boolean;
63
+ /**
64
+ * Telemetry client for `applicationinsights@3`
65
+ */
66
+ client: ITelemetryClientV3;
67
+ version: ApplicationInsightsVersion.V3;
68
+ } | {
69
+ telemetryHandler: TelemetryHandler;
70
+ version?: never;
36
71
  };
37
- type AzureApplicationInsightsLoggerOptions = AzureApplicationInsightsLoggerOptionsBase & {
38
- defaultLevel?: string;
39
- levels?: AzureLogLevels;
72
+ /**
73
+ * Configuration options for creating an Application Insights transport.
74
+ */
75
+ type CreateApplicationInsightsTransportOptions = {
76
+ /**
77
+ * Custom mapping from Winston log levels to Application Insights severity levels.
78
+ * If not provided, uses default mappings (error → Error, warn → Warning, info → Information, etc.).
79
+ * Custom levels fall back to the next available severity based on level priority.
80
+ */
81
+ severityMapping?: SeverityMapping;
82
+ /**
83
+ * Optional filter function called before sending traces to Application Insights.
84
+ * Return false to prevent the trace from being sent. Useful for filtering out verbose logs or specific patterns.
85
+ */
86
+ traceFilter?: ITraceTelemetryFilter;
87
+ /**
88
+ * Optional filter function called before sending exceptions to Application Insights.
89
+ * Return false to prevent the exception from being sent. Useful for filtering out known/expected errors.
90
+ */
91
+ exceptionFilter?: IExceptionTelemetryFilter;
92
+ /**
93
+ * Custom function to determine what objects should be treated as errors.
94
+ * Defaults to checking `obj instanceof Error`. Objects identified as errors are extracted from log
95
+ * parameters and sent as Application Insights exceptions. When the first parameter is an Error,
96
+ * only an exception is sent (no trace) to avoid duplicate telemetry.
97
+ */
98
+ isError?: IsError;
99
+ level?: string;
100
+ } & CreateTelemetryHandlerOptions;
101
+ interface WinstonLevels {
102
+ [levelName: string]: number;
103
+ }
104
+ interface WinstonColors {
105
+ [colorName: string]: string;
106
+ }
107
+ type WinstonTransportOptionsFormat = {
108
+ /**
109
+ * Output format for log messages.
110
+ * 'json' produces structured JSON output ({@link https://github.com/winstonjs/logform#json}),
111
+ * 'simple' produces human-readable text ({@link https://github.com/winstonjs/logform#simple}).
112
+ * @default 'json'
113
+ */
114
+ output?: 'json' | 'simple';
115
+ /**
116
+ * Whether to include error stack traces in log output ({@link https://github.com/winstonjs/logform#errors}).
117
+ * Use boolean for simple enable/disable, or object to control stack inclusion.
118
+ * @default { stack: true }
119
+ */
120
+ errors?: boolean | {
121
+ /**
122
+ * Whether to include stack traces when logging Error objects.
123
+ * @default true
124
+ */
125
+ stack?: boolean;
126
+ };
127
+ /**
128
+ * Whether to include timestamps in log output ({@link https://github.com/winstonjs/logform#timestamp}).
129
+ * Use boolean for default ISO format, or object to customise timestamp format.
130
+ * @default true
131
+ */
132
+ timestamp?: boolean | TimestampOptions;
133
+ /**
134
+ * Whether to colorize log output for terminal display ({@link https://github.com/winstonjs/logform#colorize}).
135
+ * When used with 'json' output, automatically unescapes ANSI color codes for proper display.
136
+ * @default true
137
+ */
138
+ colorize?: boolean | ColorizeOptions;
40
139
  };
41
- declare abstract class ITelemetryFilterV3 {
42
- filterTrace(trace: TraceTelemetry$1, client: TelemetryClient$1): boolean;
43
- filterException(trace: ExceptionTelemetry$1, client: TelemetryClient$1): boolean;
140
+ interface WinstonLoggerDefaults {
141
+ /**
142
+ * Minimum log level for the logger.
143
+ * @default 'info'
144
+ */
145
+ level?: string;
146
+ /**
147
+ * Default metadata to include with all log entries.
148
+ */
149
+ defaultMeta?: Record<string, unknown>;
44
150
  }
45
- declare abstract class ITelemetryFilterV2 {
46
- filterTrace(trace: TraceTelemetry, client: TelemetryClient): boolean;
47
- filterException(trace: ExceptionTelemetry, client: TelemetryClient): boolean;
151
+ interface WinstonBaseTransportOptions extends WinstonLoggerDefaults {
152
+ /**
153
+ * Whether this transport is enabled.
154
+ * @default true for insights transport, auto-detected for console (true locally, false in Azure)
155
+ */
156
+ enabled?: boolean;
157
+ }
158
+ interface WinstonConsoleTransportOptions extends WinstonBaseTransportOptions {
159
+ /**
160
+ * Format configuration for this transport.
161
+ * If provided as Format[] ({@link https://github.com/winstonjs/logform#formats}), it is used as-is without any additional processing.
162
+ * Use WinstonTransportOptionsFormat for simplified configuration with automatic format handling.
163
+ */
164
+ format?: Format[] | WinstonTransportOptionsFormat;
165
+ }
166
+ interface WinstonInsightsTransportOptions extends WinstonBaseTransportOptions {
167
+ }
168
+ interface WinstonLoggerOptions {
169
+ /**
170
+ * Silence the logger (no output).
171
+ * @default false
172
+ */
173
+ silent?: boolean;
174
+ /**
175
+ * Exit on error.
176
+ * @default true
177
+ */
178
+ exitOnError?: boolean | ((error: Error) => boolean);
179
+ /**
180
+ * Handle exceptions.
181
+ * @default false
182
+ */
183
+ handleExceptions?: boolean;
184
+ /**
185
+ * Handle rejections.
186
+ * @default false
187
+ */
188
+ handleRejections?: boolean;
48
189
  }
49
-
50
190
  type CreateWinstonLoggerOptions = {
51
- insights: AzureApplicationInsightsLoggerOptions;
52
- winston: {
53
- level?: string;
54
- levels?: config.AbstractConfigSetLevels;
55
- defaultMeta?: JsonObject;
56
- console: boolean;
57
- format?: Format[];
191
+ winston?: {
192
+ /**
193
+ * Custom log levels definition.
194
+ * @default winston.config.npm.levels
195
+ */
196
+ levels?: WinstonLevels;
197
+ /**
198
+ * Custom colors for log levels.
199
+ */
200
+ colors?: WinstonColors;
201
+ /**
202
+ * Additional winston logger options.
203
+ */
204
+ options?: WinstonLoggerOptions;
205
+ /**
206
+ * Default settings applied to the logger.
207
+ */
208
+ defaults?: WinstonLoggerDefaults;
209
+ /**
210
+ * Console transport configuration.
211
+ */
212
+ console?: WinstonConsoleTransportOptions;
213
+ /**
214
+ * Application Insights transport configuration.
215
+ * Format is managed automatically and cannot be overridden.
216
+ */
217
+ insights?: WinstonInsightsTransportOptions;
58
218
  };
219
+ /**
220
+ * Application Insights transport configuration (required).
221
+ */
222
+ insights: CreateApplicationInsightsTransportOptions;
59
223
  };
60
224
 
225
+ declare const createApplicationInsightsTransport: (options: CreateApplicationInsightsTransportOptions) => TransportStream;
226
+
227
+ declare const createTelemetryHandler: (options: CreateTelemetryHandlerOptions) => TelemetryHandler;
228
+
61
229
  declare const createWinstonLogger: (options: CreateWinstonLoggerOptions) => winston.Logger;
62
230
 
63
231
  declare const isRunningInAzure: () => boolean;
64
232
 
65
233
  declare const isRunningLocally: () => boolean;
66
234
 
67
- declare class AzureApplicationInsightsLogger extends TransportStream {
68
- private readonly options;
69
- sendErrorsAsExceptions: boolean;
70
- readonly name: string;
71
- get client(): TelemetryClient$1 | TelemetryClient;
72
- constructor(options: AzureApplicationInsightsLoggerOptions);
73
- private handleTrace;
74
- private handleException;
75
- private trackTraceV2;
76
- private trackTraceV3;
77
- private trackExceptionV2;
78
- private trackExceptionV3;
79
- log(info: PlainObject, callback: () => void): void;
80
- private getSeverity;
81
- }
82
-
83
- export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions, type CreateWinstonLoggerOptions, ITelemetryFilterV2, ITelemetryFilterV3, createWinstonLogger, isRunningInAzure, isRunningLocally };
235
+ export { ApplicationInsightsVersion, type CreateApplicationInsightsTransportOptions, type CreateTelemetryHandlerOptions, type CreateWinstonLoggerOptions, type IExceptionTelemetryFilter, type ITraceTelemetryFilter, type SeverityMapping, type TelemetryData, type TelemetryDataException, type TelemetryDataProperties, type TelemetryDataTrace, type TelemetryHandler, TelemetrySeverity, type WinstonColors, type WinstonLevels, createApplicationInsightsTransport, createTelemetryHandler, createWinstonLogger, isRunningInAzure, isRunningLocally };
package/dist/index.js CHANGED
@@ -1 +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,i=(e,t)=>s(e,"name",{value:t,configurable:!0}),o=class{static{i(this,"ITelemetryFilterV3")}filterTrace(e,t){return!0}filterException(e,t){return!0}},n=class{static{i(this,"ITelemetryFilterV2")}filterTrace(e,t){return!0}filterException(e,t){return!0}},c={error:3,warn:2,http:1,info:1,verbose:0,debug:0,silly:0},l={v2:{0:0,1:1,2:2,3:3,4:4},v3:{0:"Verbose",1:"Information",2:"Warning",3:"Error",4:"Critical"}},a=i(e=>e instanceof Error,"isErrorLike"),p=i(e=>null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype,"isPlainObject"),f=i(e=>"object"!=typeof e||p(e)?e:{...e},"convertToPlainObject"),g=i(e=>{const t=["level","message"];return Object.keys(e).filter(e=>!t.includes(e)).reduce((t,r)=>(t[r]=f(e[r]),t),{})},"extractPropsFromInfo"),u=i(e=>{const t={message:e.message};for(const[r,s]of Object.entries(e))"stack"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=f(s));return t},"extractErrorPropsForTrace"),h=class extends r.default{constructor(e){super({level:e.defaultLevel??"info",silent:e.silent??!1}),this.options=e,this.name="applicationinsightslogger",this.sendErrorsAsExceptions=e.sendErrorsAsExceptions??!0}static{i(this,"AzureApplicationInsightsLogger")}sendErrorsAsExceptions;name;get client(){return this.options.client}handleTrace(e,t,r,s){const i=g(t);if(a(t)&&Object.assign(i,u(t)),Object.assign(i,s),3===this.options.version){const t={message:String(r),severity:l.v3[e],properties:i};this.trackTraceV3(t)}else{const t={message:String(r),severity:l.v2[e],properties:i};this.trackTraceV2(t)}}handleException(e,t,r){let s;if(a(e))s=e;else if(a(t))s=t;else{if(!a(r))return;s=r}const i={};"string"==typeof t&&s.message!==t&&(i.message=t),s!==r&&Object.assign(i,r),3===this.options.version?this.trackExceptionV3({exception:s,properties:i}):this.trackExceptionV2({exception:s,properties:i})}trackTraceV2(e){for(const t of this.options.filters??[])if(!t.filterTrace(e,this.options.client))return;this.options.client.trackTrace(e)}trackTraceV3(e){for(const t of this.options.filters??[])if(!t.filterTrace(e,this.options.client))return;this.options.client.trackTrace(e)}trackExceptionV2(e){for(const t of this.options.filters??[])if(!t.filterException(e,this.options.client))return;this.options.client.trackException(e)}trackExceptionV3(e){for(const t of this.options.filters??[])if(!t.filterException(e,this.options.client))return;this.options.client.trackException(e)}log(e,t){const{level:r,message:s}=e,i=this.getSeverity(r),o=Reflect.get(e,Symbol.for("splat"))??[],n=o.length?o[0]:{};this.handleTrace(i,e,s,n),this.sendErrorsAsExceptions&&i>=3&&this.handleException(e,s,n),t()}getSeverity(e){return(this.options.levels??c)[e]??this.options.defaultLevel??"info"}},v={error:0,warn:1,info:2,http:3,verbose:4,debug:5,silly:6},x=i(t=>{const r=t.winston.level??"info",s=t.winston.levels??v,i=[new h({...t.insights,defaultLevel:r})];t.winston.console&&i.push(new e.transports.Console({format:e.format.json(),stderrLevels:["error","crit","alert","emerg"],consoleWarnLevels:["warn","warning"]}));const o=e.format.combine(...t.winston.format??[],e.format.json());return e.createLogger({level:r,levels:s,format:o,transports:i,defaultMeta:t.winston.defaultMeta})},"createWinstonLogger"),E=i(()=>void 0!==process.env.WEBSITE_INSTANCE_ID,"isRunningInAzure"),m=i(()=>!E(),"isRunningLocally");exports.AzureApplicationInsightsLogger=h,exports.ITelemetryFilterV2=n,exports.ITelemetryFilterV3=o,exports.createWinstonLogger=x,exports.isRunningInAzure=E,exports.isRunningLocally=m;//# sourceMappingURL=index.js.map
1
+ import e from"winston-transport";import{SPLAT as t,MESSAGE as r}from"triple-beam";import{KnownSeverityLevel as o}from"applicationinsightsv3";import i from"winston";import{env as n}from"process";var s=Object.defineProperty,l=(e,t)=>s(e,"name",{value:t,configurable:!0}),a=(e=>(e.Verbose="Verbose",e.Information="Information",e.Warning="Warning",e.Error="Error",e.Critical="Critical",e))(a||{}),c=(e=>(e.V2="2.x",e.V3="3.x",e))(c||{}),p={error:"Error",warn:"Warning",info:"Information",verbose:"Verbose"},m=l(e=>null!=e&&"object"==typeof e&&void 0===e.constructor?{...e}:e,"convertNullPrototypeToRegularObject"),u=l((e,...t)=>{const r=["message","name","stack",...t],o={};for(const t of Object.keys(e))if(!r.includes(t)){const r=e[t];o[t]=m(r)}return o},"extractErrorProperties"),f=l((e,r)=>{const o=[];r(e)&&o.push({exception:e,properties:u(e,"level")});const i=e[t];if(null!=i)for(const e of i)r(e)&&o.push({exception:e,properties:u(e)});return o},"extractErrorsStep"),g=l(e=>{const r=String(e.message),o=e[t],i=o?.[0];if(void 0!==i?.message){const e=` ${i.message}`;if(r.endsWith(e))return r.slice(0,-e.length)}return r},"extractMessageStep"),y=l(e=>{if(null==e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t},"isPlainObject"),h=l(e=>{const t=Object.entries(e);if(0===t.length)return null;const r={};for(const[e,o]of t)r[e]=m(o);return r},"extractNonSymbolProps"),v=l((e,t)=>{if(t(e)){const{level:t,message:r,...o}=e;return h(o)}const{level:r,name:o,message:i,stack:n,cause:s,...l}=e;return h(l)},"extractDefaultMeta"),x=l((e,r=e=>e instanceof Error)=>{const o=v(e,r),i=e[t];if(null==i)return o??{};const n=i.filter(e=>!r(e))[0];return null!=n&&y(n)?{...o,...n}:o??{}},"extractPropertiesStep"),d=l((e,t,r)=>{const o=t[e.level];if(null!=o)return o;if(null!=r){const o=r[e.level];if(null!=o){const e=Object.entries(r).map(e=>({levelName:e[0],priority:e[1]})).filter(e=>o<e.priority).sort((e,t)=>e.priority-t.priority);for(const{levelName:r}of e){const e=t[r];if(e)return e}}}return"Verbose"},"extractSeverityStep"),b=l(e=>e instanceof Error,"isError"),E=class extends e{static{l(this,"ApplicationInsightsTransport")}telemetryHandler;options;levels;constructor(e){super({level:e.level}),this.options={telemetryHandler:e.telemetryHandler,severityMapping:e.severityMapping??p,isError:e.isError??b,traceFilter:e.traceFilter??(()=>!0),exceptionFilter:e.exceptionFilter??(()=>!0)},this.telemetryHandler=e.telemetryHandler}log(e,t){const r=this.getExceptions(e),o=this.getTrace(e,r);this.telemetryHandler.handleTelemetry({trace:o,exceptions:r}),t()}getTrace(e,t){const r=this.extractTrace(e,t);return null!=r&&this.options.traceFilter(r)?r:null}getExceptions(e){return f(e,this.options.isError).filter(this.options.exceptionFilter)}extractTrace(e,t){if(t.length>0&&this.options.isError(e))return null;return{message:g(e),properties:x(e,this.options.isError),severity:d(e,this.options.severityMapping,this.levels)}}},w=class{static{l(this,"ApplicationInsightsV2TelemetryHandler")}client;severityMapping={Verbose:0,Information:1,Warning:2,Error:3,Critical:4};constructor(e){this.client=e.client}handleTelemetry(e){if(null!=e.trace){const t={message:e.trace.message,severity:this.mapSeverity(e.trace.severity),properties:e.trace.properties};this.client.trackTrace(t)}for(const t of e.exceptions){const e={exception:t.exception,properties:t.properties};this.client.trackException(e)}}mapSeverity(e){return this.severityMapping[e]}},j=class{static{l(this,"ApplicationInsightsV3TelemetryHandler")}client;severityMapping={Verbose:o.Verbose,Information:o.Information,Warning:o.Warning,Error:o.Error,Critical:o.Critical};constructor(e){this.client=e.client}handleTelemetry(e){if(null!=e.trace){const t={message:e.trace.message,severity:this.mapSeverity(e.trace.severity),properties:e.trace.properties};this.client.trackTrace(t)}for(const t of e.exceptions){const e={exception:t.exception,properties:t.properties};this.client.trackException(e)}}mapSeverity(e){return this.severityMapping[e]}},T=l(e=>{switch(e.version){case"2.x":return new w({client:e.client});case"3.x":return new j({client:e.client});default:return e.telemetryHandler}},"createTelemetryHandler"),F=l(e=>{const t=T(e);return new E({telemetryHandler:t,severityMapping:e.severityMapping,exceptionFilter:e.exceptionFilter,traceFilter:e.traceFilter,isError:e.isError,level:e.level})},"createApplicationInsightsTransport"),M=l(e=>e[r].replaceAll(/\\u001b/g,""),"unescapeColorCodes"),I=l(()=>i.format.printf(M),"unescapeColorCodesFormat"),S=l(e=>{if(Array.isArray(e))return i.format.combine(...e);const t=[];return!0===e.timestamp?t.push(i.format.timestamp()):"object"==typeof e.timestamp&&t.push(i.format.timestamp(e.timestamp)),!0===e.errors?t.push(i.format.errors({stack:!0})):"object"==typeof e.errors&&t.push(i.format.errors(e.errors)),!0===e.colorize?t.push(i.format.colorize({all:!0})):"object"==typeof e.colorize&&t.push(i.format.colorize(e.colorize)),"simple"===e.output&&t.push(i.format.simple()),"json"===e.output&&(t.push(i.format.json()),!0!==e.colorize&&"object"!=typeof e.colorize||t.push(I())),i.format.combine(...t)},"createWinstonFormat"),H=l(()=>void 0!==n.WEBSITE_INSTANCE_ID,"isRunningInAzure"),A=l(()=>!H(),"isRunningLocally"),C=l(e=>{const{severityMapping:t,exceptionFilter:r,traceFilter:o,isError:n,...s}=e.insights,l=T(s),a=[];if(e.winston?.console?.enabled??A()){let t;if(Array.isArray(e.winston?.console?.format))t=e.winston.console.format;else{const r=e.winston?.console?.format??{};t={output:r.output??"json",timestamp:r.timestamp??!0,errors:r.errors??{stack:!0},colorize:r.colorize??!0}}const r=S(t);a.push(new i.transports.Console({format:r,level:e.winston?.console?.level,stderrLevels:["error","crit","alert","emerg"],consoleWarnLevels:["warn","warning"]}))}if(e.winston?.insights?.enabled??!0){const i=F({telemetryHandler:l,severityMapping:t,exceptionFilter:r,traceFilter:o,isError:n,level:e.winston?.insights?.level});a.push(i)}const c=e.winston?.defaults?.level??"info",p=e.winston?.levels??i.config.npm.levels;return i.createLogger({...e.winston?.options,level:c,levels:p,transports:a,defaultMeta:e.winston?.defaults?.defaultMeta})},"createWinstonLogger");export{c as ApplicationInsightsVersion,a as TelemetrySeverity,F as createApplicationInsightsTransport,T as createTelemetryHandler,C as createWinstonLogger,H as isRunningInAzure,A as isRunningLocally};//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts","../src/logLevels.ts","../src/winston-azure-application-insights.ts","../src/createWinstonLogger.ts","../src/isRunningInAzure.ts","../src/isRunningLocally.ts"],"names":["TransportStream","transports","format","createLogger"],"mappings":";;;;AAqDO,IAAe,qBAAf,MAAkC;AAAA,EArDzC;AAqDyC,IAAA,MAAA,CAAA,IAAA,EAAA,oBAAA,CAAA;AAAA;AAAA,EAChC,WAAA,CAAY,OAAyB,MAAA,EAAoC;AAC9E,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EACO,eAAA,CAAgB,OAA6B,MAAA,EAAoC;AACtF,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AACO,IAAe,qBAAf,MAAkC;AAAA,EA7DzC;AA6DyC,IAAA,MAAA,CAAA,IAAA,EAAA,oBAAA,CAAA;AAAA;AAAA,EAChC,WAAA,CAAY,OAAyB,MAAA,EAAoC;AAC9E,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EACO,eAAA,CAAgB,OAA6B,MAAA,EAAoC;AACtF,IAAA,OAAO,IAAA;AAAA,EACT;AACF;;;AClEO,IAAM,gBAAA,GAAmC;AAAA,EAC9C,KAAA,EAAA,CAAA;AAAA,EACA,IAAA,EAAA,CAAA;AAAA,EACA,IAAA,EAAA,CAAA;AAAA,EACA,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A,EAAA,MAAM,OAAA,GAAUA,cAAA,CAAO,OAAA,CAAQ,GAAI,OAAA,CAAQ,OAAA,CAAQ,MAAA,IAAU,EAAC,EAAIA,cAAA,CAAO,IAAA,EAAM,CAAA;AAE/E,EAAA,OAAOC,oBAAA,CAAa;AAAA,IAClB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,EAAQ,OAAA;AAAA,IACR,UAAA,EAAY,WAAA;AAAA,IACZ,WAAA,EAAa,QAAQ,OAAA,CAAQ;AAAA,GAC9B,CAAA;AACH,CAAA,EA9BmC,qBAAA;;;ACf5B,IAAM,mCAAmB,MAAA,CAAA,MAAM;AACpC,EAAA,OAAO,OAAA,CAAQ,IAAI,mBAAA,KAAwB,MAAA;AAC7C,CAAA,EAFgC,kBAAA;;;ACEzB,IAAM,mCAAmB,MAAA,CAAA,MAAM;AACpC,EAAA,OAAO,CAAC,gBAAA,EAAiB;AAC3B,CAAA,EAFgC,kBAAA","file":"index.js","sourcesContent":["import type { TelemetryClient as TelemetryClientV2 } from 'applicationinsightsv2';\nimport type { ExceptionTelemetry as ExceptionTelemetryV2, TraceTelemetry as TraceTelemetryV2 } from 'applicationinsightsv2/out/Declarations/Contracts';\nimport type { ExceptionTelemetry as ExceptionTelemetryV3, TelemetryClient as TelemetryClientV3, TraceTelemetry as TraceTelemetryV3 } from 'applicationinsightsv3';\n\nexport type PlainObject = Record<string, any>;\n\nexport type NodeClient = TelemetryClientV2 | TelemetryClientV3;\n\nexport type JsonValue = string | number | JsonObject | JsonValue[] | null;\nexport type JsonObject = {\n [key: string]: JsonValue;\n};\n\nexport type AzureLogLevels = {\n [key: string]: LogLevel;\n};\n\nexport enum LogLevel {\n Verbose = 0,\n Information = 1,\n Warning = 2,\n Error = 3,\n Critical = 4,\n}\n\nexport type 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: LogLevel;\n properties: PlainObject;\n};\n\nexport type AzureApplicationInsightsLoggerOptionsBase = AzureInsightsClientOptions & {\n silent?: boolean;\n sendErrorsAsExceptions?: boolean;\n};\n\nexport type AzureApplicationInsightsLoggerOptions = AzureApplicationInsightsLoggerOptionsBase & {\n defaultLevel?: string;\n levels?: AzureLogLevels;\n};\n\nexport abstract class ITelemetryFilterV3 {\n public filterTrace(trace: TraceTelemetryV3, client: TelemetryClientV3): boolean {\n return true;\n }\n public filterException(trace: ExceptionTelemetryV3, 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: ExceptionTelemetryV2, client: TelemetryClientV2): boolean {\n return true;\n }\n}\n","import { type AzureLogLevels, LogLevel } from './types';\n\nexport const defaultLogLevels: AzureLogLevels = {\n error: LogLevel.Error,\n warn: LogLevel.Warning,\n http: LogLevel.Information,\n info: LogLevel.Information,\n verbose: LogLevel.Verbose,\n debug: LogLevel.Verbose,\n silly: LogLevel.Verbose,\n};\n","import type { TelemetryClient as TelemetryClientV2 } from 'applicationinsightsv2';\nimport type { ExceptionTelemetry as ExceptionTelemetryV2, SeverityLevel as KnownSeverityLevelV2, TraceTelemetry as TraceTelemetryV2 } from 'applicationinsightsv2/out/Declarations/Contracts';\nimport type { ExceptionTelemetry as ExceptionTelemetryV3, KnownSeverityLevel as KnownSeverityLevelV3, TelemetryClient as TelemetryClientV3, TraceTelemetry as TraceTelemetryV3 } from 'applicationinsightsv3';\nimport TransportStream from 'winston-transport';\nimport { defaultLogLevels } from './logLevels';\nimport { type AzureApplicationInsightsLoggerOptions, type AzureLogLevels, type ITelemetryFilterV2, type ITelemetryFilterV3, LogLevel, type PlainObject } from './types';\n\nconst severityLevels = {\n v2: {\n [LogLevel.Verbose]: 0,\n [LogLevel.Information]: 1,\n [LogLevel.Warning]: 2,\n [LogLevel.Error]: 3,\n [LogLevel.Critical]: 4,\n } satisfies Record<LogLevel, KnownSeverityLevelV2>,\n v3: {\n [LogLevel.Verbose]: 'Verbose' as KnownSeverityLevelV3,\n [LogLevel.Information]: 'Information' as KnownSeverityLevelV3,\n [LogLevel.Warning]: 'Warning' as KnownSeverityLevelV3,\n [LogLevel.Error]: 'Error' as KnownSeverityLevelV3,\n [LogLevel.Critical]: 'Critical' as KnownSeverityLevelV3,\n } satisfies Record<LogLevel, KnownSeverityLevelV3>,\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 return isPlainObject(obj) ? obj : { ...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 props[key] = convertToPlainObject(info[key]);\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\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.defaultLevel ?? 'info', silent: options.silent ?? false });\n this.name = 'applicationinsightslogger';\n this.sendErrorsAsExceptions = options.sendErrorsAsExceptions ?? true;\n }\n\n private handleTrace(severity: LogLevel, info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const traceProps = extractPropsFromInfo(info);\n\n if (isErrorLike(info)) {\n Object.assign(traceProps, extractErrorPropsForTrace(info));\n }\n\n Object.assign(traceProps, logMeta);\n\n if (this.options.version === 3) {\n const telemetry: TraceTelemetryV3 = {\n message: String(message),\n severity: severityLevels.v3[severity],\n properties: traceProps,\n };\n this.trackTraceV3(telemetry);\n } else {\n const telemetry: TraceTelemetryV2 = {\n message: String(message),\n severity: severityLevels.v2[severity],\n properties: traceProps,\n };\n this.trackTraceV2(telemetry);\n }\n }\n\n private handleException(info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\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 return;\n }\n\n const exceptionProps: PlainObject = {};\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 if (this.options.version === 3) {\n this.trackExceptionV3({ exception, properties: exceptionProps });\n } else {\n this.trackExceptionV2({ exception, properties: exceptionProps });\n }\n }\n\n private trackTraceV2(telemetry: TraceTelemetryV2): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV2[]) {\n if (!f.filterTrace(telemetry, this.options.client as TelemetryClientV2)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV2).trackTrace(telemetry);\n }\n\n private trackTraceV3(telemetry: TraceTelemetryV3): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV3[]) {\n if (!f.filterTrace(telemetry, this.options.client as TelemetryClientV3)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV3).trackTrace(telemetry);\n }\n\n private trackExceptionV2(telemetry: ExceptionTelemetryV2): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV2[]) {\n if (!f.filterException(telemetry, this.options.client as TelemetryClientV2)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV2).trackException(telemetry);\n }\n\n private trackExceptionV3(telemetry: ExceptionTelemetryV3): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV3[]) {\n if (!f.filterException(telemetry, this.options.client as TelemetryClientV3)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV3).trackException(telemetry);\n }\n\n override log(info: PlainObject, callback: () => void): void {\n const { level, message } = info;\n const severity = this.getSeverity(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 >= LogLevel.Error) {\n this.handleException(info, message, logMeta);\n }\n\n callback();\n }\n\n private getSeverity(level: string) {\n return (this.options.levels ?? defaultLogLevels)[level] ?? this.options.defaultLevel ?? 'info';\n }\n}\n","import { createLogger, format, transports } from 'winston';\nimport type TransportStream from 'winston-transport';\nimport type { CreateWinstonLoggerOptions } from './CreateWinstonLoggerOptions';\nimport { AzureApplicationInsightsLogger } from './winston-azure-application-insights';\n\nconst npmLevels = {\n error: 0,\n warn: 1,\n info: 2,\n http: 3,\n verbose: 4,\n debug: 5,\n silly: 6,\n};\n\nexport const createWinstonLogger = (options: CreateWinstonLoggerOptions) => {\n const level = options.winston.level ?? 'info';\n const levels = options.winston.levels ?? npmLevels;\n\n const _transports: TransportStream[] = [\n new AzureApplicationInsightsLogger({\n ...options.insights,\n defaultLevel: level,\n }),\n ];\n\n if (options.winston.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.winston.format ?? []), format.json());\n\n return createLogger({\n level,\n levels,\n format: _format,\n transports: _transports,\n defaultMeta: options.winston.defaultMeta,\n });\n};\n","export const isRunningInAzure = () => {\n return process.env.WEBSITE_INSTANCE_ID !== undefined;\n};\n","import { isRunningInAzure } from './isRunningInAzure';\n\nexport const isRunningLocally = () => {\n return !isRunningInAzure();\n};\n"]}
1
+ {"version":3,"sources":["../src/public/enums.ts","../src/private/consts.ts","../src/private/convertNullPrototypeToRegularObject.ts","../src/private/extractErrorsStep.ts","../src/private/extractMessageStep.ts","../src/private/isPlainObject.ts","../src/private/extractPropertiesStep.ts","../src/private/extractSeverityStep.ts","../src/private/isError.ts","../src/private/ApplicationInsightsTransport.ts","../src/private/ApplicationInsightsV2TelemetryHandler.ts","../src/private/ApplicationInsightsV3TelemetryHandler.ts","../src/public/createTelemetryHandler.ts","../src/public/createApplicationInsightsTransport.ts","../src/private/createWinstonFormat.ts","../src/public/isRunningInAzure.ts","../src/public/isRunningLocally.ts","../src/public/createWinstonLogger.ts"],"names":["TelemetrySeverity","ApplicationInsightsVersion","isError","SPLAT","level","message","rest","winston"],"mappings":";;;;AAAO,IAAK,iBAAA,qBAAAA,kBAAAA,KAAL;AACL,EAAAA,mBAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,mBAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,mBAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,mBAAA,OAAA,CAAA,GAAQ,OAAA;AACR,EAAAA,mBAAA,UAAA,CAAA,GAAW,UAAA;AALD,EAAA,OAAAA,kBAAAA;AAAA,CAAA,EAAA,iBAAA,IAAA,EAAA;AAQL,IAAK,0BAAA,qBAAAC,2BAAAA,KAAL;AACL,EAAAA,4BAAA,IAAA,CAAA,GAAK,KAAA;AACL,EAAAA,4BAAA,IAAA,CAAA,GAAK,KAAA;AAFK,EAAA,OAAAA,2BAAAA;AAAA,CAAA,EAAA,0BAAA,IAAA,EAAA;;;ACLL,IAAM,sBAAA,GAA0C;AAAA,EACrD,KAAA,EAAA,OAAA;AAAA,EACA,IAAA,EAAA,SAAA;AAAA,EACA,IAAA,EAAA,aAAA;AAAA,EACA,OAAA,EAAA,SAAA;AACF,CAAA;;;ACHO,IAAM,mCAAA,2BAAuC,KAA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,IAAIK,OAAAA,CAAQ,UAAA,CAAW,OAAA,CAAQ;AAAA,QAC7B,MAAA,EAAQ,aAAA;AAAA,QACR,KAAA,EAAO,OAAA,CAAQ,OAAA,EAAS,OAAA,EAAS,KAAA;AAAA,QACjC,YAAA,EAAc,CAAC,OAAA,EAAS,MAAA,EAAQ,SAAS,OAAO,CAAA;AAAA,QAChD,iBAAA,EAAmB,CAAC,MAAA,EAAQ,SAAS;AAAA,OACtC;AAAA,KACH;AAAA,EACF;AAGA,EAAA,MAAM,eAAA,GAAkB,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU,OAAA,IAAW,IAAA;AAC9D,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,MAAM,YAAY,kCAAA,CAAmC;AAAA,MACnD,gBAAA;AAAA,MACA,eAAA;AAAA,MACA,eAAA;AAAA,MACA,WAAA;AAAA,MACA,OAAA,EAAAL,QAAAA;AAAA,MACA,KAAA,EAAO,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU;AAAA,KACnC,CAAA;AACD,IAAA,UAAA,CAAW,KAAK,SAAS,CAAA;AAAA,EAC3B;AAGA,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU,KAAA,IAAS,MAAA;AAClD,EAAA,MAAM,SAAS,OAAA,CAAQ,OAAA,EAAS,MAAA,IAAUK,OAAAA,CAAQ,OAAO,GAAA,CAAI,MAAA;AAG7D,EAAA,OAAOA,QAAQ,YAAA,CAAa;AAAA,IAC1B,GAAG,QAAQ,OAAA,EAAS,OAAA;AAAA,IACpB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA,WAAA,EAAa,OAAA,CAAQ,OAAA,EAAS,QAAA,EAAU;AAAA,GACzC,CAAA;AACH,CAAA,EA7DmC,qBAAA","file":"index.js","sourcesContent":["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","/**\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 { 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","import { SPLAT } from 'triple-beam';\nimport type { WinstonInfo } from './types';\n\nexport const extractMessageStep = (info: WinstonInfo): string => {\n const messageAsString = String(info.message);\n\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\n if (messageAsString.endsWith(expectedSuffix)) {\n return messageAsString.slice(0, -expectedSuffix.length);\n }\n }\n\n return messageAsString;\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 { 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","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 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","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 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","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\n // Default format for main logger (applied to all transports)\n return winston.createLogger({\n ...options.winston?.options,\n level,\n levels,\n transports,\n defaultMeta: options.winston?.defaults?.defaultMeta,\n });\n};\n"]}
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "@shellicar/winston-azure-application-insights",
3
- "version": "5.1.0",
3
+ "version": "6.0.0-preview.2",
4
4
  "private": false,
5
5
  "description": "Azure Application Insights transport for Winston",
6
+ "type": "module",
6
7
  "files": [
7
8
  "dist"
8
9
  ],
9
- "main": "./dist/index.js",
10
- "module": "./dist/index.mjs",
10
+ "main": "./dist/index.cjs",
11
+ "module": "./dist/index.js",
11
12
  "types": "./dist/index.d.ts",
12
13
  "exports": {
13
14
  "require": {
14
15
  "types": "./dist/index.d.ts",
15
- "default": "./dist/index.js"
16
+ "default": "./dist/index.cjs"
16
17
  },
17
18
  "import": {
18
- "types": "./dist/index.d.mts",
19
- "default": "./dist/index.mjs"
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
20
21
  }
21
22
  },
22
23
  "repository": {
@@ -29,69 +30,51 @@
29
30
  "insights",
30
31
  "logging"
31
32
  ],
32
- "author": "Marco Braga (Bragma)",
33
+ "author": "Stephen Hellicar",
33
34
  "contributors": [
34
- {
35
- "name": "Will Morgan",
36
- "email": "jobs+npm@willmorgan.co.uk",
37
- "url": "http://willmorgan.co.uk"
38
- },
39
35
  {
40
36
  "name": "Stephen Hellicar",
41
- "email": "shellicar@gmail.com"
37
+ "email": "shellicar@gmail.com",
38
+ "url": "https://stephen-hellicar.com.au/"
42
39
  }
43
40
  ],
44
41
  "license": "MIT",
45
42
  "devDependencies": {
46
- "@biomejs/biome": "^1.9.3",
47
- "@types/node": "^24.1.0",
48
- "@typescript-eslint/eslint-plugin": "^8.38.0",
49
- "@typescript-eslint/parser": "^8.38.0",
50
- "eslint-config-airbnb-base": "^15.0.0",
51
- "eslint-plugin-import": "^2.32.0",
52
- "globals": "^16.3.0",
53
- "lefthook": "^1.12.2",
43
+ "@types/node": "^24.3.0",
44
+ "@types/triple-beam": "^1.3.5",
45
+ "@vitest/coverage-v8": "^3.2.4",
54
46
  "logform": "^2.7.0",
55
- "npm-check-updates": "^18.0.2",
56
- "npm-run-all2": "^8.0.4",
57
- "syncpack": "^13.0.4",
58
47
  "terser": "^5.43.1",
59
48
  "testdouble": "^3.20.2",
49
+ "triple-beam": "^1.4.1",
60
50
  "tsup": "^8.5.0",
61
- "tsx": "^4.20.3",
51
+ "tsx": "^4.20.5",
62
52
  "typescript": "^5.9.2",
63
53
  "vitest": "^3.2.4",
64
- "winston": "^3.17.0"
54
+ "winston": "^3.17.0",
55
+ "winston-transport": "^4.9.0"
65
56
  },
66
57
  "optionalDependencies": {
67
58
  "applicationinsightsv2": "npm:applicationinsights@^2",
68
- "applicationinsightsv3": "npm:applicationinsights@^3"
59
+ "applicationinsightsv3": "npm:applicationinsights@^3",
60
+ "applicationinsightsv34": "npm:applicationinsights@^3.4"
69
61
  },
70
62
  "bugs": {
71
63
  "url": "https://github.com/shellicar/winston-azure-application-insights/issues"
72
64
  },
73
65
  "homepage": "https://github.com/shellicar/winston-azure-application-insights#readme",
74
66
  "peerDependencies": {
67
+ "triple-beam": "^1.4.1",
75
68
  "winston": "^3.0.0",
76
69
  "winston-transport": "^4.0.0"
77
70
  },
78
- "dependencies": {
79
- "winston-transport": "^4.9.0"
80
- },
81
71
  "scripts": {
82
72
  "demo": "tsx demo.ts",
83
73
  "build": "tsup-node",
84
74
  "watch": "tsup-node --watch",
85
- "lint": "biome lint",
86
- "format": "biome format",
87
- "check": "biome check",
88
- "ci": "biome ci --diagnostic-level=error",
89
- "ci:fix": "biome check --diagnostic-level=error --fix",
75
+ "type-check": "tsc -p tsconfig.check.json",
90
76
  "test": "vitest run",
91
- "list-mismatches": "syncpack list-mismatches",
92
- "fix-mismatches": "syncpack fix-mismatches",
93
- "updates": "npm-check-updates",
94
- "postinstall": "lefthook install",
95
- "verify-version": "./scripts/verify-version.sh"
77
+ "coverage": "vitest run --coverage",
78
+ "test:coverage": "vitest run --coverage"
96
79
  }
97
80
  }
package/dist/index.d.mts DELETED
@@ -1,83 +0,0 @@
1
- import { Format } from 'logform';
2
- import * as winston from 'winston';
3
- import { config } from 'winston';
4
- import { TelemetryClient } from 'applicationinsightsv2';
5
- import { TraceTelemetry, ExceptionTelemetry } from 'applicationinsightsv2/out/Declarations/Contracts';
6
- import { TelemetryClient as TelemetryClient$1, TraceTelemetry as TraceTelemetry$1, ExceptionTelemetry as ExceptionTelemetry$1 } from 'applicationinsightsv3';
7
- import TransportStream from 'winston-transport';
8
-
9
- type PlainObject = Record<string, any>;
10
- type JsonValue = string | number | JsonObject | JsonValue[] | null;
11
- type JsonObject = {
12
- [key: string]: JsonValue;
13
- };
14
- type AzureLogLevels = {
15
- [key: string]: LogLevel;
16
- };
17
- declare enum LogLevel {
18
- Verbose = 0,
19
- Information = 1,
20
- Warning = 2,
21
- Error = 3,
22
- Critical = 4
23
- }
24
- type AzureInsightsClientOptions = {
25
- version: 2;
26
- client: TelemetryClient;
27
- filters?: ITelemetryFilterV2[];
28
- } | {
29
- version: 3;
30
- client: TelemetryClient$1;
31
- filters?: ITelemetryFilterV3[];
32
- };
33
- type AzureApplicationInsightsLoggerOptionsBase = AzureInsightsClientOptions & {
34
- silent?: boolean;
35
- sendErrorsAsExceptions?: boolean;
36
- };
37
- type AzureApplicationInsightsLoggerOptions = AzureApplicationInsightsLoggerOptionsBase & {
38
- defaultLevel?: string;
39
- levels?: AzureLogLevels;
40
- };
41
- declare abstract class ITelemetryFilterV3 {
42
- filterTrace(trace: TraceTelemetry$1, client: TelemetryClient$1): boolean;
43
- filterException(trace: ExceptionTelemetry$1, client: TelemetryClient$1): boolean;
44
- }
45
- declare abstract class ITelemetryFilterV2 {
46
- filterTrace(trace: TraceTelemetry, client: TelemetryClient): boolean;
47
- filterException(trace: ExceptionTelemetry, client: TelemetryClient): boolean;
48
- }
49
-
50
- type CreateWinstonLoggerOptions = {
51
- insights: AzureApplicationInsightsLoggerOptions;
52
- winston: {
53
- level?: string;
54
- levels?: config.AbstractConfigSetLevels;
55
- defaultMeta?: JsonObject;
56
- console: boolean;
57
- format?: Format[];
58
- };
59
- };
60
-
61
- declare const createWinstonLogger: (options: CreateWinstonLoggerOptions) => winston.Logger;
62
-
63
- declare const isRunningInAzure: () => boolean;
64
-
65
- declare const isRunningLocally: () => boolean;
66
-
67
- declare class AzureApplicationInsightsLogger extends TransportStream {
68
- private readonly options;
69
- sendErrorsAsExceptions: boolean;
70
- readonly name: string;
71
- get client(): TelemetryClient$1 | TelemetryClient;
72
- constructor(options: AzureApplicationInsightsLoggerOptions);
73
- private handleTrace;
74
- private handleException;
75
- private trackTraceV2;
76
- private trackTraceV3;
77
- private trackExceptionV2;
78
- private trackExceptionV3;
79
- log(info: PlainObject, callback: () => void): void;
80
- private getSeverity;
81
- }
82
-
83
- export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions, type CreateWinstonLoggerOptions, ITelemetryFilterV2, ITelemetryFilterV3, createWinstonLogger, isRunningInAzure, isRunningLocally };
package/dist/index.mjs DELETED
@@ -1 +0,0 @@
1
- import{transports as e,format as t,createLogger as r}from"winston";import s from"winston-transport";var i=Object.defineProperty,o=(e,t)=>i(e,"name",{value:t,configurable:!0}),n=class{static{o(this,"ITelemetryFilterV3")}filterTrace(e,t){return!0}filterException(e,t){return!0}},c=class{static{o(this,"ITelemetryFilterV2")}filterTrace(e,t){return!0}filterException(e,t){return!0}},l={error:3,warn:2,http:1,info:1,verbose:0,debug:0,silly:0},a={v2:{0:0,1:1,2:2,3:3,4:4},v3:{0:"Verbose",1:"Information",2:"Warning",3:"Error",4:"Critical"}},p=o(e=>e instanceof Error,"isErrorLike"),f=o(e=>null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype,"isPlainObject"),h=o(e=>"object"!=typeof e||f(e)?e:{...e},"convertToPlainObject"),g=o(e=>{const t=["level","message"];return Object.keys(e).filter(e=>!t.includes(e)).reduce((t,r)=>(t[r]=h(e[r]),t),{})},"extractPropsFromInfo"),u=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]=h(s));return t},"extractErrorPropsForTrace"),v=class extends s{constructor(e){super({level:e.defaultLevel??"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 i=g(t);if(p(t)&&Object.assign(i,u(t)),Object.assign(i,s),3===this.options.version){const t={message:String(r),severity:a.v3[e],properties:i};this.trackTraceV3(t)}else{const t={message:String(r),severity:a.v2[e],properties:i};this.trackTraceV2(t)}}handleException(e,t,r){let s;if(p(e))s=e;else if(p(t))s=t;else{if(!p(r))return;s=r}const i={};"string"==typeof t&&s.message!==t&&(i.message=t),s!==r&&Object.assign(i,r),3===this.options.version?this.trackExceptionV3({exception:s,properties:i}):this.trackExceptionV2({exception:s,properties:i})}trackTraceV2(e){for(const t of this.options.filters??[])if(!t.filterTrace(e,this.options.client))return;this.options.client.trackTrace(e)}trackTraceV3(e){for(const t of this.options.filters??[])if(!t.filterTrace(e,this.options.client))return;this.options.client.trackTrace(e)}trackExceptionV2(e){for(const t of this.options.filters??[])if(!t.filterException(e,this.options.client))return;this.options.client.trackException(e)}trackExceptionV3(e){for(const t of this.options.filters??[])if(!t.filterException(e,this.options.client))return;this.options.client.trackException(e)}log(e,t){const{level:r,message:s}=e,i=this.getSeverity(r),o=Reflect.get(e,Symbol.for("splat"))??[],n=o.length?o[0]:{};this.handleTrace(i,e,s,n),this.sendErrorsAsExceptions&&i>=3&&this.handleException(e,s,n),t()}getSeverity(e){return(this.options.levels??l)[e]??this.options.defaultLevel??"info"}},E={error:0,warn:1,info:2,http:3,verbose:4,debug:5,silly:6},m=o(s=>{const i=s.winston.level??"info",o=s.winston.levels??E,n=[new v({...s.insights,defaultLevel:i})];s.winston.console&&n.push(new e.Console({format:t.json(),stderrLevels:["error","crit","alert","emerg"],consoleWarnLevels:["warn","warning"]}));const c=t.combine(...s.winston.format??[],t.json());return r({level:i,levels:o,format:c,transports:n,defaultMeta:s.winston.defaultMeta})},"createWinstonLogger"),x=o(()=>void 0!==process.env.WEBSITE_INSTANCE_ID,"isRunningInAzure"),b=o(()=>!x(),"isRunningLocally");export{v as AzureApplicationInsightsLogger,c as ITelemetryFilterV2,n as ITelemetryFilterV3,m as createWinstonLogger,x as isRunningInAzure,b as isRunningLocally};//# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts","../src/logLevels.ts","../src/winston-azure-application-insights.ts","../src/createWinstonLogger.ts","../src/isRunningInAzure.ts","../src/isRunningLocally.ts"],"names":[],"mappings":";;;;AAqDO,IAAe,qBAAf,MAAkC;AAAA,EArDzC;AAqDyC,IAAA,MAAA,CAAA,IAAA,EAAA,oBAAA,CAAA;AAAA;AAAA,EAChC,WAAA,CAAY,OAAyB,MAAA,EAAoC;AAC9E,IAAA,OAAO,IAAA;AAAA,EACT;AAAA,EACO,eAAA,CAAgB,OAA6B,MAAA,EAAoC;AACtF,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AACO,IAAe,qBAAf,MAAkC;AAAA,EA7DzC;AA6DyC,IAAA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AAA,GACH;AAEA,EAAA,IAAI,OAAA,CAAQ,QAAQ,OAAA,EAAS;AAC3B,IAAA,WAAA,CAAY,IAAA;AAAA,MACV,IAAI,WAAW,OAAA,CAAQ;AAAA,QACrB,MAAA,EAAQ,OAAO,IAAA,EAAK;AAAA,QACpB,YAAA,EAAc,CAAC,OAAA,EAAS,MAAA,EAAQ,SAAS,OAAO,CAAA;AAAA,QAChD,iBAAA,EAAmB,CAAC,MAAA,EAAQ,SAAS;AAAA,OACtC;AAAA,KACH;AAAA,EACF;AAEA,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,GAAI,OAAA,CAAQ,OAAA,CAAQ,MAAA,IAAU,EAAC,EAAI,MAAA,CAAO,IAAA,EAAM,CAAA;AAE/E,EAAA,OAAO,YAAA,CAAa;AAAA,IAClB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA,EAAQ,OAAA;AAAA,IACR,UAAA,EAAY,WAAA;AAAA,IACZ,WAAA,EAAa,QAAQ,OAAA,CAAQ;AAAA,GAC9B,CAAA;AACH,CAAA,EA9BmC,qBAAA;;;ACf5B,IAAM,mCAAmB,MAAA,CAAA,MAAM;AACpC,EAAA,OAAO,OAAA,CAAQ,IAAI,mBAAA,KAAwB,MAAA;AAC7C,CAAA,EAFgC,kBAAA;;;ACEzB,IAAM,mCAAmB,MAAA,CAAA,MAAM;AACpC,EAAA,OAAO,CAAC,gBAAA,EAAiB;AAC3B,CAAA,EAFgC,kBAAA","file":"index.mjs","sourcesContent":["import type { TelemetryClient as TelemetryClientV2 } from 'applicationinsightsv2';\nimport type { ExceptionTelemetry as ExceptionTelemetryV2, TraceTelemetry as TraceTelemetryV2 } from 'applicationinsightsv2/out/Declarations/Contracts';\nimport type { ExceptionTelemetry as ExceptionTelemetryV3, TelemetryClient as TelemetryClientV3, TraceTelemetry as TraceTelemetryV3 } from 'applicationinsightsv3';\n\nexport type PlainObject = Record<string, any>;\n\nexport type NodeClient = TelemetryClientV2 | TelemetryClientV3;\n\nexport type JsonValue = string | number | JsonObject | JsonValue[] | null;\nexport type JsonObject = {\n [key: string]: JsonValue;\n};\n\nexport type AzureLogLevels = {\n [key: string]: LogLevel;\n};\n\nexport enum LogLevel {\n Verbose = 0,\n Information = 1,\n Warning = 2,\n Error = 3,\n Critical = 4,\n}\n\nexport type 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: LogLevel;\n properties: PlainObject;\n};\n\nexport type AzureApplicationInsightsLoggerOptionsBase = AzureInsightsClientOptions & {\n silent?: boolean;\n sendErrorsAsExceptions?: boolean;\n};\n\nexport type AzureApplicationInsightsLoggerOptions = AzureApplicationInsightsLoggerOptionsBase & {\n defaultLevel?: string;\n levels?: AzureLogLevels;\n};\n\nexport abstract class ITelemetryFilterV3 {\n public filterTrace(trace: TraceTelemetryV3, client: TelemetryClientV3): boolean {\n return true;\n }\n public filterException(trace: ExceptionTelemetryV3, 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: ExceptionTelemetryV2, client: TelemetryClientV2): boolean {\n return true;\n }\n}\n","import { type AzureLogLevels, LogLevel } from './types';\n\nexport const defaultLogLevels: AzureLogLevels = {\n error: LogLevel.Error,\n warn: LogLevel.Warning,\n http: LogLevel.Information,\n info: LogLevel.Information,\n verbose: LogLevel.Verbose,\n debug: LogLevel.Verbose,\n silly: LogLevel.Verbose,\n};\n","import type { TelemetryClient as TelemetryClientV2 } from 'applicationinsightsv2';\nimport type { ExceptionTelemetry as ExceptionTelemetryV2, SeverityLevel as KnownSeverityLevelV2, TraceTelemetry as TraceTelemetryV2 } from 'applicationinsightsv2/out/Declarations/Contracts';\nimport type { ExceptionTelemetry as ExceptionTelemetryV3, KnownSeverityLevel as KnownSeverityLevelV3, TelemetryClient as TelemetryClientV3, TraceTelemetry as TraceTelemetryV3 } from 'applicationinsightsv3';\nimport TransportStream from 'winston-transport';\nimport { defaultLogLevels } from './logLevels';\nimport { type AzureApplicationInsightsLoggerOptions, type AzureLogLevels, type ITelemetryFilterV2, type ITelemetryFilterV3, LogLevel, type PlainObject } from './types';\n\nconst severityLevels = {\n v2: {\n [LogLevel.Verbose]: 0,\n [LogLevel.Information]: 1,\n [LogLevel.Warning]: 2,\n [LogLevel.Error]: 3,\n [LogLevel.Critical]: 4,\n } satisfies Record<LogLevel, KnownSeverityLevelV2>,\n v3: {\n [LogLevel.Verbose]: 'Verbose' as KnownSeverityLevelV3,\n [LogLevel.Information]: 'Information' as KnownSeverityLevelV3,\n [LogLevel.Warning]: 'Warning' as KnownSeverityLevelV3,\n [LogLevel.Error]: 'Error' as KnownSeverityLevelV3,\n [LogLevel.Critical]: 'Critical' as KnownSeverityLevelV3,\n } satisfies Record<LogLevel, KnownSeverityLevelV3>,\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 return isPlainObject(obj) ? obj : { ...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 props[key] = convertToPlainObject(info[key]);\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\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.defaultLevel ?? 'info', silent: options.silent ?? false });\n this.name = 'applicationinsightslogger';\n this.sendErrorsAsExceptions = options.sendErrorsAsExceptions ?? true;\n }\n\n private handleTrace(severity: LogLevel, info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const traceProps = extractPropsFromInfo(info);\n\n if (isErrorLike(info)) {\n Object.assign(traceProps, extractErrorPropsForTrace(info));\n }\n\n Object.assign(traceProps, logMeta);\n\n if (this.options.version === 3) {\n const telemetry: TraceTelemetryV3 = {\n message: String(message),\n severity: severityLevels.v3[severity],\n properties: traceProps,\n };\n this.trackTraceV3(telemetry);\n } else {\n const telemetry: TraceTelemetryV2 = {\n message: String(message),\n severity: severityLevels.v2[severity],\n properties: traceProps,\n };\n this.trackTraceV2(telemetry);\n }\n }\n\n private handleException(info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\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 return;\n }\n\n const exceptionProps: PlainObject = {};\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 if (this.options.version === 3) {\n this.trackExceptionV3({ exception, properties: exceptionProps });\n } else {\n this.trackExceptionV2({ exception, properties: exceptionProps });\n }\n }\n\n private trackTraceV2(telemetry: TraceTelemetryV2): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV2[]) {\n if (!f.filterTrace(telemetry, this.options.client as TelemetryClientV2)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV2).trackTrace(telemetry);\n }\n\n private trackTraceV3(telemetry: TraceTelemetryV3): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV3[]) {\n if (!f.filterTrace(telemetry, this.options.client as TelemetryClientV3)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV3).trackTrace(telemetry);\n }\n\n private trackExceptionV2(telemetry: ExceptionTelemetryV2): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV2[]) {\n if (!f.filterException(telemetry, this.options.client as TelemetryClientV2)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV2).trackException(telemetry);\n }\n\n private trackExceptionV3(telemetry: ExceptionTelemetryV3): void {\n for (const f of (this.options.filters ?? []) as ITelemetryFilterV3[]) {\n if (!f.filterException(telemetry, this.options.client as TelemetryClientV3)) {\n return;\n }\n }\n (this.options.client as TelemetryClientV3).trackException(telemetry);\n }\n\n override log(info: PlainObject, callback: () => void): void {\n const { level, message } = info;\n const severity = this.getSeverity(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 >= LogLevel.Error) {\n this.handleException(info, message, logMeta);\n }\n\n callback();\n }\n\n private getSeverity(level: string) {\n return (this.options.levels ?? defaultLogLevels)[level] ?? this.options.defaultLevel ?? 'info';\n }\n}\n","import { createLogger, format, transports } from 'winston';\nimport type TransportStream from 'winston-transport';\nimport type { CreateWinstonLoggerOptions } from './CreateWinstonLoggerOptions';\nimport { AzureApplicationInsightsLogger } from './winston-azure-application-insights';\n\nconst npmLevels = {\n error: 0,\n warn: 1,\n info: 2,\n http: 3,\n verbose: 4,\n debug: 5,\n silly: 6,\n};\n\nexport const createWinstonLogger = (options: CreateWinstonLoggerOptions) => {\n const level = options.winston.level ?? 'info';\n const levels = options.winston.levels ?? npmLevels;\n\n const _transports: TransportStream[] = [\n new AzureApplicationInsightsLogger({\n ...options.insights,\n defaultLevel: level,\n }),\n ];\n\n if (options.winston.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.winston.format ?? []), format.json());\n\n return createLogger({\n level,\n levels,\n format: _format,\n transports: _transports,\n defaultMeta: options.winston.defaultMeta,\n });\n};\n","export const isRunningInAzure = () => {\n return process.env.WEBSITE_INSTANCE_ID !== undefined;\n};\n","import { isRunningInAzure } from './isRunningInAzure';\n\nexport const isRunningLocally = () => {\n return !isRunningInAzure();\n};\n"]}