unnbound-logger-sdk 3.0.10 → 3.0.11

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 CHANGED
@@ -5,19 +5,20 @@ A structured logging library with TypeScript support built on Pino. Provides con
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install unnbound-logger
8
+ npm install unnbound-logger-sdk
9
9
  ```
10
10
 
11
11
  ## Basic Usage
12
12
 
13
13
  ```typescript
14
- import { logger } from 'unnbound-logger';
14
+ import { logger } from 'unnbound-logger-sdk';
15
15
 
16
16
  // Log with string messages
17
17
  logger.info('Application started');
18
18
  logger.warn('Resource usage high');
19
19
  logger.error({ err: new Error('Database connection failed') }, 'Something bad happened');
20
20
  logger.debug('Debug information');
21
+ logger.trace('Trace information');
21
22
 
22
23
  // Log with object messages (merged into top level)
23
24
  logger.info({ event: 'user_login', userId: '123' }, 'Event received.');
@@ -34,17 +35,20 @@ All logs follow a standardized format based on Pino with additional context:
34
35
 
35
36
  ```typescript
36
37
  interface Log<T extends LogType = 'general'> {
37
- level: LogLevel; // "info" | "debug" | "error" | "warn"
38
+ logId: string; // Automatically generated unique ID for each log entry
39
+ level: LogLevel; // "info" | "debug" | "error" | "warn" | "trace"
38
40
  message: string;
41
+ type: T; // "general" | "http" | "sftp"
39
42
  traceId?: string; // Automatically included when in trace context
40
43
  spanId?: string; // Automatically included when in span context
41
- type?: T; // "general" | "http" | "sftp" | "dbQueryTransaction"
42
44
  serviceId?: string; // From UNNBOUND_SERVICE_ID environment variable
43
45
  deploymentId?: string; // From UNNBOUND_DEPLOYMENT_ID environment variable
44
46
  workflowId?: string; // From UNNBOUND_WORKFLOW_ID environment variable
45
47
  environment?: string; // From ENVIRONMENT environment variable
46
48
  err?: unknown; // Only present for Error objects
47
49
  duration?: number; // Duration in milliseconds for span operations
50
+ http?: T extends 'http' ? HttpPayload : never;
51
+ sftp?: T extends 'sftp' ? SftpPayload : never;
48
52
  }
49
53
  ```
50
54
 
@@ -68,7 +72,7 @@ UNNBOUND_SERVICE_ID=order-service
68
72
 
69
73
  ```typescript
70
74
  // Import the logger - workflowId and serviceId are automatically set from environment
71
- import { logger } from 'unnbound-logger';
75
+ import { logger } from 'unnbound-logger-sdk';
72
76
  ```
73
77
 
74
78
  ### Deployment Tracking
@@ -128,7 +132,7 @@ This follows Pino's standard behavior where all object properties are merged int
128
132
  ## HTTP Request/Response Logging
129
133
 
130
134
  ```typescript
131
- import { logger, traceMiddleware } from 'unnbound-logger';
135
+ import { logger, traceMiddleware } from 'unnbound-logger-sdk';
132
136
  import express from 'express';
133
137
 
134
138
  const app = express();
@@ -169,7 +173,7 @@ export UNNBOUND_WORKFLOW_URL="https://api.yourservice.com"
169
173
 
170
174
  ```typescript
171
175
  import express from 'express';
172
- import { traceMiddleware } from 'unnbound-logger';
176
+ import { traceMiddleware } from 'unnbound-logger-sdk';
173
177
 
174
178
  const app = express();
175
179
 
