@shellicar/winston-azure-application-insights 6.0.0-preview.1 → 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.
Files changed (3) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +8 -259
  3. package/package.json +6 -28
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,31 +1,15 @@
1
1
  # @shellicar/winston-azure-application-insights
2
2
 
3
- > An [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/) transport for [Winston](https://github.com/winstonjs/winston) logging library.
4
-
5
- [![npm package](https://img.shields.io/npm/v/@shellicar/winston-azure-application-insights.svg)](https://npmjs.com/package/@shellicar/winston-azure-application-insights)
6
- [![build status](https://github.com/shellicar/winston-azure-application-insights/actions/workflows/node.js.yml/badge.svg)](https://github.com/shellicar/winston-azure-application-insights/actions/workflows/node.js.yml)
7
- [![AI Assisted](https://img.shields.io/badge/AI--Assisted-GitHub_Copilot-412991?logo=github)][copilot]
8
-
9
- *Tests and documentation developed with assistance from [GitHub Copilot][copilot].*
10
-
11
- > **Upgrading from v5.x?** See the [Migration Guide](#migration) for step-by-step upgrade instructions.
12
-
13
- ## Features
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
3
+ An [Azure Application Insights](https://azure.microsoft.com/en-us/services/application-insights/) transport for [Winston](https://github.com/winstonjs/winston) logging library
22
4
 
23
5
  ## Installation & Quick Start
24
6
 
25
7
  ```sh
26
- pnpm add @shellicar/winston-azure-application-insights
8
+ npm install @shellicar/winston-azure-application-insights
27
9
  ```
28
10
 
11
+ ## Quick Example
12
+
29
13
  ```typescript
30
14
  import { createWinstonLogger, ApplicationInsightsVersion } from '@shellicar/winston-azure-application-insights';
31
15
  import applicationinsights from 'applicationinsights';
@@ -38,246 +22,11 @@ const logger = createWinstonLogger({
38
22
  client: applicationinsights.defaultClient
39
23
  },
40
24
  });
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
- });
66
- ```
67
-
68
- - **Complete Logger Setup** - Create a Winston logger with both console and Application Insights.
69
-
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
- });
94
-
95
- logger.info('Application started');
96
- ```
97
-
98
- - **Error Extraction** - Automatically detects Error objects and sends them as exceptions.
99
-
100
- ```typescript
101
- // Creates trace only
102
- logger.error('Something went wrong');
103
-
104
- // Creates EXCEPTION ONLY (no trace) - when first parameter is Error
105
- logger.error(new Error('Database error'));
106
-
107
- // Creates trace + exception (Error extracted from additional parameters)
108
- logger.error('Operation failed', new Error('Timeout'));
109
-
110
- // Creates trace + two exceptions (multiple Error objects)
111
- logger.error('Multiple failures', new Error('DB error'), new Error('Cache error'));
112
- ```
113
-
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.
117
-
118
- ```typescript
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.
127
-
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
- ```
137
-
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,
179
- client: defaultClient,
180
- traceFilter: (trace) => trace.severity !== KnownSeverityLevel.Verbose,
181
- exceptionFilter: (exception) => !exception.exception.message.includes('ignore'),
182
- });
183
- ```
184
-
185
- - **Disable Exception Tracking** - Customise error detection logic.
186
-
187
- ```typescript
188
- const transport = createApplicationInsightsTransport({
189
- version: 3,
190
- client: defaultClient,
191
- // Custom function to determine what counts as an error
192
- isError: (obj) => obj instanceof CustomError,
193
- });
194
- ```
195
-
196
- <!-- BEGIN_ECOSYSTEM -->
197
-
198
- ## @shellicar TypeScript Ecosystem
199
-
200
- ### Core Libraries
201
-
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.
204
-
205
- ### Reference Architectures
206
-
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.
209
-
210
- ### Build Tools
211
-
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.
214
-
215
- ### Framework Adapters
216
25
 
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.
218
-
219
- ### Logging & Monitoring
220
-
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
239
-
240
- ```txt
241
- No instrumentation key or connection string was provided
242
- ```
243
-
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.
245
-
246
- #### Duplicate API Registration
247
-
248
- ```txt
249
- Attempted duplicate registration of API: context
250
- ```
251
-
252
- Your environment already loaded Application Insights. Use the existing client without calling setup():
253
-
254
- ```typescript
255
- import applicationinsights from 'applicationinsights';
256
- const transport = createApplicationInsightsTransport({
257
- version: ApplicationInsightsVersion.V3,
258
- client: applicationinsights.defaultClient,
259
- });
260
- ```
261
-
262
- #### Multiple/Duplicate Traces
263
-
264
- Application Insights auto-collects from console and Winston. Disable auto-collection:
265
-
266
- ```typescript
267
- setup().setAutoCollectConsole(false).start();
26
+ logger.info('Hello World');
27
+ logger.error('Something went wrong', new Error('Database connection failed'));
268
28
  ```
269
29
 
270
- ## Migration
271
-
272
- ### Upgrading from v5.x to v6.x
273
-
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.
275
-
276
- ## Credits & Inspiration
277
-
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
30
+ ## Documentation
282
31
 
283
- [copilot]: https://github.com/features/copilot
32
+ For full documentation, visit the [GitHub repository](https://github.com/shellicar/winston-azure-application-insights).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellicar/winston-azure-application-insights",
3
- "version": "6.0.0-preview.1",
3
+ "version": "6.0.0-preview.2",
4
4
  "private": false,
5
5
  "description": "Azure Application Insights transport for Winston",
6
6
  "type": "module",
@@ -30,35 +30,25 @@
30
30
  "insights",
31
31
  "logging"
32
32
  ],
33
- "author": "Marco Braga (Bragma)",
33
+ "author": "Stephen Hellicar",
34
34
  "contributors": [
35
- {
36
- "name": "Will Morgan",
37
- "email": "jobs+npm@willmorgan.co.uk",
38
- "url": "http://willmorgan.co.uk"
39
- },
40
35
  {
41
36
  "name": "Stephen Hellicar",
42
- "email": "shellicar@gmail.com"
37
+ "email": "shellicar@gmail.com",
38
+ "url": "https://stephen-hellicar.com.au/"
43
39
  }
44
40
  ],
45
41
  "license": "MIT",
46
42
  "devDependencies": {
47
- "@biomejs/biome": "^2.2.0",
48
43
  "@types/node": "^24.3.0",
49
44
  "@types/triple-beam": "^1.3.5",
50
45
  "@vitest/coverage-v8": "^3.2.4",
51
- "lefthook": "^1.12.3",
52
46
  "logform": "^2.7.0",
53
- "npm-check-updates": "^18.0.2",
54
- "npm-run-all2": "^8.0.4",
55
- "syncpack": "^13.0.4",
56
47
  "terser": "^5.43.1",
57
48
  "testdouble": "^3.20.2",
58
49
  "triple-beam": "^1.4.1",
59
50
  "tsup": "^8.5.0",
60
- "tsx": "^4.20.4",
61
- "turbo": "^2.5.6",
51
+ "tsx": "^4.20.5",
62
52
  "typescript": "^5.9.2",
63
53
  "vitest": "^3.2.4",
64
54
  "winston": "^3.17.0",
@@ -82,21 +72,9 @@
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
75
  "type-check": "tsc -p tsconfig.check.json",
89
- "ci": "run-s ci:biome ci:type-check",
90
- "ci:biome": "biome ci --diagnostic-level=error",
91
- "ci:type-check": "turbo run type-check",
92
- "ci:fix": "biome check --diagnostic-level=error --fix",
93
76
  "test": "vitest run",
94
77
  "coverage": "vitest run --coverage",
95
- "test:coverage": "vitest run --coverage",
96
- "list-mismatches": "syncpack list-mismatches",
97
- "fix-mismatches": "syncpack fix-mismatches",
98
- "updates": "npm-check-updates --workspaces",
99
- "postinstall": "lefthook install",
100
- "verify-version": "./scripts/verify-version.sh"
78
+ "test:coverage": "vitest run --coverage"
101
79
  }
102
80
  }