dspx 0.1.1-alpha.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.
Files changed (172) hide show
  1. package/.github/workflows/ci.yml +185 -0
  2. package/.vscode/c_cpp_properties.json +17 -0
  3. package/.vscode/settings.json +68 -0
  4. package/.vscode/tasks.json +28 -0
  5. package/DISCLAIMER.md +32 -0
  6. package/LICENSE +21 -0
  7. package/README.md +1803 -0
  8. package/ROADMAP.md +192 -0
  9. package/TECHNICAL_DEBT.md +165 -0
  10. package/binding.gyp +65 -0
  11. package/docs/ADVANCED_LOGGER_FEATURES.md +598 -0
  12. package/docs/AUTHENTICATION_SECURITY.md +396 -0
  13. package/docs/BACKEND_IMPROVEMENTS.md +399 -0
  14. package/docs/CHEBYSHEV_BIQUAD_EQ_IMPLEMENTATION.md +405 -0
  15. package/docs/FFT_IMPLEMENTATION.md +490 -0
  16. package/docs/FFT_IMPROVEMENTS_SUMMARY.md +387 -0
  17. package/docs/FFT_USER_GUIDE.md +494 -0
  18. package/docs/FILTERS_IMPLEMENTATION.md +260 -0
  19. package/docs/FILTER_API_GUIDE.md +418 -0
  20. package/docs/FIR_SIMD_OPTIMIZATION.md +175 -0
  21. package/docs/LOGGER_API_REFERENCE.md +350 -0
  22. package/docs/NOTCH_FILTER_QUICK_REF.md +121 -0
  23. package/docs/PHASE2_TESTS_AND_NOTCH_FILTER.md +341 -0
  24. package/docs/PHASES_5_7_SUMMARY.md +403 -0
  25. package/docs/PIPELINE_FILTER_INTEGRATION.md +446 -0
  26. package/docs/SIMD_OPTIMIZATIONS.md +211 -0
  27. package/docs/TEST_MIGRATION_SUMMARY.md +173 -0
  28. package/docs/TIMESERIES_IMPLEMENTATION_SUMMARY.md +322 -0
  29. package/docs/TIMESERIES_QUICK_REF.md +85 -0
  30. package/docs/advanced.md +559 -0
  31. package/docs/time-series-guide.md +617 -0
  32. package/docs/time-series-migration.md +376 -0
  33. package/jest.config.js +37 -0
  34. package/package.json +42 -0
  35. package/prebuilds/linux-x64/dsp-ts-redis.node +0 -0
  36. package/prebuilds/win32-x64/dsp-ts-redis.node +0 -0
  37. package/scripts/test.js +24 -0
  38. package/src/build/dsp-ts-redis.node +0 -0
  39. package/src/native/DspPipeline.cc +675 -0
  40. package/src/native/DspPipeline.h +44 -0
  41. package/src/native/FftBindings.cc +817 -0
  42. package/src/native/FilterBindings.cc +1001 -0
  43. package/src/native/IDspStage.h +53 -0
  44. package/src/native/adapters/InterpolatorStage.h +201 -0
  45. package/src/native/adapters/MeanAbsoluteValueStage.h +289 -0
  46. package/src/native/adapters/MovingAverageStage.h +306 -0
  47. package/src/native/adapters/RectifyStage.h +88 -0
  48. package/src/native/adapters/ResamplerStage.h +238 -0
  49. package/src/native/adapters/RmsStage.h +299 -0
  50. package/src/native/adapters/SscStage.h +121 -0
  51. package/src/native/adapters/VarianceStage.h +307 -0
  52. package/src/native/adapters/WampStage.h +114 -0
  53. package/src/native/adapters/WaveformLengthStage.h +115 -0
  54. package/src/native/adapters/ZScoreNormalizeStage.h +326 -0
  55. package/src/native/core/FftEngine.cc +441 -0
  56. package/src/native/core/FftEngine.h +224 -0
  57. package/src/native/core/FirFilter.cc +324 -0
  58. package/src/native/core/FirFilter.h +149 -0
  59. package/src/native/core/IirFilter.cc +576 -0
  60. package/src/native/core/IirFilter.h +210 -0
  61. package/src/native/core/MovingAbsoluteValueFilter.cc +17 -0
  62. package/src/native/core/MovingAbsoluteValueFilter.h +135 -0
  63. package/src/native/core/MovingAverageFilter.cc +18 -0
  64. package/src/native/core/MovingAverageFilter.h +135 -0
  65. package/src/native/core/MovingFftFilter.cc +291 -0
  66. package/src/native/core/MovingFftFilter.h +203 -0
  67. package/src/native/core/MovingVarianceFilter.cc +194 -0
  68. package/src/native/core/MovingVarianceFilter.h +114 -0
  69. package/src/native/core/MovingZScoreFilter.cc +215 -0
  70. package/src/native/core/MovingZScoreFilter.h +113 -0
  71. package/src/native/core/Policies.h +352 -0
  72. package/src/native/core/RmsFilter.cc +18 -0
  73. package/src/native/core/RmsFilter.h +131 -0
  74. package/src/native/core/SscFilter.cc +16 -0
  75. package/src/native/core/SscFilter.h +137 -0
  76. package/src/native/core/WampFilter.cc +16 -0
  77. package/src/native/core/WampFilter.h +101 -0
  78. package/src/native/core/WaveformLengthFilter.cc +17 -0
  79. package/src/native/core/WaveformLengthFilter.h +98 -0
  80. package/src/native/utils/CircularBufferArray.cc +336 -0
  81. package/src/native/utils/CircularBufferArray.h +62 -0
  82. package/src/native/utils/CircularBufferVector.cc +145 -0
  83. package/src/native/utils/CircularBufferVector.h +45 -0
  84. package/src/native/utils/NapiUtils.cc +53 -0
  85. package/src/native/utils/NapiUtils.h +21 -0
  86. package/src/native/utils/SimdOps.h +870 -0
  87. package/src/native/utils/SlidingWindowFilter.cc +239 -0
  88. package/src/native/utils/SlidingWindowFilter.h +159 -0
  89. package/src/native/utils/TimeSeriesBuffer.cc +205 -0
  90. package/src/native/utils/TimeSeriesBuffer.h +140 -0
  91. package/src/ts/CircularLogBuffer.ts +87 -0
  92. package/src/ts/DriftDetector.ts +331 -0
  93. package/src/ts/TopicRouter.ts +428 -0
  94. package/src/ts/__tests__/AdvancedDsp.test.ts +585 -0
  95. package/src/ts/__tests__/AuthAndEdgeCases.test.ts +241 -0
  96. package/src/ts/__tests__/Chaining.test.ts +387 -0
  97. package/src/ts/__tests__/ChebyshevBiquad.test.ts +229 -0
  98. package/src/ts/__tests__/CircularLogBuffer.test.ts +158 -0
  99. package/src/ts/__tests__/DriftDetector.test.ts +389 -0
  100. package/src/ts/__tests__/Fft.test.ts +484 -0
  101. package/src/ts/__tests__/ListState.test.ts +153 -0
  102. package/src/ts/__tests__/Logger.test.ts +208 -0
  103. package/src/ts/__tests__/LoggerAdvanced.test.ts +319 -0
  104. package/src/ts/__tests__/LoggerMinor.test.ts +247 -0
  105. package/src/ts/__tests__/MeanAbsoluteValue.test.ts +398 -0
  106. package/src/ts/__tests__/MovingAverage.test.ts +322 -0
  107. package/src/ts/__tests__/RMS.test.ts +315 -0
  108. package/src/ts/__tests__/Rectify.test.ts +272 -0
  109. package/src/ts/__tests__/Redis.test.ts +456 -0
  110. package/src/ts/__tests__/SlopeSignChange.test.ts +166 -0
  111. package/src/ts/__tests__/Tap.test.ts +164 -0
  112. package/src/ts/__tests__/TimeBasedExpiration.test.ts +124 -0
  113. package/src/ts/__tests__/TimeBasedRmsAndMav.test.ts +231 -0
  114. package/src/ts/__tests__/TimeBasedVarianceAndZScore.test.ts +284 -0
  115. package/src/ts/__tests__/TimeSeries.test.ts +254 -0
  116. package/src/ts/__tests__/TopicRouter.test.ts +332 -0
  117. package/src/ts/__tests__/TopicRouterAdvanced.test.ts +483 -0
  118. package/src/ts/__tests__/TopicRouterPriority.test.ts +487 -0
  119. package/src/ts/__tests__/Variance.test.ts +509 -0
  120. package/src/ts/__tests__/WaveformLength.test.ts +147 -0
  121. package/src/ts/__tests__/WillisonAmplitude.test.ts +197 -0
  122. package/src/ts/__tests__/ZScoreNormalize.test.ts +459 -0
  123. package/src/ts/advanced-dsp.ts +566 -0
  124. package/src/ts/backends.ts +1137 -0
  125. package/src/ts/bindings.ts +1225 -0
  126. package/src/ts/easter-egg.ts +42 -0
  127. package/src/ts/examples/MeanAbsoluteValue/test-state.ts +99 -0
  128. package/src/ts/examples/MeanAbsoluteValue/test-streaming.ts +269 -0
  129. package/src/ts/examples/MovingAverage/test-state.ts +85 -0
  130. package/src/ts/examples/MovingAverage/test-streaming.ts +188 -0
  131. package/src/ts/examples/RMS/test-state.ts +97 -0
  132. package/src/ts/examples/RMS/test-streaming.ts +253 -0
  133. package/src/ts/examples/Rectify/test-state.ts +107 -0
  134. package/src/ts/examples/Rectify/test-streaming.ts +242 -0
  135. package/src/ts/examples/Variance/test-state.ts +195 -0
  136. package/src/ts/examples/Variance/test-streaming.ts +260 -0
  137. package/src/ts/examples/ZScoreNormalize/test-state.ts +277 -0
  138. package/src/ts/examples/ZScoreNormalize/test-streaming.ts +306 -0
  139. package/src/ts/examples/advanced-dsp-examples.ts +397 -0
  140. package/src/ts/examples/callbacks/advanced-router-features.ts +326 -0
  141. package/src/ts/examples/callbacks/benchmark-circular-buffer.ts +109 -0
  142. package/src/ts/examples/callbacks/monitoring-example.ts +265 -0
  143. package/src/ts/examples/callbacks/pipeline-callbacks-example.ts +137 -0
  144. package/src/ts/examples/callbacks/pooled-callbacks-example.ts +274 -0
  145. package/src/ts/examples/callbacks/priority-routing-example.ts +277 -0
  146. package/src/ts/examples/callbacks/production-topic-router.ts +214 -0
  147. package/src/ts/examples/callbacks/topic-based-logging.ts +161 -0
  148. package/src/ts/examples/chaining/test-chaining-redis.ts +113 -0
  149. package/src/ts/examples/chaining/test-chaining.ts +52 -0
  150. package/src/ts/examples/emg-features-example.ts +284 -0
  151. package/src/ts/examples/fft-example.ts +309 -0
  152. package/src/ts/examples/fft-examples.ts +349 -0
  153. package/src/ts/examples/filter-examples.ts +320 -0
  154. package/src/ts/examples/list-state-example.ts +131 -0
  155. package/src/ts/examples/logger-example.ts +91 -0
  156. package/src/ts/examples/notch-filter-examples.ts +243 -0
  157. package/src/ts/examples/phase5/drift-detection-example.ts +290 -0
  158. package/src/ts/examples/phase6-7/production-observability.ts +476 -0
  159. package/src/ts/examples/phase6-7/redis-timeseries-integration.ts +446 -0
  160. package/src/ts/examples/redis/redis-example.ts +202 -0
  161. package/src/ts/examples/redis-example.ts +202 -0
  162. package/src/ts/examples/simd-benchmark.ts +126 -0
  163. package/src/ts/examples/tap-debugging.ts +230 -0
  164. package/src/ts/examples/timeseries/comparison-example.ts +290 -0
  165. package/src/ts/examples/timeseries/iot-sensor-example.ts +143 -0
  166. package/src/ts/examples/timeseries/redis-streaming-example.ts +233 -0
  167. package/src/ts/examples/waveform-length-example.ts +139 -0
  168. package/src/ts/fft.ts +722 -0
  169. package/src/ts/filters.ts +1078 -0
  170. package/src/ts/index.ts +120 -0
  171. package/src/ts/types.ts +589 -0
  172. package/tsconfig.json +15 -0