@@ -190,6 +194,45 @@ app.post('/webhooks/github', (req, res) => {
190
194
 
191
195
  This ensures webhook logs contain the complete URL for easy debugging and monitoring.
192
196
 
197
+ ## SFTP Operations Logging
198
+
199
+ The logger supports structured logging for SFTP operations with automatic span tracking:
200
+
201
+ ```typescript
202
+ import { logger, startSpan } from 'unnbound-logger-sdk';
203
+
204
+ // Example SFTP operation with automatic logging
205
+ const uploadFile = async (filePath: string, content: string) => {
206
+ return await startSpan(
207
+ 'SFTP upload operation',
208
+ async () => {
209
+ // Your SFTP upload logic here
210
+ logger.info('Uploading file', { filePath, contentLength: content.length });
211
+ return { success: true, filePath };
212
+ },
213
+ (result) => ({
214
+ type: 'sftp',
215
+ sftp: {
216
+ host: 'sftp.example.com',
217
+ operation: 'upload',
218
+ path: filePath,
219
+ content: content,
220
+ bytes: content.length,
221
+ },
222
+ })
223
+ );
224
+ };
225
+ ```
226
+
227
+ The SFTP logging automatically captures:
228
+
229
+ - Host information
230
+ - Operation type (connect, upload, download, list, delete, etc.)
231
+ - File paths and content
232
+ - Byte counts for transfers
233
+ - Operation duration
234
+ - Success/failure status
235
+
193
236
  ## Middleware Usage
194
237
 
195
238
  ### Express Trace Middleware
@@ -197,7 +240,7 @@ This ensures webhook logs contain the complete URL for easy debugging and monito
197
240
  The library provides a comprehensive trace middleware for Express applications that automatically handles trace context and HTTP logging:
198
241
 
199
242
  ```typescript
200
- import { traceMiddleware } from 'unnbound-logger';
243
+ import { traceMiddleware } from 'unnbound-logger-sdk';
201
244
  import express from 'express';
202
245
 
203
246
  const app = express();
@@ -221,7 +264,7 @@ The trace middleware automatically:
221
264
  For comprehensive logging of outgoing HTTP requests made with Axios:
222
265
 
223
266
  ```typescript
224
- import { traceAxios } from 'unnbound-logger';
267
+ import { traceAxios } from 'unnbound-logger-sdk';
225
268
  import axios from 'axios';
226
269
 
227
270
  // Create an axios instance and wrap it with tracing
@@ -245,7 +288,7 @@ The Axios middleware:
245
288
  In case the function doesn't run inside an HTTP handler (for example a cron job), you can assign a trace id manually by using the `withTrace` function:
246
289
 
247
290
  ```typescript
248
- import { withTrace } from 'unnbound-logger';
291
+ import { withTrace } from 'unnbound-logger-sdk';
249
292
 
250
293
  const operation = async (value: number) => {
251
294
  // This will log a { traceId, value }
@@ -261,7 +304,7 @@ setInterval(() => withTrace(() => operation(13)), 1000);
261
304
  The `startSpan` function allows you to wrap any async operation with automatic span tracking and logging. This is particularly useful for maintaining consistent trace IDs across async operations and distributed systems:
262
305
 
263
306
  ```typescript
264
- import { logger, startSpan } from 'unnbound-logger';
307
+ import { logger, startSpan } from 'unnbound-logger-sdk';
265
308
 
266
309
  // Example: Wrapping a function with span tracking
267
310
  const operation = async (value: number) => {
@@ -320,17 +363,22 @@ The main logger instance that provides all logging functionality using Pino.
320
363
  #### Usage
321
364
 
322
365
  ```typescript
323
- import { logger } from 'unnbound-logger';
366
+ import { logger } from 'unnbound-logger-sdk';
324
367
  ```
325
368
 
326
369
  The logger is a Pino instance with additional context automatically included from environment variables and trace context.
327
370
 
328
371
  #### Methods
329
372
 
373
+ - `logger.trace(object: {}, message: string): void`
374
+ - `logger.trace(message: string): void`
375
+ - `logger.debug(object: {}, message: string): void`
376
+ - `logger.debug(message: string): void`
330
377
  - `logger.info(object: {}, message: string): void`
378
+ - `logger.info(message: string): void`
331
379
  - `logger.warn(object: {}, message: string): void`
332
- - `logger.error(object: {}, message: string): void`
333
- - `logger.debug(object: {}, message: string): void`
380
+ - `logger.warn(message: string): void`
381
+ - `logger.error<O extends { err: unknown }>(object: O, message: string): void`
334
382
 
335
383
  ### traceMiddleware
336
384
 
@@ -339,7 +387,7 @@ Express middleware for automatic HTTP request/response logging and trace context
339
387
  #### Usage
340
388
 
341
389
  ```typescript
342
- import { traceMiddleware } from 'unnbound-logger';
390
+ import { traceMiddleware } from 'unnbound-logger-sdk';
343
391
 
344
392
  app.use(traceMiddleware(options?: HttpOptions));
345
393
  ```
@@ -356,7 +404,7 @@ Wraps an Axios instance with automatic request/response logging and trace contex
356
404
  #### Usage
357
405
 
358
406
  ```typescript
359
- import { traceAxios } from 'unnbound-logger';
407
+ import { traceAxios } from 'unnbound-logger-sdk';
360
408
  import axios from 'axios';
361
409
 
362
410
  const client = traceAxios(axios.create(), options?: HttpOptions);
@@ -369,7 +417,7 @@ Creates a span for tracking async operations with automatic logging and duration
369
417
  #### Usage
370
418
 
371
419
  ```typescript
372
- import { startSpan } from 'unnbound-logger';
420
+ import { startSpan } from 'unnbound-logger-sdk';
373
421
 
374
422
  const result = await startSpan<T>(
375
423
  spanName: string,
@@ -384,6 +432,19 @@ const result = await startSpan<T>(
384
432
  - `callback`: The async function to execute within the span
385
433
  - `getter`: Optional function to generate log payload based on operation result/error
386
434
 
435
+ ### getTraceId
436
+
437
+ Generates a new trace ID for manual trace context management.
438
+
439
+ #### Usage
440
+
441
+ ```typescript
442
+ import { getTraceId } from 'unnbound-logger-sdk';
443
+
444
+ const traceId = getTraceId();
445
+ console.log(traceId); // "550e8400-e29b-41d4-a716-446655440000"
446
+ ```
447
+
387
448
  ### Environment Variables
388
449
 
389
450
  - `UNNBOUND_WORKFLOW_ID` - Workflow identifier (included in all logs)
package/dist/axios.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Axios, type AxiosRequestConfig, type AxiosResponse } from 'axios';
1
+ import { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
2
2
  import { HttpOptions } from './types';
3
3
  type GetPayload = (config: AxiosRequestConfig, res?: AxiosResponse) => object;
4
4
  /**
@@ -7,5 +7,5 @@ type GetPayload = (config: AxiosRequestConfig, res?: AxiosResponse) => object;
7
7
  * @param options - Configuration options for HTTP tracing
8
8
  * @returns The wrapped axios instance with span tracking
9
9
  */
10
- export declare const traceAxios: (client: Axios, { ignoreTraceRoutes, traceHeaderKey, getPayload, }?: HttpOptions<GetPayload>) => Axios;
10
+ export declare const traceAxios: (client: AxiosInstance, { ignoreTraceRoutes, traceHeaderKey, getPayload, }?: HttpOptions<GetPayload>) => AxiosInstance;
11
11
  export {};
@@ -1,3 +1 @@
1
- export declare const internal: () => {
2
- _internal: boolean;
3
- };
1
+ export declare const internal: () => Record<string, unknown>;
package/dist/internal.js CHANGED
@@ -1,5 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.internal = void 0;
4
- const internal = () => ({ _internal: true });
4
+ const o = { _internal: true };
5
+ // Internal logs should be hidden in sandbox
6
+ // TODO: Find a better way to detect sandbox
7
+ if (process.env.UNNBOUND_IDLE_TIMEOUT)
8
+ o._hide = true;
9
+ const internal = () => o;
5
10
  exports.internal = internal;
package/dist/logger.js CHANGED
@@ -28,6 +28,15 @@ exports.logger = (0, pino_1.default)({
28
28
  formatters: {
29
29
  level: (level) => ({ level }),
30
30
  },
31
+ hooks: {
32
+ logMethod(args, method) {
33
+ const firstArg = args[0];
34
+ if (!!firstArg && typeof firstArg === 'object' && '_hide' in firstArg && firstArg._hide)
35
+ return;
36
+ // Otherwise log normally
37
+ method.apply(this, args);
38
+ },
39
+ },
31
40
  redact: {
32
41
  paths: [
33
42
  'http.request.headers.authorization',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unnbound-logger-sdk",
3
3
  "description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.",
4
- "version": "3.0.10",
4
+ "version": "3.0.11",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "keywords": [