unnbound-logger-sdk 1.1.3 → 1.1.5

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.
@@ -61,15 +61,18 @@ class UnnboundLogger {
61
61
  }
62
62
  // Store request start time for duration calculation
63
63
  config.metadata = { startTime: Date.now() };
64
- // Log the outgoing request
65
- this.info(`HTTP Request: ${config.method?.toUpperCase()} ${config.baseURL || ''}${config.url}`, {
66
- type: 'httpRequest',
67
- httpRequest: {
68
- url: `${config.baseURL || ''}${config.url}`,
69
- method: config.method?.toUpperCase(),
70
- headers: (0, logger_utils_1.filterHeaders)(config.headers),
71
- body: config.data
72
- }
64
+ // Log the outgoing request using proper httpRequest method
65
+ const mockReq = {
66
+ method: config.method?.toUpperCase() || 'UNKNOWN',
67
+ url: `${config.baseURL || ''}${config.url}`,
68
+ originalUrl: `${config.baseURL || ''}${config.url}`,
69
+ headers: config.headers || {},
70
+ body: config.data,
71
+ ip: 'outgoing' // Mark as outgoing request
72
+ };
73
+ this.httpRequest(mockReq, {
74
+ traceId,
75
+ startTime: config.metadata.startTime
73
76
  });
74
77
  return config;
75
78
  },
@@ -83,17 +86,25 @@ class UnnboundLogger {
83
86
  // Calculate duration
84
87
  const startTime = response.config.metadata?.startTime || Date.now();
85
88
  const duration = Date.now() - startTime;
86
- // Log the successful response
87
- this.info(`HTTP Response: ${response.config.method?.toUpperCase()} ${response.config.baseURL || ''}${response.config.url} - ${response.status}`, {
88
- type: 'httpResponse',
89
+ // Log the successful response using proper httpResponse method
90
+ const mockReq = {
91
+ method: response.config.method?.toUpperCase() || 'UNKNOWN',
92
+ url: `${response.config.baseURL || ''}${response.config.url}`,
93
+ originalUrl: `${response.config.baseURL || ''}${response.config.url}`,
94
+ ip: 'outgoing' // Mark as outgoing request
95
+ };
96
+ const mockRes = {
97
+ statusCode: response.status,
98
+ locals: {
99
+ body: response.data,
100
+ startTime: startTime,
101
+ traceId: trace_context_1.traceContext.getTraceId()
102
+ },
103
+ getHeaders: () => response.headers || {}
104
+ };
105
+ this.httpResponse(mockRes, mockReq, {
89
106
  duration,
90
- httpResponse: {
91
- url: `${response.config.baseURL || ''}${response.config.url}`,
92
- method: response.config.method?.toUpperCase(),
93
- status: response.status,
94
- headers: (0, logger_utils_1.filterHeaders)(response.headers),
95
- body: response.data
96
- }
107
+ traceId: trace_context_1.traceContext.getTraceId()
97
108
  });
98
109
  return response;
99
110
  },
@@ -101,21 +112,30 @@ class UnnboundLogger {
101
112
  // Calculate duration for error responses
102
113
  const startTime = error.config?.metadata?.startTime || Date.now();
103
114
  const duration = Date.now() - startTime;
104
- // Log the error response
115
+ // Log the error response using proper httpResponse method
105
116
  if (error.response) {
106
- this.error(`HTTP Error Response: ${error.config?.method?.toUpperCase()} ${error.config?.baseURL || ''}${error.config?.url} - ${error.response.status}`, {
107
- type: 'httpResponse',
117
+ const mockReq = {
118
+ method: error.config?.method?.toUpperCase() || 'UNKNOWN',
119
+ url: `${error.config?.baseURL || ''}${error.config?.url}`,
120
+ originalUrl: `${error.config?.baseURL || ''}${error.config?.url}`,
121
+ ip: 'outgoing' // Mark as outgoing request
122
+ };
123
+ const mockRes = {
124
+ statusCode: error.response.status,
125
+ locals: {
126
+ body: error.response.data,
127
+ startTime: startTime,
128
+ traceId: trace_context_1.traceContext.getTraceId()
129
+ },
130
+ getHeaders: () => error.response.headers || {}
131
+ };
132
+ this.httpResponse(mockRes, mockReq, {
108
133
  duration,
109
- httpResponse: {
110
- url: `${error.config?.baseURL || ''}${error.config?.url}`,
111
- method: error.config?.method?.toUpperCase(),
112
- status: error.response.status,
113
- headers: (0, logger_utils_1.filterHeaders)(error.response.headers),
114
- body: error.response.data
115
- }
134
+ traceId: trace_context_1.traceContext.getTraceId()
116
135
  });
117
136
  }
118
137
  else {
138
+ // For network errors without response, log as general error
119
139
  this.error(`HTTP Request Failed: ${error.config?.method?.toUpperCase()} ${error.config?.baseURL || ''}${error.config?.url}`, {
120
140
  context: 'No response received',
121
141
  error: error.message
@@ -264,7 +284,7 @@ class UnnboundLogger {
264
284
  url: req.originalUrl || req.url,
265
285
  method: req.method,
266
286
  headers: (0, logger_utils_1.filterHeaders)(req.headers),
267
- ip: req.ip,
287
+ ip: (0, logger_utils_1.normalizeIp)(req.ip),
268
288
  body: req.body,
269
289
  },
270
290
  };
@@ -305,7 +325,7 @@ class UnnboundLogger {
305
325
  url: req.originalUrl || req.url,
306
326
  method: req.method,
307
327
  headers: (0, logger_utils_1.filterHeaders)(res.getHeaders()),
308
- ip: req.ip,
328
+ ip: (0, logger_utils_1.normalizeIp)(req.ip),
309
329
  status: res.statusCode,
310
330
  body: res.locals.body,
311
331
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unnbound-logger-sdk",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging across different operational contexts with automatic trace ID propagation.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",