@shellicar/winston-azure-application-insights 5.0.0
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 +21 -0
- package/README.md +147 -0
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Stephen Hellicar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
@shellicar/winston-azure-application-insights
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
## Update
|
|
5
|
+
|
|
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
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pnpm install @shellicar/winston-azure-application-insights
|
|
24
|
+
```
|
|
25
|
+
|
|
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:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { setup, defaultClient } from 'applicationinsights';
|
|
48
|
+
import { AzureApplicationInsightsLogger } from '@shellicar/winston-azure-application-insights';
|
|
49
|
+
|
|
50
|
+
setup().start();
|
|
51
|
+
|
|
52
|
+
const insightsLogger = new AzureApplicationInsightsLogger({
|
|
53
|
+
client: defaultClient,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
```cjs
|
|
57
|
+
const { setup, defaultClient } = require("applicationinsights");
|
|
58
|
+
const { AzureApplicationInsightsLogger } = require('@shellicar/winston-azure-application-insights');
|
|
59
|
+
|
|
60
|
+
setup(process.env.APPLICATIONINSIGHTS_CONNECTION_STRING).start();
|
|
61
|
+
|
|
62
|
+
const insightsLogger = new AzureApplicationInsightsLogger({
|
|
63
|
+
client: defaultClient,
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**I get an error when using this transport**
|
|
68
|
+
|
|
69
|
+
If you receive the error:
|
|
70
|
+
|
|
71
|
+
`No instrumentation key or connection string was provided to the Azure Monitor Exporter`
|
|
72
|
+
|
|
73
|
+
Then you didn't specify a suitable instrumentation key. See the section above.
|
|
74
|
+
|
|
75
|
+
`Error: @opentelemetry/api: Attempted duplicate registration of API: context`
|
|
76
|
+
|
|
77
|
+
This may be because your environment has already (maybe implicitly) loaded applicationinsights and called `.setup()`.
|
|
78
|
+
This happens if you are running an Azure Function App and have `APPLICATIONINSIGHTS_CONNECTION_STRING` set.
|
|
79
|
+
The best solution to this is to load `applicationinsights` and pass in `appInsights.defaultClient` using the `client`
|
|
80
|
+
option as per example.
|
|
81
|
+
|
|
82
|
+
**I'm seeing multiple traces with similar/identical messages**
|
|
83
|
+
|
|
84
|
+
`applicationinsights` deeply integrates into the `console` transports, and `winston` itself (via `diagnostic-channel`).
|
|
85
|
+
If you are integrating this transport, it's recommended to disable `diagnostic-channel` and console auto collection:
|
|
86
|
+
|
|
87
|
+
To control `diagnostic-channel`, [follow the guide in the main repository](https://github.com/Microsoft/ApplicationInsights-node.js#automatic-third-party-instrumentation).
|
|
88
|
+
|
|
89
|
+
It is recommended to use _only_ this transport where your application is running in production mode and needs to
|
|
90
|
+
stream data to Application Insights. In all other scenarios such as local debug and test suites, the console transport
|
|
91
|
+
(or similar) should suffice. This is to avoid polluting instances/unnecessary cost.
|
|
92
|
+
|
|
93
|
+
Despite this notice, to specifically disable console transport collection, use `.setAutoCollectConsole(false)`:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
setup().setAutoCollectConsole(false);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Options
|
|
100
|
+
|
|
101
|
+
* **level**: lowest logging level transport to be logged (default: `info`)
|
|
102
|
+
* **sendErrorsAsExceptions**: Boolean flag indicating whether to also track errors to the AI exceptions table.
|
|
103
|
+
See section below for more details (default: `true`).
|
|
104
|
+
|
|
105
|
+
**SDK integration options (required):**
|
|
106
|
+
|
|
107
|
+
* **client**: An existing App Insights client
|
|
108
|
+
|
|
109
|
+
## Log Levels
|
|
110
|
+
|
|
111
|
+
Supported log levels are:
|
|
112
|
+
|
|
113
|
+
Winston Level | App Insights level
|
|
114
|
+
---------------|------------------
|
|
115
|
+
error | error (3)
|
|
116
|
+
warn | warning (2)
|
|
117
|
+
info | informational (1)
|
|
118
|
+
verbose | verbose (0)
|
|
119
|
+
debug | verbose (0)
|
|
120
|
+
silly | verbose (0)
|
|
121
|
+
|
|
122
|
+
**All other possible levels, or custom levels, will default to `info`**
|
|
123
|
+
|
|
124
|
+
[0]: https://azure.microsoft.com/en-us/services/application-insights/
|
|
125
|
+
[1]: https://github.com/winstonjs/winston
|
|
126
|
+
|
|
127
|
+
## Error & Exception Logging: Exceptions vs. Traces
|
|
128
|
+
|
|
129
|
+
The Application Insights "exceptions" table allows you to see more detailed error information including the stack trace.
|
|
130
|
+
Therefore for all log events at severity level error or above, an exception is logged if the library detects that an
|
|
131
|
+
Error object has been passed.
|
|
132
|
+
The log event will still generate a trace with the correct severity level regardless of this setting, but please note
|
|
133
|
+
that any Error object will have its `stack` property omitted when sent to `trackTrace`.
|
|
134
|
+
All other properties are included.
|
|
135
|
+
|
|
136
|
+
This allows you to see clearly Azure Application Insights instead of having to access trace information manually and set
|
|
137
|
+
up alerts based on the related metrics.
|
|
138
|
+
|
|
139
|
+
How it works with `sendErrorsAsExceptions: true`:
|
|
140
|
+
|
|
141
|
+
* `logger.error('error message');` creates a trace with severity level 3; *no* exception is tracked
|
|
142
|
+
* `logger.error(new Error('error message'));` creates a trace with severity level 3, *and* an exception with the Error object as argument
|
|
143
|
+
* `logger.error('error message', new Error('error message'));` creates a trace with severity level 3, *and* an exception with the Error object as argument
|
|
144
|
+
* `logger.error(new Error('error message'), logContext);` creates a trace and exception and logContext is set to the customDimensions (properties) track* field
|
|
145
|
+
* `logger.info(new Error('error message'));` creates a trace with severity level 1; *no* exception is tracked
|
|
146
|
+
|
|
147
|
+
If you do not wish to track exceptions, you can set the option `sendErrorsAsExceptions: false` when configuring the transport.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("applicationinsights");function t(e){return e&&e.__esModule?e:{default:e}}var r=t(require("winston-transport")),s=Object.defineProperty,n=(e,t)=>s(e,"name",{value:t,configurable:!0}),i={0:e.KnownSeverityLevel.Verbose,1:e.KnownSeverityLevel.Information,2:e.KnownSeverityLevel.Warning,3:e.KnownSeverityLevel.Error,4:e.KnownSeverityLevel.Critical},o=n((e=>({emerg:4,alert:4,crit:4,error:3,warning:2,warn:2,notice:1,info:1,verbose:0,debug:0,silly:0}[e]??1)),"getMessageLevel"),c=n((e=>e instanceof Error),"isErrorLike"),l=n((e=>null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype),"isPlainObject"),a=n((e=>"object"!=typeof e||l(e)?e:Object.assign({},e)),"convertToPlainObject"),p=n((e=>{const t=["level","message"];return Object.keys(e).filter((e=>!t.includes(e))).reduce(((t,r)=>{const s=e[r];return t[r]=a(s),t}),{})}),"extractPropsFromInfo"),g=n((e=>{const t={message:e.message};for(const[r,s]of Object.entries(e))"stack"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=a(s));return t}),"extractErrorPropsForTrace"),f=class extends r.default{static{n(this,"AzureApplicationInsightsLogger")}client;sendErrorsAsExceptions;name;constructor(e){super({level:e.level??"info",silent:e.silent??!1}),this.client=e.client,this.name="applicationinsightslogger",this.sendErrorsAsExceptions=e.sendErrorsAsExceptions??!0}handleTrace(e,t,r,s){const n=p(t);let o;c(t)?o=t:c(r)?o=r:c(s)&&(o=s),o&&Object.assign(n,g(o)),s!==o&&Object.assign(n,s),this.client.trackTrace({message:String(r),severity:i[e],properties:n})}handleException(e,t,r){const s={};let n;if(c(e))n=e;else if(c(t))n=t;else{if(!c(r))return;n=r}"string"==typeof t&&n.message!==t&&(s.message=t),n!==r&&Object.assign(s,r),this.client.trackException({exception:n,properties:s})}log(e,t){const{level:r,message:s}=e,n=o(r),i=Reflect.get(e,Symbol.for("splat"))??[],c=i.length?i[0]:{};this.handleTrace(n,e,s,c),this.sendErrorsAsExceptions&&n>=3&&this.handleException(e,s,c),t()}};exports.AzureApplicationInsightsLogger=f;//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/winston-azure-application-insights.ts"],"names":["KnownSeverityLevel","TransportStream"],"mappings":";;;;;;;;;;;AAaA,IAAM,mBAAiE,GAAA;AAAA,EACrE,CAAC,CAAqB,iBAAGA,sCAAmB,CAAA,OAAA;AAAA,EAC5C,CAAC,CAAyB,qBAAGA,sCAAmB,CAAA,WAAA;AAAA,EAChD,CAAC,CAAqB,iBAAGA,sCAAmB,CAAA,OAAA;AAAA,EAC5C,CAAC,CAAmB,eAAGA,sCAAmB,CAAA,KAAA;AAAA,EAC1C,CAAC,CAAsB,kBAAGA,sCAAmB,CAAA,QAAA;AAC/C,CAAA,CAAA;AAGA,IAAM,eAAA,2BAAmB,YAAwC,KAAA;AAC/D,EAAA,MAAM,MAAwC,GAAA;AAAA,IAC5C,KAAO,EAAA,CAAA;AAAA,IACP,KAAO,EAAA,CAAA;AAAA,IACP,IAAM,EAAA,CAAA;AAAA,IACN,KAAO,EAAA,C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import { TelemetryClient, KnownSeverityLevel } from 'applicationinsights';\nimport TransportStream from 'winston-transport';\n\ntype PlainObject = Record<string, any>;\n\nenum SeverityLevel {\n Verbose = 0,\n Information = 1,\n Warning = 2,\n Error = 3,\n Critical = 4,\n}\n\nconst knownSeverityLevels: Record<SeverityLevel, KnownSeverityLevel> = {\n [SeverityLevel.Verbose]: KnownSeverityLevel.Verbose,\n [SeverityLevel.Information]: KnownSeverityLevel.Information,\n [SeverityLevel.Warning]: KnownSeverityLevel.Warning,\n [SeverityLevel.Error]: KnownSeverityLevel.Error,\n [SeverityLevel.Critical]: KnownSeverityLevel.Critical,\n};\n\n\nconst getMessageLevel = (winstonLevel: string): SeverityLevel => {\n const levels: Record<string, SeverityLevel> = {\n emerg: SeverityLevel.Critical,\n alert: SeverityLevel.Critical,\n crit: SeverityLevel.Critical,\n error: SeverityLevel.Error,\n warning: SeverityLevel.Warning,\n warn: SeverityLevel.Warning,\n notice: SeverityLevel.Information,\n info: SeverityLevel.Information,\n verbose: SeverityLevel.Verbose,\n debug: SeverityLevel.Verbose,\n silly: SeverityLevel.Verbose,\n } as const;\n\n return levels[winstonLevel] ?? SeverityLevel.Information;\n};\n\nconst isErrorLike = (obj: unknown): obj is Error => {\n return obj instanceof Error;\n};\n\n\nconst isPlainObject = (obj: unknown): obj is PlainObject => {\n return obj !== null && typeof obj === 'object' && Object.getPrototypeOf(obj) === Object.prototype;\n};\n\nconst convertToPlainObject = (obj: any): PlainObject => {\n if (typeof obj !== 'object') {\n return obj;\n }\n if (isPlainObject(obj)) {\n return obj;\n }\n return Object.assign({}, obj);\n};\n\nconst extractPropsFromInfo = (info: PlainObject): PlainObject => {\n const exclude = ['level', 'message'];\n\n return Object.keys(info)\n .filter((key) => !exclude.includes(key))\n .reduce<PlainObject>((props, key) => {\n const value = info[key];\n props[key] = convertToPlainObject(value);\n return props;\n }, {});\n};\n\nconst extractErrorPropsForTrace = (errorLike: Error): PlainObject => {\n const properties: PlainObject = {\n message: errorLike.message,\n };\n for (const [key, value] of Object.entries(errorLike)) {\n if (key !== 'stack' && Object.prototype.hasOwnProperty.call(errorLike, key)) {\n properties[key] = convertToPlainObject(value);\n }\n }\n return properties;\n};\n\nexport interface AzureApplicationInsightsLoggerOptions {\n client: TelemetryClient;\n level?: string;\n silent?: boolean;\n sendErrorsAsExceptions?: boolean;\n}\n\nexport class AzureApplicationInsightsLogger extends TransportStream {\n public readonly client: TelemetryClient;\n public sendErrorsAsExceptions: boolean;\n readonly name: string;\n\n constructor(options: AzureApplicationInsightsLoggerOptions) {\n super({ level: options.level ?? 'info', silent: options.silent ?? false });\n this.client = options.client;\n this.name = 'applicationinsightslogger';\n this.sendErrorsAsExceptions = options.sendErrorsAsExceptions ?? true;\n }\n\n private handleTrace(severity: SeverityLevel, info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const traceProps = extractPropsFromInfo(info);\n let errorArg: Error | undefined;\n\n if (isErrorLike(info)) {\n errorArg = info;\n } else if (isErrorLike(message)) {\n errorArg = message as unknown as Error;\n } else if (isErrorLike(logMeta)) {\n errorArg = logMeta;\n }\n\n if (errorArg) {\n Object.assign(traceProps, extractErrorPropsForTrace(errorArg));\n }\n\n if (logMeta !== errorArg) {\n Object.assign(traceProps, logMeta);\n }\n\n this.client.trackTrace({\n message: String(message),\n severity: knownSeverityLevels[severity],\n properties: traceProps,\n });\n }\n\n private handleException(info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const exceptionProps: PlainObject = {};\n let exception: Error | undefined;\n\n if (isErrorLike(info)) {\n exception = info;\n } else if (isErrorLike(message)) {\n exception = message as unknown as Error;\n } else if (isErrorLike(logMeta)) {\n exception = logMeta;\n } else {\n return;\n }\n\n if (typeof message === 'string' && exception.message !== message) {\n exceptionProps.message = message;\n }\n\n if (exception !== logMeta) {\n Object.assign(exceptionProps, logMeta);\n }\n\n this.client.trackException({ exception, properties: exceptionProps });\n }\n\n override log(info: PlainObject, callback: () => void): void {\n const { level, message } = info;\n const severity = getMessageLevel(level);\n const splat = Reflect.get(info, Symbol.for('splat')) ?? [];\n const logMeta = splat.length ? splat[0] : {};\n\n this.handleTrace(severity, info, message, logMeta);\n\n if (this.sendErrorsAsExceptions && severity >= SeverityLevel.Error) {\n this.handleException(info, message, logMeta);\n }\n\n callback();\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TelemetryClient } from 'applicationinsights';
|
|
2
|
+
import TransportStream from 'winston-transport';
|
|
3
|
+
|
|
4
|
+
type PlainObject = Record<string, any>;
|
|
5
|
+
interface AzureApplicationInsightsLoggerOptions {
|
|
6
|
+
client: TelemetryClient;
|
|
7
|
+
level?: string;
|
|
8
|
+
silent?: boolean;
|
|
9
|
+
sendErrorsAsExceptions?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare class AzureApplicationInsightsLogger extends TransportStream {
|
|
12
|
+
readonly client: TelemetryClient;
|
|
13
|
+
sendErrorsAsExceptions: boolean;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
constructor(options: AzureApplicationInsightsLoggerOptions);
|
|
16
|
+
private handleTrace;
|
|
17
|
+
private handleException;
|
|
18
|
+
log(info: PlainObject, callback: () => void): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { AzureApplicationInsightsLogger, type AzureApplicationInsightsLoggerOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{KnownSeverityLevel as e}from"applicationinsights";import t from"winston-transport";var r=Object.defineProperty,s=(e,t)=>r(e,"name",{value:t,configurable:!0}),n={0:e.Verbose,1:e.Information,2:e.Warning,3:e.Error,4:e.Critical},o=s((e=>({emerg:4,alert:4,crit:4,error:3,warning:2,warn:2,notice:1,info:1,verbose:0,debug:0,silly:0}[e]??1)),"getMessageLevel"),i=s((e=>e instanceof Error),"isErrorLike"),c=s((e=>null!==e&&"object"==typeof e&&Object.getPrototypeOf(e)===Object.prototype),"isPlainObject"),a=s((e=>"object"!=typeof e||c(e)?e:Object.assign({},e)),"convertToPlainObject"),l=s((e=>{const t=["level","message"];return Object.keys(e).filter((e=>!t.includes(e))).reduce(((t,r)=>{const s=e[r];return t[r]=a(s),t}),{})}),"extractPropsFromInfo"),p=s((e=>{const t={message:e.message};for(const[r,s]of Object.entries(e))"stack"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=a(s));return t}),"extractErrorPropsForTrace"),g=class extends t{static{s(this,"AzureApplicationInsightsLogger")}client;sendErrorsAsExceptions;name;constructor(e){super({level:e.level??"info",silent:e.silent??!1}),this.client=e.client,this.name="applicationinsightslogger",this.sendErrorsAsExceptions=e.sendErrorsAsExceptions??!0}handleTrace(e,t,r,s){const o=l(t);let c;i(t)?c=t:i(r)?c=r:i(s)&&(c=s),c&&Object.assign(o,p(c)),s!==c&&Object.assign(o,s),this.client.trackTrace({message:String(r),severity:n[e],properties:o})}handleException(e,t,r){const s={};let n;if(i(e))n=e;else if(i(t))n=t;else{if(!i(r))return;n=r}"string"==typeof t&&n.message!==t&&(s.message=t),n!==r&&Object.assign(s,r),this.client.trackException({exception:n,properties:s})}log(e,t){const{level:r,message:s}=e,n=o(r),i=Reflect.get(e,Symbol.for("splat"))??[],c=i.length?i[0]:{};this.handleTrace(n,e,s,c),this.sendErrorsAsExceptions&&n>=3&&this.handleException(e,s,c),t()}};export{g as AzureApplicationInsightsLogger};//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/winston-azure-application-insights.ts"],"names":[],"mappings":";;;;;AAaA,IAAM,mBAAiE,GAAA;AAAA,EACrE,CAAC,CAAqB,iBAAG,kBAAmB,CAAA,OAAA;AAAA,EAC5C,CAAC,CAAyB,qBAAG,kBAAmB,CAAA,WAAA;AAAA,EAChD,CAAC,CAAqB,iBAAG,kBAAmB,CAAA,OAAA;AAAA,EAC5C,CAAC,CAAmB,eAAG,kBAAmB,CAAA,KAAA;AAAA,EAC1C,CAAC,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,CAAA;AAEjD,IAAI,IAAA,IAAA,CAAK,sBAA0B,IAAA,QAAA,IAAY,CAAqB,cAAA;AAClE,MAAK,IAAA,CAAA,eAAA,CAAgB,IAAM,EAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,KAC7C;AAEA,IAAS,QAAA,EAAA,CAAA;AAAA,GACX;AACF","file":"index.mjs","sourcesContent":["import { TelemetryClient, KnownSeverityLevel } from 'applicationinsights';\nimport TransportStream from 'winston-transport';\n\ntype PlainObject = Record<string, any>;\n\nenum SeverityLevel {\n Verbose = 0,\n Information = 1,\n Warning = 2,\n Error = 3,\n Critical = 4,\n}\n\nconst knownSeverityLevels: Record<SeverityLevel, KnownSeverityLevel> = {\n [SeverityLevel.Verbose]: KnownSeverityLevel.Verbose,\n [SeverityLevel.Information]: KnownSeverityLevel.Information,\n [SeverityLevel.Warning]: KnownSeverityLevel.Warning,\n [SeverityLevel.Error]: KnownSeverityLevel.Error,\n [SeverityLevel.Critical]: KnownSeverityLevel.Critical,\n};\n\n\nconst getMessageLevel = (winstonLevel: string): SeverityLevel => {\n const levels: Record<string, SeverityLevel> = {\n emerg: SeverityLevel.Critical,\n alert: SeverityLevel.Critical,\n crit: SeverityLevel.Critical,\n error: SeverityLevel.Error,\n warning: SeverityLevel.Warning,\n warn: SeverityLevel.Warning,\n notice: SeverityLevel.Information,\n info: SeverityLevel.Information,\n verbose: SeverityLevel.Verbose,\n debug: SeverityLevel.Verbose,\n silly: SeverityLevel.Verbose,\n } as const;\n\n return levels[winstonLevel] ?? SeverityLevel.Information;\n};\n\nconst isErrorLike = (obj: unknown): obj is Error => {\n return obj instanceof Error;\n};\n\n\nconst isPlainObject = (obj: unknown): obj is PlainObject => {\n return obj !== null && typeof obj === 'object' && Object.getPrototypeOf(obj) === Object.prototype;\n};\n\nconst convertToPlainObject = (obj: any): PlainObject => {\n if (typeof obj !== 'object') {\n return obj;\n }\n if (isPlainObject(obj)) {\n return obj;\n }\n return Object.assign({}, obj);\n};\n\nconst extractPropsFromInfo = (info: PlainObject): PlainObject => {\n const exclude = ['level', 'message'];\n\n return Object.keys(info)\n .filter((key) => !exclude.includes(key))\n .reduce<PlainObject>((props, key) => {\n const value = info[key];\n props[key] = convertToPlainObject(value);\n return props;\n }, {});\n};\n\nconst extractErrorPropsForTrace = (errorLike: Error): PlainObject => {\n const properties: PlainObject = {\n message: errorLike.message,\n };\n for (const [key, value] of Object.entries(errorLike)) {\n if (key !== 'stack' && Object.prototype.hasOwnProperty.call(errorLike, key)) {\n properties[key] = convertToPlainObject(value);\n }\n }\n return properties;\n};\n\nexport interface AzureApplicationInsightsLoggerOptions {\n client: TelemetryClient;\n level?: string;\n silent?: boolean;\n sendErrorsAsExceptions?: boolean;\n}\n\nexport class AzureApplicationInsightsLogger extends TransportStream {\n public readonly client: TelemetryClient;\n public sendErrorsAsExceptions: boolean;\n readonly name: string;\n\n constructor(options: AzureApplicationInsightsLoggerOptions) {\n super({ level: options.level ?? 'info', silent: options.silent ?? false });\n this.client = options.client;\n this.name = 'applicationinsightslogger';\n this.sendErrorsAsExceptions = options.sendErrorsAsExceptions ?? true;\n }\n\n private handleTrace(severity: SeverityLevel, info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const traceProps = extractPropsFromInfo(info);\n let errorArg: Error | undefined;\n\n if (isErrorLike(info)) {\n errorArg = info;\n } else if (isErrorLike(message)) {\n errorArg = message as unknown as Error;\n } else if (isErrorLike(logMeta)) {\n errorArg = logMeta;\n }\n\n if (errorArg) {\n Object.assign(traceProps, extractErrorPropsForTrace(errorArg));\n }\n\n if (logMeta !== errorArg) {\n Object.assign(traceProps, logMeta);\n }\n\n this.client.trackTrace({\n message: String(message),\n severity: knownSeverityLevels[severity],\n properties: traceProps,\n });\n }\n\n private handleException(info: PlainObject, message: string | undefined, logMeta: PlainObject): void {\n const exceptionProps: PlainObject = {};\n let exception: Error | undefined;\n\n if (isErrorLike(info)) {\n exception = info;\n } else if (isErrorLike(message)) {\n exception = message as unknown as Error;\n } else if (isErrorLike(logMeta)) {\n exception = logMeta;\n } else {\n return;\n }\n\n if (typeof message === 'string' && exception.message !== message) {\n exceptionProps.message = message;\n }\n\n if (exception !== logMeta) {\n Object.assign(exceptionProps, logMeta);\n }\n\n this.client.trackException({ exception, properties: exceptionProps });\n }\n\n override log(info: PlainObject, callback: () => void): void {\n const { level, message } = info;\n const severity = getMessageLevel(level);\n const splat = Reflect.get(info, Symbol.for('splat')) ?? [];\n const logMeta = splat.length ? splat[0] : {};\n\n this.handleTrace(severity, info, message, logMeta);\n\n if (this.sendErrorsAsExceptions && severity >= SeverityLevel.Error) {\n this.handleException(info, message, logMeta);\n }\n\n callback();\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shellicar/winston-azure-application-insights",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Azure Application Insights transport for Winston",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.mjs",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/willmorgan/winston-azure-application-insights.git"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"winston",
|
|
28
|
+
"azure",
|
|
29
|
+
"insights",
|
|
30
|
+
"logging"
|
|
31
|
+
],
|
|
32
|
+
"author": "Marco Braga (Bragma)",
|
|
33
|
+
"contributors": [
|
|
34
|
+
{
|
|
35
|
+
"name": "Will Morgan",
|
|
36
|
+
"email": "jobs+npm@willmorgan.co.uk",
|
|
37
|
+
"url": "http://willmorgan.co.uk"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "Stephen Hellicar",
|
|
41
|
+
"email": "shellicar@gmail.com"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/mocha": "^10.0.8",
|
|
47
|
+
"@types/node": "^22.5.5",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^8.6.0",
|
|
49
|
+
"@typescript-eslint/parser": "^8.6.0",
|
|
50
|
+
"eslint": "^9.11.0",
|
|
51
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
52
|
+
"eslint-plugin-import": "^2.29.0",
|
|
53
|
+
"globals": "^15.9.0",
|
|
54
|
+
"mocha": "^10.7.3",
|
|
55
|
+
"npm-run-all2": "^6.2.3",
|
|
56
|
+
"terser": "^5.33.0",
|
|
57
|
+
"testdouble": "^3.20.2",
|
|
58
|
+
"tsup": "^8.3.0",
|
|
59
|
+
"tsx": "^4.19.1",
|
|
60
|
+
"typescript": "^5.6.2",
|
|
61
|
+
"winston": "^3.14.2"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/shellicar/winston-azure-application-insights/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://github.com/shellicar/winston-azure-application-insights#readme",
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"applicationinsights": "^3.3.0",
|
|
69
|
+
"winston-transport": "^4.7.1"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"demo": "tsx demo.ts",
|
|
73
|
+
"build": "run-s build:source build:types",
|
|
74
|
+
"build:source": "tsup",
|
|
75
|
+
"build:types": "tsup --dts-only --format cjs",
|
|
76
|
+
"lint": "eslint .",
|
|
77
|
+
"lint-fix": "eslint . --fix",
|
|
78
|
+
"test": "mocha"
|
|
79
|
+
}
|
|
80
|
+
}
|