@shellicar/winston-azure-application-insights 5.1.0 → 6.0.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -89
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +235 -0
- package/dist/index.d.ts +218 -66
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +27 -22
- package/dist/index.d.mts +0 -83
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,149 +1,283 @@
|
|
|
1
|
-
@shellicar/winston-azure-application-insights
|
|
2
|
-
==================================
|
|
1
|
+
# @shellicar/winston-azure-application-insights
|
|
3
2
|
|
|
4
|
-
|
|
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
|
-
|
|
5
|
+
[](https://npmjs.com/package/@shellicar/winston-azure-application-insights)
|
|
6
|
+
[](https://github.com/shellicar/winston-azure-application-insights/actions/workflows/node.js.yml)
|
|
7
|
+
[][copilot]
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
*Tests and documentation developed with assistance from [GitHub Copilot][copilot].*
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
> **Upgrading from v5.x?** See the [Migration Guide](#migration) for step-by-step upgrade instructions.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
## Features
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
- 🔄 **Dual SDK Support** - Works with both Application Insights v2 and v3 SDKs
|
|
16
|
+
- 🚀 **Simple Factory Functions** - Easy setup with `createApplicationInsightsTransport()` and `createWinstonLogger()`
|
|
17
|
+
- 🔍 **Automatic Error Detection** - Extracts Error objects from logs and sends them as Application Insights exceptions
|
|
18
|
+
- 📊 **Trace + Exception Logging** - Sends logs as traces while also tracking errors as detailed exceptions
|
|
19
|
+
- 🎯 **Flexible Filtering** - Optional trace and exception filters for fine-grained control
|
|
20
|
+
- 🔧 **Custom Severity Mapping** - Map Winston levels to Application Insights severity levels
|
|
21
|
+
- 🏠 **Local Development** - Log to console locally while sending to Application Insights in production
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
## Installation & Quick Start
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
```sh
|
|
26
|
+
pnpm add @shellicar/winston-azure-application-insights
|
|
27
|
+
```
|
|
19
28
|
|
|
20
|
-
|
|
29
|
+
```typescript
|
|
30
|
+
import { createWinstonLogger, ApplicationInsightsVersion } from '@shellicar/winston-azure-application-insights';
|
|
31
|
+
import applicationinsights from 'applicationinsights';
|
|
21
32
|
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
applicationinsights.setup().start();
|
|
34
|
+
|
|
35
|
+
const logger = createWinstonLogger({
|
|
36
|
+
insights: {
|
|
37
|
+
version: ApplicationInsightsVersion.V3,
|
|
38
|
+
client: applicationinsights.defaultClient
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
logger.info('Hello World');
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For more advanced usage and configuration, see the [examples](./examples) directory.
|
|
45
|
+
|
|
46
|
+
## Motivation
|
|
47
|
+
|
|
48
|
+
When logging directly to Application Insights using the telemetry client, it makes debugging locally more difficult. Logging to console pollutes logs in Azure, so this provides a compromise.
|
|
49
|
+
|
|
50
|
+
I forked the original library to add support for Application Insights v3, which is relatively recent. I have also refactored it to handle certain error logging scenarios that weren't working as expected.
|
|
51
|
+
|
|
52
|
+
## Feature Examples
|
|
53
|
+
|
|
54
|
+
- **Factory Functions** - Simple setup with clean API.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import applicationinsights from 'applicationinsights';
|
|
58
|
+
import { createApplicationInsightsTransport, ApplicationInsightsVersion } from '@shellicar/winston-azure-application-insights';
|
|
59
|
+
|
|
60
|
+
applicationinsights.setup().start();
|
|
61
|
+
|
|
62
|
+
const transport = createApplicationInsightsTransport({
|
|
63
|
+
version: ApplicationInsightsVersion.V3,
|
|
64
|
+
client: applicationinsights.defaultClient,
|
|
65
|
+
});
|
|
24
66
|
```
|
|
25
67
|
|
|
26
|
-
|
|
68
|
+
- **Complete Logger Setup** - Create a Winston logger with both console and Application Insights.
|
|
27
69
|
|
|
28
|
-
|
|
70
|
+
```typescript
|
|
71
|
+
import { createWinstonLogger, ApplicationInsightsVersion } from '@shellicar/winston-azure-application-insights';
|
|
72
|
+
import applicationinsights from 'applicationinsights';
|
|
73
|
+
|
|
74
|
+
const logger = createWinstonLogger({
|
|
75
|
+
winston: {
|
|
76
|
+
console: {
|
|
77
|
+
enabled: true,
|
|
78
|
+
format: {
|
|
79
|
+
output: 'json',
|
|
80
|
+
timestamp: true,
|
|
81
|
+
errors: true,
|
|
82
|
+
colorize: true,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
defaults: {
|
|
86
|
+
level: 'info',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
insights: {
|
|
90
|
+
version: ApplicationInsightsVersion.V3,
|
|
91
|
+
client: applicationinsights.defaultClient,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
29
94
|
|
|
30
|
-
|
|
95
|
+
logger.info('Application started');
|
|
96
|
+
```
|
|
31
97
|
|
|
32
|
-
|
|
98
|
+
- **Error Extraction** - Automatically detects Error objects and sends them as exceptions.
|
|
33
99
|
|
|
34
|
-
|
|
100
|
+
```typescript
|
|
101
|
+
// Creates trace only
|
|
102
|
+
logger.error('Something went wrong');
|
|
35
103
|
|
|
36
|
-
|
|
104
|
+
// Creates EXCEPTION ONLY (no trace) - when first parameter is Error
|
|
105
|
+
logger.error(new Error('Database error'));
|
|
37
106
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
for more information.
|
|
107
|
+
// Creates trace + exception (Error extracted from additional parameters)
|
|
108
|
+
logger.error('Operation failed', new Error('Timeout'));
|
|
41
109
|
|
|
42
|
-
|
|
110
|
+
// Creates trace + two exceptions (multiple Error objects)
|
|
111
|
+
logger.error('Multiple failures', new Error('DB error'), new Error('Cache error'));
|
|
112
|
+
```
|
|
43
113
|
|
|
44
|
-
|
|
114
|
+
**Key Behaviour:** When you log an Error as the first parameter (`logger.error(new Error())`), it sends **only the exception** to Application Insights, not a trace. This avoids duplicate telemetry.
|
|
115
|
+
|
|
116
|
+
- **Properties Extraction** - Winston splat parameters become telemetry properties.
|
|
45
117
|
|
|
46
118
|
```typescript
|
|
47
|
-
|
|
48
|
-
|
|
119
|
+
// Simple properties
|
|
120
|
+
logger.info('User logged in', { userId: 123, action: 'login' });
|
|
121
|
+
|
|
122
|
+
// Mixed types - Error objects are extracted, others become properties
|
|
123
|
+
logger.error('Complex operation failed', { userId: 123, operation: 'checkout' }, new Error('Payment failed'));
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- **Severity Mapping** - Winston levels map to Application Insights severity with priority fallback.
|
|
49
127
|
|
|
50
|
-
|
|
128
|
+
```typescript
|
|
129
|
+
logger.error('Critical issue'); // → Error
|
|
130
|
+
logger.warn('Warning message'); // → Warning
|
|
131
|
+
logger.info('Info message'); // → Information
|
|
132
|
+
logger.verbose('Debug info'); // → Verbose
|
|
133
|
+
|
|
134
|
+
// Custom levels fall back to next available mapping
|
|
135
|
+
logger.log('audit', 'Audit event'); // → Falls back based on level priority
|
|
136
|
+
```
|
|
51
137
|
|
|
52
|
-
|
|
53
|
-
|
|
138
|
+
- **Custom Severity Mapping** - Override default level mappings.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const transport = createApplicationInsightsTransport({
|
|
142
|
+
version: ApplicationInsightsVersion.V3,
|
|
143
|
+
client: defaultClient,
|
|
144
|
+
severityMapping: {
|
|
145
|
+
error: TelemetrySeverity.Error,
|
|
146
|
+
warn: TelemetrySeverity.Warning,
|
|
147
|
+
info: TelemetrySeverity.Information,
|
|
148
|
+
debug: TelemetrySeverity.Verbose,
|
|
149
|
+
// Custom levels
|
|
150
|
+
audit: TelemetrySeverity.Critical,
|
|
151
|
+
security: TelemetrySeverity.Error,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- **Dual SDK Support** - Works with both Application Insights v2 and v3.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Application Insights v2
|
|
160
|
+
import applicationinsights from 'applicationinsights'; // v2
|
|
161
|
+
const transport = createApplicationInsightsTransport({
|
|
162
|
+
version: ApplicationInsightsVersion.V2,
|
|
163
|
+
client: applicationinsights.defaultClient,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Application Insights v3
|
|
167
|
+
import applicationinsights from 'applicationinsights'; // v3
|
|
168
|
+
const transport = createApplicationInsightsTransport({
|
|
169
|
+
version: ApplicationInsightsVersion.V3,
|
|
170
|
+
client: applicationinsights.defaultClient,
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- **Filtering** - Optional filters for traces and exceptions.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const transport = createApplicationInsightsTransport({
|
|
178
|
+
version: ApplicationInsightsVersion.V3,
|
|
54
179
|
client: defaultClient,
|
|
180
|
+
traceFilter: (trace) => trace.severity !== KnownSeverityLevel.Verbose,
|
|
181
|
+
exceptionFilter: (exception) => !exception.exception.message.includes('ignore'),
|
|
55
182
|
});
|
|
56
183
|
```
|
|
57
|
-
```cjs
|
|
58
|
-
const { setup, defaultClient } = require("applicationinsights");
|
|
59
|
-
const { AzureApplicationInsightsLogger } = require('@shellicar/winston-azure-application-insights');
|
|
60
184
|
|
|
61
|
-
|
|
185
|
+
- **Disable Exception Tracking** - Customise error detection logic.
|
|
62
186
|
|
|
63
|
-
|
|
187
|
+
```typescript
|
|
188
|
+
const transport = createApplicationInsightsTransport({
|
|
64
189
|
version: 3,
|
|
65
190
|
client: defaultClient,
|
|
191
|
+
// Custom function to determine what counts as an error
|
|
192
|
+
isError: (obj) => obj instanceof CustomError,
|
|
66
193
|
});
|
|
67
194
|
```
|
|
68
195
|
|
|
69
|
-
|
|
196
|
+
<!-- BEGIN_ECOSYSTEM -->
|
|
70
197
|
|
|
71
|
-
|
|
198
|
+
## @shellicar TypeScript Ecosystem
|
|
72
199
|
|
|
73
|
-
|
|
200
|
+
### Core Libraries
|
|
74
201
|
|
|
75
|
-
|
|
202
|
+
- [`@shellicar/core-config`](https://github.com/shellicar/core-config) - A library for securely handling sensitive configuration values like connection strings, URLs, and secrets.
|
|
203
|
+
- [`@shellicar/core-di`](https://github.com/shellicar/core-di) - A basic dependency injection library.
|
|
76
204
|
|
|
77
|
-
|
|
205
|
+
### Reference Architectures
|
|
78
206
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
The best solution to this is to load `applicationinsights` and pass in `appInsights.defaultClient` using the `client`
|
|
82
|
-
option as per example.
|
|
207
|
+
- [`@shellicar/reference-foundation`](https://github.com/shellicar/reference-foundation) - A comprehensive starter repository. Illustrates individual concepts.
|
|
208
|
+
- [`@shellicar/reference-enterprise`](https://github.com/shellicar/reference-enterprise) - A comprehensive starter repository. Can be used as the basis for creating a new Azure application workload.
|
|
83
209
|
|
|
84
|
-
|
|
210
|
+
### Build Tools
|
|
85
211
|
|
|
86
|
-
`
|
|
87
|
-
|
|
212
|
+
- [`@shellicar/build-version`](https://github.com/shellicar/build-version) - Build plugin that calculates and exposes version information through a virtual module import.
|
|
213
|
+
- [`@shellicar/build-graphql`](https://github.com/shellicar/build-graphql) - Build plugin that loads GraphQL files and makes them available through a virtual module import.
|
|
88
214
|
|
|
89
|
-
|
|
215
|
+
### Framework Adapters
|
|
90
216
|
|
|
91
|
-
|
|
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.
|
|
217
|
+
- [`@shellicar/svelte-adapter-azure-functions`](https://github.com/shellicar/svelte-adapter-azure-functions) - A [SvelteKit adapter](https://kit.svelte.dev/docs/adapters) that builds your app into an Azure Function.
|
|
94
218
|
|
|
95
|
-
|
|
219
|
+
### Logging & Monitoring
|
|
96
220
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
221
|
+
- [`@shellicar/winston-azure-application-insights`](https://github.com/shellicar/winston-azure-application-insights) - An [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/) transport for [Winston](https://github.com/winstonjs/winston) logging library.
|
|
222
|
+
- [`@shellicar/pino-applicationinsights-transport`](https://github.com/shellicar/pino-applicationinsights-transport) - [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights) transport for [pino](https://github.com/pinojs/pino)
|
|
223
|
+
|
|
224
|
+
<!-- END_ECOSYSTEM -->
|
|
225
|
+
|
|
226
|
+
## Configuration Options
|
|
227
|
+
|
|
228
|
+
- **version**: `ApplicationInsightsVersion.V2` or `ApplicationInsightsVersion.V3` - Application Insights SDK version (required)
|
|
229
|
+
- **client**: Application Insights client instance (required)
|
|
230
|
+
- **telemetryHandler**: Custom telemetry handler function (instead of version and client)
|
|
231
|
+
- **isError**: Custom function to determine what counts as an error (default: detects Error instances)
|
|
232
|
+
- **severityMapping**: Custom Winston level to Application Insights severity mapping
|
|
233
|
+
- **traceFilter**: Optional function to filter traces before sending
|
|
234
|
+
- **exceptionFilter**: Optional function to filter exceptions before sending
|
|
235
|
+
|
|
236
|
+
### Troubleshooting
|
|
237
|
+
|
|
238
|
+
#### Missing Connection String
|
|
100
239
|
|
|
101
|
-
|
|
240
|
+
```txt
|
|
241
|
+
No instrumentation key or connection string was provided
|
|
242
|
+
```
|
|
102
243
|
|
|
103
|
-
|
|
104
|
-
* **sendErrorsAsExceptions**: Boolean flag indicating whether to also track errors to the AI exceptions table.
|
|
105
|
-
See section below for more details (default: `true`).
|
|
244
|
+
Set the connection string via environment variable or setup parameter. See the [Application Insights setup guide](https://github.com/microsoft/ApplicationInsights-node.js?tab=readme-ov-file#get-started) for detailed instructions.
|
|
106
245
|
|
|
107
|
-
|
|
246
|
+
#### Duplicate API Registration
|
|
108
247
|
|
|
109
|
-
|
|
248
|
+
```txt
|
|
249
|
+
Attempted duplicate registration of API: context
|
|
250
|
+
```
|
|
110
251
|
|
|
111
|
-
|
|
252
|
+
Your environment already loaded Application Insights. Use the existing client without calling setup():
|
|
112
253
|
|
|
113
|
-
|
|
254
|
+
```typescript
|
|
255
|
+
import applicationinsights from 'applicationinsights';
|
|
256
|
+
const transport = createApplicationInsightsTransport({
|
|
257
|
+
version: ApplicationInsightsVersion.V3,
|
|
258
|
+
client: applicationinsights.defaultClient,
|
|
259
|
+
});
|
|
260
|
+
```
|
|
114
261
|
|
|
115
|
-
|
|
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)
|
|
262
|
+
#### Multiple/Duplicate Traces
|
|
123
263
|
|
|
124
|
-
|
|
264
|
+
Application Insights auto-collects from console and Winston. Disable auto-collection:
|
|
125
265
|
|
|
126
|
-
|
|
127
|
-
|
|
266
|
+
```typescript
|
|
267
|
+
setup().setAutoCollectConsole(false).start();
|
|
268
|
+
```
|
|
128
269
|
|
|
129
|
-
##
|
|
270
|
+
## Migration
|
|
130
271
|
|
|
131
|
-
|
|
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.
|
|
272
|
+
### Upgrading from v5.x to v6.x
|
|
137
273
|
|
|
138
|
-
|
|
139
|
-
up alerts based on the related metrics.
|
|
274
|
+
v6.x includes significant improvements to error handling, type safety, and configuration structure. See the complete [Migration Guide](./MIGRATION.md) for detailed upgrade instructions.
|
|
140
275
|
|
|
141
|
-
|
|
276
|
+
## Credits & Inspiration
|
|
142
277
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
* `logger.info(new Error('error message'));` creates a trace with severity level 1; *no* exception is tracked
|
|
278
|
+
- [willmorgan/winston-azure-application-insights](https://github.com/willmorgan/winston-azure-application-insights) - Forked from willmorgan's version
|
|
279
|
+
- [bragma/winston-azure-application-insights](https://github.com/bragma/winston-azure-application-insights) - Original library by bragma
|
|
280
|
+
- [Winston](https://github.com/winstonjs/winston) - Universal logging library for Node.js
|
|
281
|
+
- [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/) - Application Performance Management service
|
|
148
282
|
|
|
149
|
-
|
|
283
|
+
[copilot]: https://github.com/features/copilot
|
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,GAAG,gBAAgB,CAAA;AAC/D,EAAA,MAAM,aAAsC,EAAC;AAC7C,EAAA,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W,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"]}
|