@@ -0,0 +1,396 @@
1
+ # Authentication & Security Enhancements
2
+
3
+ ## Overview
4
+
5
+ This document describes the authentication error handling improvements and security considerations added to the observability backend handlers.
6
+
7
+ ## Key Improvements
8
+
9
+ ### 1. **Circular Reference Protection**
10
+
11
+ **Problem**: `TextFormatter` could throw exceptions when formatting logs with circular references or non-serializable objects.
12
+
13
+ **Solution**: Added try-catch around `JSON.stringify()` with graceful fallback:
14
+
15
+ ```typescript
16
+ try {
17
+ output += `\n Context: ${JSON.stringify(log.context)}`;
18
+ } catch (error) {
19
+ output += `\n Context: [Unable to stringify: ${
20
+ error instanceof Error ? error.message : "unknown error"
21
+ }]`;
22
+ }
23
+ ```
24
+
25
+ **Impact**: Prevents logging system from crashing when encountering:
26
+
27
+ - Circular object references
28
+ - Non-serializable values (functions, symbols)
29
+ - Deeply nested objects
30
+ - BigInt values
31
+
32
+ ---
33
+
34
+ ### 2. **Authentication Error Detection**
35
+
36
+ Each handler now provides specific error messages for authentication failures:
37
+
38
+ #### **PagerDuty Handler**
39
+
40
+ ```typescript
41
+ if (error.message.includes("401")) {
42
+ throw new Error(
43
+ `PagerDuty authentication failed: Invalid routing_key. Check your Integration Key.`
44
+ );
45
+ }
46
+ ```
47
+
48
+ **Configuration Notes**:
49
+
50
+ - Requires `routing_key` (Integration Key) from PagerDuty
51
+ - Regional endpoints: US (default), EU requires custom endpoint
52
+ - Common errors: Invalid key, revoked key, wrong regional endpoint
53
+
54
+ ---
55
+
56
+ #### **Prometheus Pushgateway Handler**
57
+
58
+ ```typescript
59
+ if (response.status === 401 || response.status === 403) {
60
+ throw new Error(
61
+ `Prometheus authentication failed (${response.status}). Check config.headers for HTTP Basic Auth credentials.`
62
+ );
63
+ }
64
+ ```
65
+
66
+ **Configuration Notes**:
67
+
68
+ - Authentication varies by setup:
69
+ - HTTP Basic Auth (pass via `config.headers`)
70
+ - Network-level controls (VPN, firewall)
71
+ - Common errors: Missing Basic Auth header, incorrect credentials
72
+
73
+ ---
74
+
75
+ #### **Loki Handler**
76
+
77
+ ```typescript
78
+ if (error.message.includes("401") || error.message.includes("403")) {
79
+ throw new Error(
80
+ `Loki authentication failed. Check apiKey (Bearer token) or config.headers for Basic Auth / X-Scope-OrgID.`
81
+ );
82
+ }
83
+ ```
84
+
85
+ **Configuration Notes**:
86
+
87
+ - Supports multiple auth methods:
88
+ - Bearer token (most common, via `apiKey`)
89
+ - HTTP Basic Auth (via `config.headers`)
90
+ - Multi-tenant ID via `X-Scope-OrgID` header
91
+ - Common errors: Invalid token, wrong auth method, missing tenant ID
92
+
93
+ ---
94
+
95
+ #### **CloudWatch Handler** ⚠️
96
+
97
+ **WARNING**: This handler uses manual AWS authentication which is **error-prone** and **not recommended for production**.
98
+
99
+ ```typescript
100
+ throw new Error(
101
+ `CloudWatch authentication failed. AWS requires proper IAM credentials and request signing. ` +
102
+ `Consider using @aws-sdk/client-cloudwatch-logs instead of manual fetch. Error: ${error.message}`
103
+ );
104
+ ```
105
+
106
+ **Why Manual Auth Fails**:
107
+
108
+ 1. AWS uses complex signature version 4 (SigV4) request signing
109
+ 2. Credentials can come from multiple sources:
110
+ - Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)
111
+ - EC2 instance metadata service
112
+ - ECS task roles
113
+ - Shared credential files (`~/.aws/credentials`)
114
+ - IAM roles for service accounts (IRSA in EKS)
115
+ 3. Simple API key passing bypasses all of this
116
+
117
+ **Recommended Solution**:
118
+
119
+ ```typescript
120
+ import {
121
+ CloudWatchLogsClient,
122
+ PutLogEventsCommand,
123
+ } from "@aws-sdk/client-cloudwatch-logs";
124
+
125
+ const client = new CloudWatchLogsClient({ region: "us-east-1" });
126
+ // SDK automatically discovers credentials from environment
127
+ ```
128
+
129
+ **Configuration Notes**:
130
+
131
+ - Requires proper IAM permissions: `logs:PutLogEvents`, `logs:CreateLogStream`
132
+ - Regional endpoint configuration required
133
+ - Common errors: Invalid credentials, insufficient permissions, wrong region
134
+
135
+ ---
136
+
137
+ #### **Datadog Handler**
138
+
139
+ ```typescript
140
+ if (error.message.includes("403") || error.message.includes("401")) {
141
+ throw new Error(
142
+ `Datadog authentication failed. Check apiKey validity and regional endpoint (US vs EU). Error: ${error.message}`
143
+ );
144
+ }
145
+ ```
146
+
147
+ **Configuration Notes**:
148
+
149
+ - API key embedded in URL path: `${endpoint}/v1/input/${apiKey}`
150
+ - Regional endpoints:
151
+ - US: `https://http-intake.logs.datadoghq.com` (default)
152
+ - EU: `https://http-intake.logs.datadoghq.eu`
153
+ - Common errors: Invalid API key, wrong regional endpoint
154
+
155
+ ---
156
+
157
+ ## Configuration Validation
158
+
159
+ All handlers now warn at construction time if credentials are missing:
160
+
161
+ ```typescript
162
+ // Example warning output
163
+ "PagerDuty handler: endpoint or apiKey (routing_key) not configured. Logs will be dropped.";
164
+ "CloudWatch handler: endpoint or apiKey not configured. Note: AWS authentication is complex...";
165
+ ```
166
+
167
+ This provides **immediate feedback** during development instead of silent failures at runtime.
168
+
169
+ ---
170
+
171
+ ## Testing
172
+
173
+ Added comprehensive test suite (`AuthAndEdgeCases.test.ts`) covering:
174
+
175
+ ### Authentication Scenarios
176
+
177
+ - ✅ Clear error messages for 401/403 responses
178
+ - ✅ Configuration warnings for missing credentials
179
+ - ✅ Service-specific auth requirement documentation
180
+
181
+ ### Edge Cases
182
+
183
+ - ✅ Circular reference handling in `TextFormatter`
184
+ - ✅ Deeply nested object formatting (100+ levels)
185
+ - ✅ Non-serializable values (functions, symbols, undefined)
186
+ - ✅ Empty and missing context objects
187
+ - ✅ `JSONFormatter` pass-through behavior
188
+
189
+ **Test Results**: 372 tests passing (12 new authentication/edge case tests)
190
+
191
+ ---
192
+
193
+ ## Security Best Practices
194
+
195
+ ### 1. **Credential Management**
196
+
197
+ ❌ **Don't** hardcode API keys:
198
+
199
+ ```typescript
200
+ const logger = new Logger([
201
+ createDatadogHandler({
202
+ endpoint: "https://...",
203
+ apiKey: "abc123hardcoded", // BAD!
204
+ }),
205
+ ]);
206
+ ```
207
+
208
+ ✅ **Do** use environment variables:
209
+
210
+ ```typescript
211
+ const logger = new Logger([
212
+ createDatadogHandler({
213
+ endpoint: process.env.DATADOG_ENDPOINT,
214
+ apiKey: process.env.DATADOG_API_KEY,
215
+ }),
216
+ ]);
217
+ ```
218
+
219
+ ### 2. **AWS Authentication**
220
+
221
+ ❌ **Don't** use the built-in CloudWatch handler for production:
222
+
223
+ ```typescript
224
+ createCloudWatchHandler({
225
+ endpoint: "...",
226
+ apiKey: process.env.AWS_ACCESS_KEY, // Incomplete!
227
+ });
228
+ ```
229
+
230
+ ✅ **Do** use AWS SDK with automatic credential discovery:
231
+
232
+ ```typescript
233
+ import { CloudWatchLogsClient } from "@aws-sdk/client-cloudwatch-logs";
234
+
235
+ // Automatically uses IAM roles, instance metadata, env vars, etc.
236
+ const client = new CloudWatchLogsClient({ region: "us-east-1" });
237
+ ```
238
+
239
+ ### 3. **Regional Endpoints**
240
+
241
+ Always verify the correct regional endpoint:
242
+
243
+ | Service | US Endpoint | EU Endpoint |
244
+ | ---------- | ---------------------------------------- | --------------------------------------- |
245
+ | PagerDuty | `https://events.pagerduty.com` | `https://events.eu.pagerduty.com` |
246
+ | Datadog | `https://http-intake.logs.datadoghq.com` | `https://http-intake.logs.datadoghq.eu` |
247
+ | Loki | Custom (user-hosted) | Custom (user-hosted) |
248
+ | Prometheus | Custom (user-hosted) | Custom (user-hosted) |
249
+ | CloudWatch | Region-specific AWS endpoint | Region-specific AWS endpoint |
250
+
251
+ ### 4. **Sensitive Data in Logs**
252
+
253
+ Avoid logging sensitive information in `context` fields:
254
+
255
+ ❌ **Don't**:
256
+
257
+ ```typescript
258
+ logger.error("Auth failed", "api.auth", {
259
+ password: "secret123", // BAD!
260
+ apiKey: "xyz789", // BAD!
261
+ });
262
+ ```
263
+
264
+ ✅ **Do**:
265
+
266
+ ```typescript
267
+ logger.error("Auth failed", "api.auth", {
268
+ username: "user@example.com",
269
+ reason: "invalid_credentials",
270
+ timestamp: Date.now(),
271
+ });
272
+ ```
273
+
274
+ ---
275
+
276
+ ## Troubleshooting
277
+
278
+ ### "401 Unauthorized" Errors
279
+
280
+ **PagerDuty**:
281
+
282
+ 1. Verify `routing_key` matches Integration Key from PagerDuty service
283
+ 2. Check service is not disabled
284
+ 3. Verify endpoint URL (US vs EU)
285
+
286
+ **Datadog**:
287
+
288
+ 1. Verify API key is valid and active
289
+ 2. Check regional endpoint (US vs EU)
290
+ 3. Ensure key has `logs_write` permission
291
+
292
+ **Loki**:
293
+
294
+ 1. Try multiple auth methods (Bearer, Basic Auth, X-Scope-OrgID)
295
+ 2. Check Loki tenant configuration if using multi-tenancy
296
+ 3. Verify endpoint URL includes `/loki/api/v1/push`
297
+
298
+ ### "403 Forbidden" Errors
299
+
300
+ **CloudWatch**:
301
+
302
+ 1. Verify IAM user/role has `logs:PutLogEvents` permission
303
+ 2. Check CloudWatch log group exists
304
+ 3. Ensure log stream is created or auto-creation is allowed
305
+
306
+ **Prometheus**:
307
+
308
+ 1. Verify Pushgateway allows writes
309
+ 2. Check network ACLs/firewalls
310
+ 3. Try adding HTTP Basic Auth via `config.headers`
311
+
312
+ ### "Connection Refused" Errors
313
+
314
+ 1. Verify endpoint URL is correct
315
+ 2. Check service is running and accessible
316
+ 3. Verify firewall/VPN rules
317
+ 4. Test connectivity: `curl -v <endpoint>`
318
+
319
+ ### Circular Reference Errors
320
+
321
+ If you see `[Unable to stringify: ...]` in formatted logs:
322
+
323
+ 1. **Root cause**: Your `context` object has circular references
324
+ 2. **Impact**: Context is not fully logged (but system doesn't crash)
325
+ 3. **Solution**: Sanitize context before logging:
326
+
327
+ ```typescript
328
+ // Remove circular references before logging
329
+ function sanitizeContext(obj: any): any {
330
+ const seen = new WeakSet();
331
+ return JSON.parse(
332
+ JSON.stringify(obj, (key, value) => {
333
+ if (typeof value === "object" && value !== null) {
334
+ if (seen.has(value)) return "[Circular]";
335
+ seen.add(value);
336
+ }
337
+ return value;
338
+ })
339
+ );
340
+ }
341
+
342
+ logger.info("Process started", "app.init", sanitizeContext(config));
343
+ ```
344
+
345
+ ---
346
+
347
+ ## Migration Guide
348
+
349
+ If you're upgrading from a previous version:
350
+
351
+ ### Breaking Changes
352
+
353
+ **None** - All changes are backward compatible.
354
+
355
+ ### New Features
356
+
357
+ 1. **Circular reference protection** - Automatic, no config needed
358
+ 2. **Better error messages** - Automatic, no config needed
359
+ 3. **Configuration warnings** - Shows at handler creation time
360
+
361
+ ### Recommended Actions
362
+
363
+ 1. **Review CloudWatch usage**: Migrate to AWS SDK if using CloudWatch handler
364
+ 2. **Add credential validation**: Check for missing env vars at startup
365
+ 3. **Update error handling**: Catch and log authentication errors specifically
366
+
367
+ Example:
368
+
369
+ ```typescript
370
+ try {
371
+ await logger.info("Test connection", "init");
372
+ } catch (error) {
373
+ if (
374
+ error instanceof Error &&
375
+ error.message.includes("authentication failed")
376
+ ) {
377
+ console.error("Backend authentication error:", error.message);
378
+ console.error(
379
+ "Check environment variables: DATADOG_API_KEY, LOKI_ENDPOINT, etc."
380
+ );
381
+ process.exit(1);
382
+ }
383
+ throw error;
384
+ }
385
+ ```
386
+
387
+ ---
388
+
389
+ ## References
390
+
391
+ - **PagerDuty Events API**: https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgw-events-api-v2-overview
392
+ - **Datadog HTTP API**: https://docs.datadoghq.com/api/latest/logs/
393
+ - **Loki HTTP API**: https://grafana.com/docs/loki/latest/api/
394
+ - **Prometheus Pushgateway**: https://prometheus.io/docs/practices/pushing/
395
+ - **AWS CloudWatch Logs SDK**: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/cloudwatch-logs/
396
+ - **W3C Trace Context**: https://www.w3.org/TR/trace-context/