@dex-monit/observability-sdk-node 1.0.14 → 1.0.15

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 (2) hide show
  1. package/README.md +302 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,302 @@
1
+ # @dex-monit/observability-sdk-node
2
+
3
+ NestJS SDK for Dex Monitoring - Automatic error tracking, log management, and HTTP tracing.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @dex-monit/observability-sdk-node
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - ✅ **Automatic Error Capture** - Catches all unhandled exceptions
14
+ - ✅ **Console Capture** - Intercepts `console.log`, `console.warn`, `console.error`
15
+ - ✅ **NestJS Logger Capture** - Intercepts native `Logger.log`, `Logger.warn`, `Logger.error`
16
+ - ✅ **HTTP Request Tracing** - Records all incoming HTTP requests with timing
17
+ - ✅ **Request Context** - Automatic `requestId` propagation
18
+ - ✅ **Breadcrumbs** - Track events leading up to errors
19
+ - ✅ **Source Code Context** - Displays code snippets around errors
20
+ - ✅ **Zero Configuration** - Works out of the box
21
+
22
+ ## Quick Start
23
+
24
+ ### 1. Import the Module
25
+
26
+ ```typescript
27
+ // app.module.ts
28
+ import { Module } from '@nestjs/common';
29
+ import { SdkNodeModule } from '@dex-monit/observability-sdk-node';
30
+
31
+ @Module({
32
+ imports: [
33
+ SdkNodeModule.forRoot({
34
+ logger: {
35
+ serviceName: 'my-api',
36
+ environment: process.env.NODE_ENV || 'development',
37
+ },
38
+ monitoring: {
39
+ apiKey: process.env.DEX_MONITORING_API_KEY,
40
+ apiUrl: process.env.DEX_MONITORING_API_URL || 'https://monit-api.example.com/api',
41
+ project: 'my-project',
42
+ environment: process.env.NODE_ENV || 'development',
43
+ },
44
+ }),
45
+ // ... other modules
46
+ ],
47
+ })
48
+ export class AppModule {}
49
+ ```
50
+
51
+ ### 2. That's It! 🎉
52
+
53
+ The SDK automatically:
54
+ - Captures all unhandled errors
55
+ - Captures all console logs
56
+ - Captures all NestJS Logger calls
57
+ - Records HTTP request traces
58
+ - Generates unique request IDs
59
+
60
+ ## Configuration
61
+
62
+ ### Full Configuration Options
63
+
64
+ ```typescript
65
+ SdkNodeModule.forRoot({
66
+ // Logger configuration
67
+ logger: {
68
+ serviceName: 'my-api', // Required: Your service name
69
+ environment: 'production', // Required: Environment
70
+ level: 'info', // Optional: Minimum log level (default: 'info')
71
+ },
72
+
73
+ // Monitoring client configuration
74
+ monitoring: {
75
+ apiKey: 'your-api-key', // Required: API key from Dex Monitoring
76
+ apiUrl: 'https://api.example.com/api', // Required: Monitoring API URL
77
+ project: 'my-project', // Required: Project identifier
78
+ environment: 'production', // Required: Environment
79
+ release: '1.0.0', // Optional: Release/version
80
+ serverName: 'api-server-1', // Optional: Server identifier
81
+ debug: false, // Optional: Enable debug mode
82
+ },
83
+
84
+ // Optional settings
85
+ remoteLogLevel: 'info', // Minimum level to send remotely (default: 'debug')
86
+ captureConsole: true, // Capture console.* calls (default: true)
87
+ captureNestLogger: true, // Capture NestJS Logger (default: true)
88
+ captureHttpRequests: true, // Record HTTP traces (default: true)
89
+ });
90
+ ```
91
+
92
+ ## Using the Logger
93
+
94
+ ### Option 1: DexLoggerService (Recommended)
95
+
96
+ ```typescript
97
+ import { Injectable } from '@nestjs/common';
98
+ import { DexLoggerService, DEX_LOGGER_TOKEN } from '@dex-monit/observability-sdk-node';
99
+
100
+ @Injectable()
101
+ export class MyService {
102
+ constructor(
103
+ @Inject(DEX_LOGGER_TOKEN) private readonly logger: DexLoggerService,
104
+ ) {}
105
+
106
+ doSomething() {
107
+ this.logger.log('Processing started', 'MyService');
108
+ this.logger.debug('Debug info', 'MyService');
109
+ this.logger.warn('Warning message', 'MyService');
110
+ this.logger.error('Error occurred', 'stack trace', 'MyService');
111
+ }
112
+ }
113
+ ```
114
+
115
+ ### Option 2: Native NestJS Logger (Auto-captured)
116
+
117
+ ```typescript
118
+ import { Injectable, Logger } from '@nestjs/common';
119
+
120
+ @Injectable()
121
+ export class MyService {
122
+ private readonly logger = new Logger(MyService.name);
123
+
124
+ doSomething() {
125
+ // These are automatically captured and sent to monitoring
126
+ this.logger.log('Processing started');
127
+ this.logger.warn('Warning message');
128
+ this.logger.error('Error occurred');
129
+ }
130
+ }
131
+ ```
132
+
133
+ ### Option 3: Console (Auto-captured)
134
+
135
+ ```typescript
136
+ // These are automatically captured and sent to monitoring
137
+ console.log('Info message');
138
+ console.warn('Warning message');
139
+ console.error('Error message');
140
+ ```
141
+
142
+ ## Manual Error Capture
143
+
144
+ ```typescript
145
+ import { Injectable, Inject } from '@nestjs/common';
146
+ import { MonitoringClient, MONITORING_CLIENT_TOKEN } from '@dex-monit/observability-sdk-node';
147
+
148
+ @Injectable()
149
+ export class MyService {
150
+ constructor(
151
+ @Inject(MONITORING_CLIENT_TOKEN) private readonly monitoring: MonitoringClient,
152
+ ) {}
153
+
154
+ async processPayment() {
155
+ try {
156
+ await this.paymentGateway.charge();
157
+ } catch (error) {
158
+ // Manually capture with extra context
159
+ this.monitoring.captureException(error, {
160
+ user: { id: 'user-123', email: 'user@example.com' },
161
+ tags: { component: 'payment', gateway: 'stripe' },
162
+ extra: { orderId: 'order-456', amount: 99.99 },
163
+ });
164
+ throw error;
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ ## Breadcrumbs
171
+
172
+ Track events leading up to errors:
173
+
174
+ ```typescript
175
+ import { addBreadcrumb } from '@dex-monit/observability-sdk-node';
176
+
177
+ // Add a breadcrumb
178
+ addBreadcrumb({
179
+ category: 'user.action',
180
+ message: 'User clicked checkout button',
181
+ level: 'info',
182
+ data: { cartItems: 3 },
183
+ });
184
+
185
+ // HTTP breadcrumbs are added automatically for HTTP traces
186
+ ```
187
+
188
+ ## User Context
189
+
190
+ Set user information for error tracking:
191
+
192
+ ```typescript
193
+ import { Injectable, Inject } from '@nestjs/common';
194
+ import { MonitoringClient, MONITORING_CLIENT_TOKEN } from '@dex-monit/observability-sdk-node';
195
+
196
+ @Injectable()
197
+ export class AuthService {
198
+ constructor(
199
+ @Inject(MONITORING_CLIENT_TOKEN) private readonly monitoring: MonitoringClient,
200
+ ) {}
201
+
202
+ onLogin(user: User) {
203
+ this.monitoring.setUser({
204
+ id: user.id,
205
+ email: user.email,
206
+ username: user.username,
207
+ });
208
+ }
209
+ }
210
+ ```
211
+
212
+ ## HTTP Tracing
213
+
214
+ HTTP requests are automatically traced with:
215
+ - Request method, URL, path
216
+ - Response status code
217
+ - Duration (ms)
218
+ - Client IP address
219
+ - User agent
220
+ - Headers (sensitive data scrubbed)
221
+ - Query parameters
222
+ - Request/response sizes
223
+
224
+ View traces in the Dex Monitoring dashboard under **Traces**.
225
+
226
+ ## Request ID Propagation
227
+
228
+ The SDK automatically:
229
+ 1. Generates a unique `requestId` for each request
230
+ 2. Reads incoming `x-request-id` header (for distributed tracing)
231
+ 3. Sets `x-request-id` on the response
232
+ 4. Includes `requestId` in all logs and errors
233
+
234
+ ## What Gets Captured
235
+
236
+ ### Automatic Capture
237
+ | Type | Captured | Sent to |
238
+ |------|----------|---------|
239
+ | Unhandled exceptions | ✅ | Errors |
240
+ | Promise rejections | ✅ | Errors |
241
+ | `console.log/warn/error` | ✅ | Logs |
242
+ | `Logger.log/warn/error` | ✅ | Logs |
243
+ | HTTP requests | ✅ | Traces |
244
+
245
+ ### Error Context
246
+ Each captured error includes:
247
+ - Full stack trace with source code context
248
+ - Request details (URL, method, headers, body)
249
+ - User information (if set)
250
+ - Breadcrumbs (recent events)
251
+ - Runtime info (Node.js version, memory)
252
+ - OS info (platform, version)
253
+ - Custom tags and extra data
254
+
255
+ ## Environment Variables
256
+
257
+ ```env
258
+ # Required
259
+ DEX_MONITORING_API_KEY=your-api-key
260
+ DEX_MONITORING_API_URL=https://monit-api.example.com/api
261
+
262
+ # Optional
263
+ NODE_ENV=production
264
+ ```
265
+
266
+ ## Disabling Features
267
+
268
+ ```typescript
269
+ SdkNodeModule.forRoot({
270
+ logger: { serviceName: 'my-api', environment: 'production' },
271
+ monitoring: { /* ... */ },
272
+
273
+ // Disable specific features
274
+ captureConsole: false, // Don't capture console.*
275
+ captureNestLogger: false, // Don't capture NestJS Logger
276
+ captureHttpRequests: false, // Don't record HTTP traces
277
+ remoteLogLevel: 'error', // Only send errors remotely
278
+ });
279
+ ```
280
+
281
+ ## Dependencies
282
+
283
+ This SDK includes:
284
+ - `@dex-monit/observability-contracts` - TypeScript interfaces
285
+ - `@dex-monit/observability-logger` - Pino-based logger
286
+ - `@dex-monit/observability-request-context` - Request context
287
+ - `@dex-monit/observability-scrubber` - Sensitive data scrubbing
288
+
289
+ ## Peer Dependencies
290
+
291
+ ```json
292
+ {
293
+ "@nestjs/common": "^10.0.0 || ^11.0.0",
294
+ "@nestjs/core": "^10.0.0 || ^11.0.0",
295
+ "rxjs": "^7.0.0 || ^8.0.0",
296
+ "uuid": "^9.0.0 - ^13.0.0"
297
+ }
298
+ ```
299
+
300
+ ## License
301
+
302
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dex-monit/observability-sdk-node",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "NestJS SDK for Dex Monitoring - Error tracking and log management",
5
5
  "keywords": [
6
6
  "observability",