@nicollasfrazao/liguelead-log-service 1.2.19 → 1.3.1

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
@@ -2,6 +2,18 @@
2
2
 
3
3
  Este é um **serviço de logging standalone** para aplicações Express com armazenamento multi-destino (arquivos locais + S3 via Kinesis Firehose) e rastreamento abrangente de requisições. O serviço utiliza o **padrão strategy** com classes base abstratas para destinos de armazenamento.
4
4
 
5
+ ## 🚀 AWS Lambda Ready
6
+
7
+ **Novo**: Totalmente otimizado para AWS Lambda com detecção automática de ambiente e configurações inteligentes:
8
+ - ✅ **Detecção automática** de ambiente Lambda
9
+ - ✅ **Timeouts otimizados** para evitar timeouts da Lambda
10
+ - ✅ **Autenticação inteligente** usando IAM role da Lambda
11
+ - ✅ **Logs compatíveis** com CloudWatch
12
+ - ✅ **Cache de credenciais** otimizado para cold starts
13
+ - ✅ **Monitoramento de timeout** em tempo real
14
+
15
+ 📖 **Guia Completo**: [Lambda Integration Guide](./docs/lambda-integration.md)
16
+
5
17
  ## Instalação
6
18
 
7
19
  ```bash
@@ -177,6 +189,10 @@ LogService.info('Log batch', logs); // Array de logs pré-formatados
177
189
  - ✅ **Autenticação via IAM Role ARN** (AssumeRole automático, cache, renovação, cross-account)
178
190
  - 🛡️ **Resilência de rede** com retry automático e backoff exponencial para conexões Firehose
179
191
  - 🔄 **Recovery automático** de erros transitórios como `socket hang up` e `write EPIPE`
192
+ - 🔑 **Gerenciamento inteligente de credenciais** com detecção e recovery automático de erros de "Signature expired" (v1.2.17+)
193
+ - 🚀 **Compatibilidade com AWS Lambda** - otimização automática de timeouts, retries e autenticação (v1.2.17+)
194
+ - ⏱️ **Monitoramento de timeout Lambda** - prevenção automática de operações que causariam timeout
195
+ - 📊 **Logs compatíveis com CloudWatch** - formatação JSON estruturada para análise
180
196
 
181
197
  ## Estrutura dos Arquivos de Log
182
198
 
@@ -307,6 +323,10 @@ LOG_AWS_SECRET_ACCESS_KEY=test # Secret Key (dev only)
307
323
  LOG_INCLUDE_REQUEST_BODY=true # Inclui corpo da requisição
308
324
  LOG_INCLUDE_RESPONSE_BODY=true # Inclui corpo da resposta
309
325
  LOG_MAX_BODY_SIZE=5000 # Tamanho máximo dos corpos (bytes)
326
+
327
+ # Configurações avançadas de credenciais AWS (v1.2.17+)
328
+ LOG_AWS_CREDENTIALS_MAX_RETRIES=3 # Máximo de tentativas para erros de credenciais
329
+ LOG_AWS_CREDENTIALS_CACHE_BUFFER_MS=300000 # Buffer antes da expiração (5min padrão)
310
330
  ```
311
331
 
312
332
  #### Configuração para Diferentes Ambientes
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.config.d.ts","sourceRoot":"","sources":["../../src/configs/log.storage.external.s3.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0CAA0C,EAAE,MAAM,gEAAgE,CAAC;AAE5H;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QAAO,0CA4BhD,CAAA"}
1
+ {"version":3,"file":"log.storage.external.s3.config.d.ts","sourceRoot":"","sources":["../../src/configs/log.storage.external.s3.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0CAA0C,EAAE,MAAM,gEAAgE,CAAC;AAG5H;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,QAAO,0CAiEhD,CAAA"}
@@ -1,27 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLogStorageExternalS3Config = void 0;
4
+ const lambda_utils_1 = require("../utils/lambda.utils");
4
5
  /**
5
6
  * Get Log Storage External S3 Configuration
6
7
  *
7
8
  * @returns {LogStorageExternalS3ServiceConfigInterface} Log Storage External S3 Configuration
8
9
  */
9
10
  const getLogStorageExternalS3Config = () => {
11
+ const isLambda = (0, lambda_utils_1.isLambdaEnvironment)();
10
12
  let config = {
11
13
  firehoseStreamName: process.env.LOG_FIREHOSE_STREAM_NAME || 'log-service-firehose',
12
14
  region: process.env.LOG_AWS_REGION || 'us-east-1',
13
15
  version: 'latest',
16
+ maxCredentialsRetries: (0, lambda_utils_1.getLambdaOptimizedRetries)(parseInt(process.env.LOG_AWS_CREDENTIALS_MAX_RETRIES || '3'), parseInt(process.env.LOG_AWS_LAMBDA_CREDENTIALS_MAX_RETRIES || '2')),
17
+ credentialsCacheBufferMs: (0, lambda_utils_1.getLambdaOptimizedCredentialsBuffer)(parseInt(process.env.LOG_AWS_CREDENTIALS_CACHE_BUFFER_MS || '300000')),
18
+ requestTimeout: (0, lambda_utils_1.getLambdaOptimizedTimeout)(parseInt(process.env.LOG_AWS_REQUEST_TIMEOUT_MS || '30000'), parseInt(process.env.LOG_AWS_LAMBDA_REQUEST_TIMEOUT_MS || '15000')),
19
+ maxAttempts: (0, lambda_utils_1.getLambdaOptimizedRetries)(parseInt(process.env.LOG_AWS_MAX_ATTEMPTS || '3'), parseInt(process.env.LOG_AWS_LAMBDA_MAX_ATTEMPTS || '2')),
20
+ useLambdaCredentials: isLambda && !process.env.LOG_AWS_ROLE_ARN && !process.env.LOG_AWS_ACCESS_KEY_ID,
14
21
  };
15
- if (process.env.LOG_AWS_ROLE_ARN) {
16
- config.roleArn = process.env.LOG_AWS_ROLE_ARN;
22
+ if (isLambda
23
+ && !process.env.LOG_FORCE_ASSUME_ROLE) {
24
+ if (process.env.LOG_AWS_ROLE_ARN) {
25
+ config.roleArn = process.env.LOG_AWS_ROLE_ARN;
26
+ }
27
+ else if (process.env.LOG_AWS_ACCESS_KEY_ID
28
+ && process.env.LOG_AWS_SECRET_ACCESS_KEY) {
29
+ config = {
30
+ ...config,
31
+ accessKeyId: process.env.LOG_AWS_ACCESS_KEY_ID,
32
+ secretAccessKey: process.env.LOG_AWS_SECRET_ACCESS_KEY,
33
+ };
34
+ }
17
35
  }
18
- if (process.env.LOG_AWS_ACCESS_KEY_ID
19
- && process.env.LOG_AWS_SECRET_ACCESS_KEY) {
20
- config = {
21
- ...config,
22
- accessKeyId: process.env.LOG_AWS_ACCESS_KEY_ID,
23
- secretAccessKey: process.env.LOG_AWS_SECRET_ACCESS_KEY,
24
- };
36
+ else {
37
+ if (process.env.LOG_AWS_ROLE_ARN) {
38
+ config.roleArn = process.env.LOG_AWS_ROLE_ARN;
39
+ }
40
+ if (process.env.LOG_AWS_ACCESS_KEY_ID
41
+ && process.env.LOG_AWS_SECRET_ACCESS_KEY) {
42
+ config = {
43
+ ...config,
44
+ accessKeyId: process.env.LOG_AWS_ACCESS_KEY_ID,
45
+ secretAccessKey: process.env.LOG_AWS_SECRET_ACCESS_KEY,
46
+ };
47
+ }
25
48
  }
26
49
  if (process.env.LOG_AWS_ENDPOINT) {
27
50
  config.endpoint = process.env.LOG_AWS_ENDPOINT;
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.config.js","sourceRoot":"","sources":["../../src/configs/log.storage.external.s3.config.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACI,MAAM,6BAA6B,GAAG,GAA+C,EAAE;IAE5F,IAAI,MAAM,GAA+C;QACvD,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,sBAAsB;QAClF,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,WAAW;QACjD,OAAO,EAAE,QAAQ;KAClB,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAChD,CAAC;IAED,IACE,OAAO,CAAC,GAAG,CAAC,qBAAqB;WAC9B,OAAO,CAAC,GAAG,CAAC,yBAAyB,EACxC,CAAC;QACD,MAAM,GAAG;YACP,GAAG,MAAM;YACT,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC9C,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;SACvD,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,g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ts CHANGED
@@ -19,4 +19,6 @@ export { LogStorageLocalService } from './services/log.storage.local.service';
19
19
  export { LogStorageExternalS3Service } from './services/log.storage.external.s3.service';
20
20
  export { LogStorageExternalService } from './services/log.storage.external.service';
21
21
  export type { LogStorageBaseServiceInterface } from './interfaces/log.storage.base.service.interface';
22
+ export { isLambdaEnvironment, getLambdaEnvironmentInfo, getLambdaOptimizedTimeout, getLambdaOptimizedRetries, getLambdaOptimizedCredentialsBuffer, hasEnoughLambdaTime } from './utils/lambda.utils';
23
+ export type { LambdaEnvironmentInfo } from './utils/lambda.utils';
22
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG9C,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,YAAY,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC3F,YAAY,EAAE,0CAA0C,EAAE,MAAM,+DAA+D,CAAC;AAGhI,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAGzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAGpF,YAAY,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG9C,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,YAAY,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC3F,YAAY,EAAE,0CAA0C,EAAE,MAAM,+DAA+D,CAAC;AAGhI,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAGzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAGpF,YAAY,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AAGtG,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,mCAAmC,EACnC,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * (local files + S3 via Kinesis Firehose) and comprehensive request tracking.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.LogStorageExternalService = exports.LogStorageExternalS3Service = exports.LogStorageLocalService = exports.LogStorageBaseService = exports.LogStorageService = exports.getLogStorageExternalS3Config = exports.getLogServiceConfig = exports.LogError = exports.logMiddleware = exports.LogService = void 0;
9
+ exports.hasEnoughLambdaTime = exports.getLambdaOptimizedCredentialsBuffer = exports.getLambdaOptimizedRetries = exports.getLambdaOptimizedTimeout = exports.getLambdaEnvironmentInfo = exports.isLambdaEnvironment = exports.LogStorageExternalService = exports.LogStorageExternalS3Service = exports.LogStorageLocalService = exports.LogStorageBaseService = exports.LogStorageService = exports.getLogStorageExternalS3Config = exports.getLogServiceConfig = exports.LogError = exports.logMiddleware = exports.LogService = void 0;
10
10
  // Main service exports
11
11
  var log_service_1 = require("./services/log.service");
12
12
  Object.defineProperty(exports, "LogService", { enumerable: true, get: function () { return log_service_1.LogService; } });
@@ -32,4 +32,12 @@ var log_storage_external_s3_service_1 = require("./services/log.storage.external
32
32
  Object.defineProperty(exports, "LogStorageExternalS3Service", { enumerable: true, get: function () { return log_storage_external_s3_service_1.LogStorageExternalS3Service; } });
33
33
  var log_storage_external_service_1 = require("./services/log.storage.external.service");
34
34
  Object.defineProperty(exports, "LogStorageExternalService", { enumerable: true, get: function () { return log_storage_external_service_1.LogStorageExternalService; } });
35
+ // Lambda utilities exports (for AWS Lambda compatibility)
36
+ var lambda_utils_1 = require("./utils/lambda.utils");
37
+ Object.defineProperty(exports, "isLambdaEnvironment", { enumerable: true, get: function () { return lambda_utils_1.isLambdaEnvironment; } });
38
+ Object.defineProperty(exports, "getLambdaEnvironmentInfo", { enumerable: true, get: function () { return lambda_utils_1.getLambdaEnvironmentInfo; } });
39
+ Object.defineProperty(exports, "getLambdaOptimizedTimeout", { enumerable: true, get: function () { return lambda_utils_1.getLambdaOptimizedTimeout; } });
40
+ Object.defineProperty(exports, "getLambdaOptimizedRetries", { enumerable: true, get: function () { return lambda_utils_1.getLambdaOptimizedRetries; } });
41
+ Object.defineProperty(exports, "getLambdaOptimizedCredentialsBuffer", { enumerable: true, get: function () { return lambda_utils_1.getLambdaOptimizedCredentialsBuffer; } });
42
+ Object.defineProperty(exports, "hasEnoughLambdaTime", { enumerable: true, get: function () { return lambda_utils_1.hasEnoughLambdaTime; } });
35
43
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uBAAuB;AACvB,sDAAoD;AAA3C,yGAAA,UAAU,OAAA;AAEnB,uBAAuB;AACvB,+DAA6D;AAApD,+GAAA,aAAa,OAAA;AAEtB,yBAAyB;AACzB,gDAA8C;AAArC,qGAAA,QAAQ,OAAA;AAUjB,wBAAwB;AACxB,mEAAmE;AAA1D,yHAAA,mBAAmB,OAAA;AAC5B,2FAAyF;AAAhF,+IAAA,6BAA6B,OAAA;AAEtC,+CAA+C;AAC/C,sEAAmE;AAA1D,wHAAA,iBAAiB,OAAA;AAC1B,gFAA4E;AAAnE,iIAAA,qBAAqB,OAAA;AAC9B,kFAA8E;AAArE,mIAAA,sBAAsB,OAAA;AAC/B,8FAAyF;AAAhF,8IAAA,2BAA2B,OAAA;AACpC,wFAAoF;AAA3E,yIAAA,yBAAyB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uBAAuB;AACvB,sDAAoD;AAA3C,yGAAA,UAAU,OAAA;AAEnB,uBAAuB;AACvB,+DAA6D;AAApD,+GAAA,aAAa,OAAA;AAEtB,yBAAyB;AACzB,gDAA8C;AAArC,qGAAA,QAAQ,OAAA;AAUjB,wBAAwB;AACxB,mEAAmE;AAA1D,yHAAA,mBAAmB,OAAA;AAC5B,2FAAyF;AAAhF,+IAAA,6BAA6B,OAAA;AAEtC,+CAA+C;AAC/C,sEAAmE;AAA1D,wHAAA,iBAAiB,OAAA;AAC1B,gFAA4E;AAAnE,iIAAA,qBAAqB,OAAA;AAC9B,kFAA8E;AAArE,mIAAA,sBAAsB,OAAA;AAC/B,8FAAyF;AAAhF,8IAAA,2BAA2B,OAAA;AACpC,wFAAoF;AAA3E,yIAAA,yBAAyB,OAAA;AAKlC,0DAA0D;AAC1D,qDAO8B;AAN5B,mHAAA,mBAAmB,OAAA;AACnB,wHAAA,wBAAwB,OAAA;AACxB,yHAAA,yBAAyB,OAAA;AACzB,yHAAA,yBAAyB,OAAA;AACzB,mIAAA,mCAAmC,OAAA;AACnC,mHAAA,mBAAmB,OAAA"}
@@ -10,6 +10,11 @@
10
10
  * @property {string} accessKeyId - AWS access key ID (optional)
11
11
  * @property {string} secretAccessKey - AWS secret access key (optional)
12
12
  * @property {string} roleArn - AWS IAM role ARN for assume role authentication (optional)
13
+ * @property {number} maxCredentialsRetries - Maximum number of retries for credential-related errors (optional)
14
+ * @property {number} credentialsCacheBufferMs - Buffer time in milliseconds before credentials expiration to refresh cache (optional)
15
+ * @property {number} requestTimeout - Request timeout in milliseconds (optional)
16
+ * @property {number} maxAttempts - Maximum number of attempts for AWS SDK requests (optional)
17
+ * @property {boolean} useLambdaCredentials - Whether to use Lambda's default IAM role credentials (optional)
13
18
  */
14
19
  export interface LogStorageExternalS3ServiceConfigInterface {
15
20
  /**
@@ -40,5 +45,25 @@ export interface LogStorageExternalS3ServiceConfigInterface {
40
45
  * @var {string}
41
46
  */
42
47
  roleArn?: string;
48
+ /**
49
+ * @var {number}
50
+ */
51
+ maxCredentialsRetries?: number;
52
+ /**
53
+ * @var {number}
54
+ */
55
+ credentialsCacheBufferMs?: number;
56
+ /**
57
+ * @var {number}
58
+ */
59
+ requestTimeout?: number;
60
+ /**
61
+ * @var {number}
62
+ */
63
+ maxAttempts?: number;
64
+ /**
65
+ * @var {boolean}
66
+ */
67
+ useLambdaCredentials?: boolean;
43
68
  }
44
69
  //# sourceMappingURL=log.storage.external.s3.service.config.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.service.config.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/log.storage.external.s3.service.config.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,0CAA0C;IAEzD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
1
+ {"version":3,"file":"log.storage.external.s3.service.config.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/log.storage.external.s3.service.config.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,0CAA0C;IAEzD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC"}
@@ -9,6 +9,9 @@ import { LogType } from '../types/log.type';
9
9
  * @property {FirehoseClient} firehose
10
10
  * @property {LogStorageExternalS3ServiceConfigInterface} config
11
11
  * @property {Promise<any> | null} credentialsCache
12
+ * @property {number} maxRetries
13
+ * @property {number} baseDelay
14
+ * @property {number} maxCredentialsRetries
12
15
  */
13
16
  export declare class LogStorageExternalS3Service extends LogStorageExternalService {
14
17
  /**
@@ -23,6 +26,26 @@ export declare class LogStorageExternalS3Service extends LogStorageExternalServi
23
26
  * @var {Promise<any> | null}
24
27
  */
25
28
  private credentialsCache;
29
+ /**
30
+ * @var {number}
31
+ */
32
+ private readonly maxRetries;
33
+ /**
34
+ * @var {number}
35
+ */
36
+ private readonly baseDelay;
37
+ /**
38
+ * @var {number}
39
+ */
40
+ private readonly maxCredentialsRetries;
41
+ /**
42
+ * @var {boolean}
43
+ */
44
+ private readonly isLambdaEnv;
45
+ /**
46
+ * @var {any}
47
+ */
48
+ private lambdaContext;
26
49
  /**
27
50
  * Constructor of the LogStorageS3Service
28
51
  *
@@ -35,6 +58,47 @@ export declare class LogStorageExternalS3Service extends LogStorageExternalServi
35
58
  * @returns {boolean} True if the storage target should be used, false otherwise
36
59
  */
37
60
  shouldUse(): boolean;
61
+ /**
62
+ * Sets the Lambda context for timeout management
63
+ *
64
+ * @param {any} context - Lambda context object
65
+ */
66
+ setLambdaContext(context: any): void;
67
+ /**
68
+ * Checks if there's enough time remaining for an operation in Lambda
69
+ *
70
+ * @param {number} estimatedDurationMs - Estimated operation duration
71
+ *
72
+ * @returns {boolean} True if operation should proceed
73
+ */
74
+ private checkLambdaTimeout;
75
+ /**
76
+ * Determines if an error is credential-related and requires cache invalidation
77
+ *
78
+ * @param {any} error - The error to check
79
+ *
80
+ * @returns {boolean} True if the error is credential-related
81
+ */
82
+ private isCredentialError;
83
+ /**
84
+ * Determines if an error is retryable (network-related)
85
+ *
86
+ * @param {any} error - The error to check
87
+ *
88
+ * @returns {boolean} True if the error is retryable
89
+ */
90
+ private isRetryableError;
91
+ /**
92
+ * Performs retry operation with exponential backoff
93
+ *
94
+ * @param {Function} operation - The operation to retry
95
+ * @param {number} retries - Number of retries remaining
96
+ * @param {number} delay - Initial delay in milliseconds
97
+ * @param {boolean} isCredentialOperation - Whether this is a credential-related operation
98
+ *
99
+ * @returns {Promise<T>} The result of the operation
100
+ */
101
+ private retryWithBackoff;
38
102
  /**
39
103
  * Gets temporary credentials using STS AssumeRole
40
104
  *
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,yBAAyB;IAExE;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAiB;IAEjC;;OAEG;IACH,OAAO,CAAC,MAAM,CAA6C;IAE3D;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAA6B;IAErD;;;;OAIG;gBACU,gBAAgB,EAAE,yBAAyB;IAgCxD;;;;OAIG;IACI,SAAS,IAAI,OAAO;IAK3B;;;;OAIG;YACW,wBAAwB;IAqCtC;;;;OAIG;YACW,4BAA4B;IA8C1C;;;;;;;OAOG;YACW,SAAS;IAqCvB;;;;;;;OAOG;YACW,SAAS;IAyBvB;;;;;;OAMG;IACU,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BnD"}
1
+ {"version":3,"file":"log.storage.external.s3.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAK5C;;;;;;;;;;;GAWG;AACH,qBAAa,2BAA4B,SAAQ,yBAAyB;IAExE;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAiB;IAEjC;;OAEG;IACH,OAAO,CAAC,MAAM,CAA6C;IAE3D;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAA6B;IAErD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAE1C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAS;IAE/C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IAEtC;;OAEG;IACH,OAAO,CAAC,aAAa,CAAa;IAElC;;;;OAIG;gBACU,gBAAgB,EAAE,yBAAyB;IAsCxD;;;;OAIG;IACI,SAAS,IAAI,OAAO;IAK3B;;;;OAIG;IACI,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAU3C;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IA8CzB;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAqCxB;;;;;;;;;OASG;YACW,gBAAgB;IA2H9B;;;;OAIG;YACW,wBAAwB;IAgFtC;;;;OAIG;YACW,4BAA4B;IAoE1C;;;;;;;OAOG;YACW,SAAS;IA2HvB;;;;;;;OAOG;YACW,SAAS;IAmCvB;;;;;;OAMG;IACU,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BnD"}
@@ -7,6 +7,7 @@ const log_storage_external_service_1 = require("./log.storage.external.service")
7
7
  const log_service_1 = require("./log.service");
8
8
  const log_storage_external_s3_config_1 = require("../configs/log.storage.external.s3.config");
9
9
  const log_error_1 = require("../errors/log.error");
10
+ const lambda_utils_1 = require("../utils/lambda.utils");
10
11
  /**
11
12
  * Class LogStorageExternalS3Service
12
13
  *
@@ -15,6 +16,9 @@ const log_error_1 = require("../errors/log.error");
15
16
  * @property {FirehoseClient} firehose
16
17
  * @property {LogStorageExternalS3ServiceConfigInterface} config
17
18
  * @property {Promise<any> | null} credentialsCache
19
+ * @property {number} maxRetries
20
+ * @property {number} baseDelay
21
+ * @property {number} maxCredentialsRetries
18
22
  */
19
23
  class LogStorageExternalS3Service extends log_storage_external_service_1.LogStorageExternalService {
20
24
  /**
@@ -28,14 +32,31 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
28
32
  * @var {Promise<any> | null}
29
33
  */
30
34
  this.credentialsCache = null;
35
+ /**
36
+ * @var {number}
37
+ */
38
+ this.maxRetries = 3;
39
+ /**
40
+ * @var {number}
41
+ */
42
+ this.baseDelay = 1000;
43
+ /**
44
+ * @var {any}
45
+ */
46
+ this.lambdaContext = null;
31
47
  this.config = (0, log_storage_external_s3_config_1.getLogStorageExternalS3Config)();
48
+ this.maxCredentialsRetries = this.config.maxCredentialsRetries || 3;
49
+ this.isLambdaEnv = (0, lambda_utils_1.isLambdaEnvironment)();
32
50
  const firehoseConfig = {
33
51
  region: this.config.region,
34
- requestTimeout: 30000,
35
- maxAttempts: 3,
52
+ requestTimeout: this.config.requestTimeout || 30000,
53
+ maxAttempts: this.config.maxAttempts || 3,
36
54
  retryMode: 'adaptive'
37
55
  };
38
- if (this.config.roleArn) {
56
+ if (this.config.useLambdaCredentials
57
+ && this.isLambdaEnv) {
58
+ }
59
+ else if (this.config.roleArn) {
39
60
  firehoseConfig.credentials = () => this.getAssumeRoleCredentials();
40
61
  }
41
62
  else if (this.config.accessKeyId
@@ -58,6 +79,208 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
58
79
  shouldUse() {
59
80
  return this.logServiceConfig.useS3Storage;
60
81
  }
82
+ /**
83
+ * Sets the Lambda context for timeout management
84
+ *
85
+ * @param {any} context - Lambda context object
86
+ */
87
+ setLambdaContext(context) {
88
+ if (this.isLambdaEnv
89
+ && context) {
90
+ this.lambdaContext = context;
91
+ }
92
+ }
93
+ /**
94
+ * Checks if there's enough time remaining for an operation in Lambda
95
+ *
96
+ * @param {number} estimatedDurationMs - Estimated operation duration
97
+ *
98
+ * @returns {boolean} True if operation should proceed
99
+ */
100
+ checkLambdaTimeout(estimatedDurationMs = 5000) {
101
+ if (!this.isLambdaEnv
102
+ || !this.lambdaContext) {
103
+ return true;
104
+ }
105
+ const hasTime = (0, lambda_utils_1.hasEnoughLambdaTime)(this.lambdaContext, estimatedDurationMs, 3000);
106
+ if (!hasTime) {
107
+ console.warn('Insufficient Lambda time remaining for operation', {
108
+ estimatedDurationMs,
109
+ remainingTimeMs: this.lambdaContext.getRemainingTimeInMillis?.(),
110
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME
111
+ });
112
+ }
113
+ return hasTime;
114
+ }
115
+ /**
116
+ * Determines if an error is credential-related and requires cache invalidation
117
+ *
118
+ * @param {any} error - The error to check
119
+ *
120
+ * @returns {boolean} True if the error is credential-related
121
+ */
122
+ isCredentialError(error) {
123
+ if (!error) {
124
+ return false;
125
+ }
126
+ const errorMessage = error.message?.toLowerCase() || '';
127
+ const errorCode = error.code?.toLowerCase() || '';
128
+ const signatureExpiredPatterns = [
129
+ 'signature expired',
130
+ 'signatureexpired',
131
+ 'signature not yet current',
132
+ 'signaturenotcurrent'
133
+ ];
134
+ const credentialErrorPatterns = [
135
+ 'credentials',
136
+ 'invalid access key',
137
+ 'invalid secret',
138
+ 'invalid security token',
139
+ 'security token expired',
140
+ 'token expired',
141
+ 'unauthorized',
142
+ 'access denied',
143
+ 'invalid credentials'
144
+ ];
145
+ const credentialErrorCodes = [
146
+ 'credentialsnotfound',
147
+ 'expiredtoken',
148
+ 'invalidaccesskeyid',
149
+ 'invalidsecuritytoken',
150
+ 'signatureexpired',
151
+ 'tokenrefreshrequired',
152
+ 'unauthorizedoperation',
153
+ 'accessdenied'
154
+ ];
155
+ return signatureExpiredPatterns.some(pattern => errorMessage.includes(pattern))
156
+ || credentialErrorPatterns.some(pattern => errorMessage.includes(pattern))
157
+ || credentialErrorCodes.some(code => errorCode.includes(code))
158
+ || error.$metadata?.httpStatusCode === 401
159
+ || error.$metadata?.httpStatusCode === 403;
160
+ }
161
+ /**
162
+ * Determines if an error is retryable (network-related)
163
+ *
164
+ * @param {any} error - The error to check
165
+ *
166
+ * @returns {boolean} True if the error is retryable
167
+ */
168
+ isRetryableError(error) {
169
+ if (!error) {
170
+ return false;
171
+ }
172
+ const retryableCodes = [
173
+ 'ECONNRESET',
174
+ 'ECONNREFUSED',
175
+ 'ETIMEDOUT',
176
+ 'EPIPE',
177
+ 'EHOSTUNREACH',
178
+ 'ENETUNREACH',
179
+ 'EAI_AGAIN',
180
+ 'ENOTFOUND'
181
+ ];
182
+ const retryableMessages = [
183
+ 'socket hang up',
184
+ 'network timeout',
185
+ 'connection timeout',
186
+ 'write EPIPE',
187
+ 'read ECONNRESET',
188
+ 'connection refused',
189
+ 'service unavailable',
190
+ 'throttling'
191
+ ];
192
+ const errorMessage = error.message?.toLowerCase() || '';
193
+ const errorCode = error.code?.toUpperCase() || '';
194
+ return retryableCodes.includes(errorCode)
195
+ || retryableMessages.some(msg => errorMessage.includes(msg))
196
+ || error.$metadata?.httpStatusCode >= 500
197
+ || error.$metadata?.httpStatusCode === 429;
198
+ }
199
+ /**
200
+ * Performs retry operation with exponential backoff
201
+ *
202
+ * @param {Function} operation - The operation to retry
203
+ * @param {number} retries - Number of retries remaining
204
+ * @param {number} delay - Initial delay in milliseconds
205
+ * @param {boolean} isCredentialOperation - Whether this is a credential-related operation
206
+ *
207
+ * @returns {Promise<T>} The result of the operation
208
+ */
209
+ async retryWithBackoff(operation, retries = this.maxRetries, delay = this.baseDelay, isCredentialOperation = false) {
210
+ try {
211
+ return await operation();
212
+ }
213
+ catch (error) {
214
+ const isCredentialError = this.isCredentialError(error);
215
+ const isRetryable = this.isRetryableError(error);
216
+ const maxRetriesToUse = isCredentialOperation
217
+ ? this.maxCredentialsRetries
218
+ : this.maxRetries;
219
+ const logContext = {
220
+ error: error.message,
221
+ code: error.code,
222
+ statusCode: error.$metadata?.httpStatusCode,
223
+ requestId: error.$metadata?.requestId,
224
+ isCredentialError: isCredentialError,
225
+ isRetryable: isRetryable,
226
+ remainingRetries: retries,
227
+ timestamp: new Date().toISOString(),
228
+ ...(this.isLambdaEnv
229
+ && {
230
+ lambda: {
231
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
232
+ requestId: process.env.AWS_LAMBDA_REQUEST_ID,
233
+ remainingTime: this.lambdaContext?.getRemainingTimeInMillis?.(),
234
+ memoryLimit: process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE
235
+ }
236
+ })
237
+ };
238
+ const errorMessage = `Operation failed (${maxRetriesToUse - retries + 1}/${maxRetriesToUse}):`;
239
+ if (this.isLambdaEnv) {
240
+ console.error(errorMessage, JSON.stringify(logContext));
241
+ }
242
+ else {
243
+ console.error(errorMessage, logContext);
244
+ }
245
+ if (isCredentialError) {
246
+ const warnMessage = 'Credential error detected, invalidating credentials cache...';
247
+ if (this.isLambdaEnv) {
248
+ console.warn(warnMessage, JSON.stringify({
249
+ roleArn: this.config.roleArn,
250
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME
251
+ }));
252
+ }
253
+ else {
254
+ console.warn(warnMessage);
255
+ }
256
+ this.credentialsCache = null;
257
+ }
258
+ if (this.isLambdaEnv
259
+ && !this.checkLambdaTimeout(delay + 5000)) {
260
+ console.warn('Insufficient Lambda time for retry, aborting operation');
261
+ throw error;
262
+ }
263
+ if (retries > 0
264
+ && (isRetryable
265
+ || isCredentialError)) {
266
+ const retryMessage = `Retrying operation in ${delay}ms... (${retries} retries remaining)`;
267
+ if (this.isLambdaEnv) {
268
+ console.info(retryMessage, JSON.stringify({
269
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
270
+ remainingTime: this.lambdaContext?.getRemainingTimeInMillis?.()
271
+ }));
272
+ }
273
+ else {
274
+ console.info(retryMessage);
275
+ }
276
+ await new Promise(resolve => setTimeout(resolve, delay));
277
+ const jitter = Math.random() * 0.3 * delay;
278
+ const nextDelay = Math.min(delay * 2 + jitter, 30000);
279
+ return this.retryWithBackoff(operation, retries - 1, nextDelay, isCredentialOperation);
280
+ }
281
+ throw error;
282
+ }
283
+ }
61
284
  /**
62
285
  * Gets temporary credentials using STS AssumeRole
63
286
  *
@@ -67,6 +290,18 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
67
290
  if (!this.config.roleArn) {
68
291
  throw new Error('Role ARN is required for AssumeRole authentication');
69
292
  }
293
+ if (this.isLambdaEnv
294
+ && !this.checkLambdaTimeout(10000)) {
295
+ console.warn('Insufficient Lambda time for credential refresh, using cached credentials if available');
296
+ if (this.credentialsCache) {
297
+ try {
298
+ return await this.credentialsCache;
299
+ }
300
+ catch (error) {
301
+ console.error('Failed to use cached credentials:', error);
302
+ }
303
+ }
304
+ }
70
305
  if (this.credentialsCache) {
71
306
  try {
72
307
  const credentials = await this.credentialsCache;
@@ -79,16 +314,31 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
79
314
  credentials.expiration = expirationTime;
80
315
  }
81
316
  const now = new Date();
82
- const bufferTime = 5 * 60 * 1000;
83
- if (expirationTime.getTime() - now.getTime() > bufferTime) {
317
+ const bufferTime = this.config.credentialsCacheBufferMs || 300000;
318
+ const timeUntilExpiration = expirationTime.getTime() - now.getTime();
319
+ if (timeUntilExpiration > bufferTime) {
84
320
  return credentials;
85
321
  }
322
+ if (this.isLambdaEnv) {
323
+ console.info('Lambda credentials cache expired or near expiration'
324
+ + ` (${Math.round(timeUntilExpiration / 1000)}s remaining), refreshing...`);
325
+ }
326
+ else {
327
+ console.info('Credentials cache expired or near expiration'
328
+ + ` (${Math.round(timeUntilExpiration / 1000)}s remaining), refreshing...`);
329
+ }
86
330
  }
87
331
  catch (error) {
88
- console.warn('Cached credentials failed, refreshing:', error);
332
+ console.warn('Cached credentials failed validation, refreshing:', {
333
+ error: error instanceof Error ? error.message : String(error),
334
+ isLambda: this.isLambdaEnv,
335
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
336
+ timestamp: new Date().toISOString()
337
+ });
89
338
  }
90
339
  }
91
- this.credentialsCache = this.refreshAssumeRoleCredentials();
340
+ this.credentialsCache = null;
341
+ this.credentialsCache = this.retryWithBackoff(() => this.refreshAssumeRoleCredentials(), this.maxCredentialsRetries, this.baseDelay, true);
92
342
  return this.credentialsCache;
93
343
  }
94
344
  /**
@@ -103,28 +353,42 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
103
353
  maxAttempts: 3,
104
354
  retryMode: 'adaptive'
105
355
  });
356
+ const sessionName = `log-service-session-${Date.now()}-${Math.random().toString(36).substring(7)}`;
106
357
  const command = new client_sts_1.AssumeRoleCommand({
107
358
  RoleArn: this.config.roleArn,
108
- RoleSessionName: `log-service-session-${Date.now()}`,
359
+ RoleSessionName: sessionName,
109
360
  DurationSeconds: 3600,
110
361
  });
111
362
  try {
112
363
  const response = await stsClient.send(command);
113
364
  if (!response.Credentials) {
114
- throw new log_error_1.LogError('Failed to retrieve credentials from STS AssumeRole');
365
+ throw new log_error_1.LogError('Failed to retrieve credentials from STS AssumeRole'
366
+ + ' - No credentials in response');
115
367
  }
116
- return {
368
+ const credentials = {
117
369
  accessKeyId: response.Credentials.AccessKeyId,
118
370
  secretAccessKey: response.Credentials.SecretAccessKey,
119
371
  sessionToken: response.Credentials.SessionToken,
120
372
  expiration: response.Credentials.Expiration,
121
373
  };
374
+ console.info('Successfully refreshed AWS credentials:', {
375
+ expiration: credentials.expiration.toISOString(),
376
+ sessionName: sessionName,
377
+ validForSeconds: Math.round((credentials.expiration.getTime() - Date.now()) / 1000),
378
+ timestamp: new Date().toISOString()
379
+ });
380
+ return credentials;
122
381
  }
123
382
  catch (error) {
124
383
  console.error('Failed to assume role:', {
125
384
  error: error.message,
126
385
  code: error.code,
127
- statusCode: error.$metadata?.httpStatusCode
386
+ statusCode: error.$metadata?.httpStatusCode,
387
+ requestId: error.$metadata?.requestId,
388
+ roleArn: this.config.roleArn,
389
+ sessionName: sessionName,
390
+ region: this.config.region,
391
+ timestamp: new Date().toISOString()
128
392
  });
129
393
  this.credentialsCache = null;
130
394
  throw error;
@@ -140,9 +404,21 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
140
404
  */
141
405
  async uploadLog(key, data) {
142
406
  const FIREHOSE_BATCH_SIZE = 500;
407
+ if (this.isLambdaEnv
408
+ && !this.checkLambdaTimeout(data.length * 100)) {
409
+ throw new Error('Insufficient Lambda time remaining for log upload operation');
410
+ }
143
411
  try {
144
412
  for (let i = 0; i < data.length; i += FIREHOSE_BATCH_SIZE) {
145
413
  const batch = data.slice(i, i + FIREHOSE_BATCH_SIZE);
414
+ const batchNumber = Math.floor(i / FIREHOSE_BATCH_SIZE) + 1;
415
+ const totalBatches = Math.ceil(data.length / FIREHOSE_BATCH_SIZE);
416
+ if (this.isLambdaEnv
417
+ && !this.checkLambdaTimeout(batch.length * 50)) {
418
+ console.warn('Lambda timeout risk, skipping remaining'
419
+ + ` ${data.length - i} log entries`);
420
+ break;
421
+ }
146
422
  const records = batch.map((log) => {
147
423
  const logEntry = log_service_1.LogService.formatLog(log);
148
424
  return { Data: Buffer.from(logEntry + '\n', 'utf8') };
@@ -151,15 +427,58 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
151
427
  DeliveryStreamName: this.config.firehoseStreamName,
152
428
  Records: records
153
429
  });
154
- await this.firehose.send(command);
430
+ await this.retryWithBackoff(async () => {
431
+ const result = await this.firehose.send(command);
432
+ if (result.FailedPutCount
433
+ && result.FailedPutCount > 0) {
434
+ const failureContext = {
435
+ failedCount: result.FailedPutCount,
436
+ requestId: result.$metadata?.requestId,
437
+ recordErrors: result.RequestResponses?.filter(r => r.ErrorCode)
438
+ .map(r => ({
439
+ errorCode: r.ErrorCode,
440
+ errorMessage: r.ErrorMessage
441
+ }))
442
+ };
443
+ const warnMessage = `Batch ${batchNumber}/${totalBatches} had ${result.FailedPutCount} failed records`;
444
+ if (this.isLambdaEnv) {
445
+ console.warn(warnMessage, JSON.stringify(failureContext));
446
+ }
447
+ else {
448
+ console.warn(warnMessage, failureContext);
449
+ }
450
+ }
451
+ return result;
452
+ }, this.maxRetries, this.baseDelay, false);
155
453
  }
156
454
  }
157
455
  catch (error) {
158
- console.error(`Failed to upload log to Firehose: ${key}`, {
456
+ const errorContext = {
159
457
  error: error.message,
160
458
  code: error.code,
161
- statusCode: error.$metadata?.httpStatusCode
162
- });
459
+ statusCode: error.$metadata?.httpStatusCode,
460
+ requestId: error.$metadata?.requestId,
461
+ streamName: this.config.firehoseStreamName,
462
+ region: this.config.region,
463
+ totalEntries: data.length,
464
+ isCredentialError: this.isCredentialError(error),
465
+ isRetryableError: this.isRetryableError(error),
466
+ timestamp: new Date().toISOString(),
467
+ ...(this.isLambdaEnv
468
+ && {
469
+ lambda: {
470
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
471
+ remainingTime: this.lambdaContext?.getRemainingTimeInMillis?.()
472
+ }
473
+ })
474
+ };
475
+ const finalMessage = `Failed to upload log to Firehose: ${key}`;
476
+ if (this.isLambdaEnv) {
477
+ console.error(finalMessage, JSON.stringify(errorContext));
478
+ }
479
+ else {
480
+ console.error(finalMessage, errorContext);
481
+ }
163
482
  throw error;
164
483
  }
165
484
  }
@@ -172,16 +491,23 @@ class LogStorageExternalS3Service extends log_storage_external_service_1.LogStor
172
491
  * @returns {Promise<void>}
173
492
  */
174
493
  async appendLog(key, data) {
494
+ const startTime = Date.now();
175
495
  try {
176
496
  await this.uploadLog(key, data);
177
497
  }
178
498
  catch (error) {
499
+ const duration = Date.now() - startTime;
179
500
  console.error(`Failed to send log to Firehose: ${key}`, {
180
501
  error: error.message,
181
502
  code: error.code,
182
503
  statusCode: error.$metadata?.httpStatusCode,
183
504
  requestId: error.$metadata?.requestId,
184
505
  batchSize: data.length,
506
+ durationMs: duration,
507
+ streamName: this.config.firehoseStreamName,
508
+ region: this.config.region,
509
+ isCredentialError: this.isCredentialError(error),
510
+ isRetryableError: this.isRetryableError(error),
185
511
  timestamp: new Date().toISOString()
186
512
  });
187
513
  throw error;
@@ -1 +1 @@
1
- {"version":3,"file":"log.storage.external.s3.service.js","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":";;;AAAA,8DAAiF;AACjF,oDAAmE;AACnE,iFAA2E;AAG3E,+CAA2C;AAE3C,8FAA0F;AAC1F,mDAA+C;AAE/C;;;;;;;;GAQG;AACH,MAAa,2BAA4B,SAAQ,wDAAyB;IAiBxE;;;;OAIG;IACH,YAAa,gBAA2C;QAEtD,KAAK,CAAE,gBAAgB,CAAC,CAAC;QAZ3B;;WAEG;QACK,qBAAgB,GAAwB,IAAI,CAAC;QAWnD,IAAI,CAAC,MAAM,GAAG,IAAA,8DAA6B,GAAE,CAAC;QAE9C,MAAM,cAAc,GAAQ;YAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;YAC1B,cAAc,EAAE,KAAK;YACrB,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,UAAU;SACtB,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,cAAc,CAAC,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QACrE,CAAC;aAAM,IACL,IAAI,CAAC,MAAM,CAAC,WAAW;eACpB,IAAI,CAAC,MAAM,CAAC,eAAe,EAC9B,CAAC;YACD,cAAc,CAAC,WAAW,GAAG;gBAC3B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;gBACpC,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,eAAe;aAC7C,CAAC;QACJ,CAAC;QAED,IAAI,IAA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;AA7QD,kEA6QC"}
1
+ {"version":3,"file":"log.storage.external.s3.service.js","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":";;;AAAA,8DAAiF;AACjF,oDAAmE;AACnE,iFAA2E;AAG3E,+CAA2C;AAE3C,8FAA0F;AAC1F,mDAA+C;AAC/C,wDAA2G;AAE3G;;;;;;;;;;;GAWG;AACH,MAAa,2BAA4B,SAAQ,wDAAyB;IA0CxE;;;;OAIG;IACH,YAAa,gBAA2C;QAEtD,KAAK,CAAE,gBAAgB,CAAC,CAAC;QArC3B;;WAEG;QACK,qBAAgB,GAAwB,IAAI,CAAC;QAErD;;WAEG;QACc,eAAU,GAAW,CAAC,CAAC;QAExC;;WAEG;QACc,cAAS,GAAW,IAAI,CAAC;QAY1C;;WAEG;QACK,kBAAa,GAAQ,IAAI,CAAC;QAWhC,IAAI,CAAC,MAAM,GAAG,IAAA,8DAA6B,GAAE,CAAC;QAC9C,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,MAAM,CAAC,qBAAqB,IAAI,CAAC,CAAC;QACpE,IAAI,CAAC,WAAW,GAAG,IAAA,kCAAmB,GAAE,CAAC;QAEzC,MAAM,cAAc,GAAQ;YAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;YAC1B,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,KAAK;YACnD,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC;YACzC,SAAS,EAAE,UAAU;SACtB,CAAC;QAEF,IACE,IAAI,CAAC,MAAM,CAAC,oBAAoB;eAC7B,IAAI,CAAC,WAAW,EACnB,CAAC;QACH,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC/B,cAAc,CAAC,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QACrE,CAAC;aAAM,IACL,IAAI,CAAC,MAAM,C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,CAAC,IAAe;QAEhC,IAAI,CAAC;YACH,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAEvD,MAAM,IAAI,CAAC,SAAS,CAClB,gBAAgB,EAChB,IAAI,CACL,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CACX,6CAA6C,EAC7C;gBACE,KAAK,EAAE,KAAK,CAAC,OAAO;gBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,UAAU,EAAE,KAAK,CAAC,SAAS,EAAE,cAAc;gBAC3C,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS;gBACrC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB;gBACtC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC1B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC,CACF,CAAC;YAEF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAtuBD,kEAsuBC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Lambda environment detection utilities
3
+ */
4
+ export interface LambdaEnvironmentInfo {
5
+ isLambda: boolean;
6
+ functionName?: string;
7
+ functionVersion?: string;
8
+ logGroup?: string;
9
+ logStream?: string;
10
+ requestId?: string;
11
+ remainingTimeMs?: number;
12
+ }
13
+ /**
14
+ * Detects if the current execution environment is AWS Lambda
15
+ *
16
+ * @returns {boolean} True if running in Lambda environment
17
+ */
18
+ export declare const isLambdaEnvironment: () => boolean;
19
+ /**
20
+ * Gets Lambda environment information
21
+ *
22
+ * @returns {LambdaEnvironmentInfo} Lambda environment details
23
+ */
24
+ export declare const getLambdaEnvironmentInfo: () => LambdaEnvironmentInfo;
25
+ /**
26
+ * Gets optimal timeout values for Lambda environment
27
+ *
28
+ * @param {number} defaultTimeoutMs - Default timeout for non-Lambda environments
29
+ * @param {number} lambdaTimeoutMs - Specific timeout for Lambda environments
30
+ *
31
+ * @returns {number} Optimal timeout in milliseconds
32
+ */
33
+ export declare const getLambdaOptimizedTimeout: (defaultTimeoutMs: number, lambdaTimeoutMs?: number) => number;
34
+ /**
35
+ * Gets optimal retry count for Lambda environment
36
+ *
37
+ * @param {number} defaultRetries - Default retry count for non-Lambda environments
38
+ * @param {number} lambdaRetries - Specific retry count for Lambda environments
39
+ *
40
+ * @returns {number} Optimal retry count
41
+ */
42
+ export declare const getLambdaOptimizedRetries: (defaultRetries: number, lambdaRetries?: number) => number;
43
+ /**
44
+ * Checks if Lambda execution has enough remaining time for an operation
45
+ *
46
+ * @param {any} context - Lambda context object (if available)
47
+ * @param {number} estimatedDurationMs - Estimated duration of the operation
48
+ * @param {number} bufferMs - Safety buffer in milliseconds
49
+ *
50
+ * @returns {boolean} True if there's enough time remaining
51
+ */
52
+ export declare const hasEnoughLambdaTime: (context: any, estimatedDurationMs: number, bufferMs?: number) => boolean;
53
+ /**
54
+ * Gets Lambda-optimized credentials cache buffer time
55
+ *
56
+ * @param {number} defaultBufferMs - Default buffer time for non-Lambda environments
57
+ *
58
+ * @returns {number} Optimal buffer time in milliseconds
59
+ */
60
+ export declare const getLambdaOptimizedCredentialsBuffer: (defaultBufferMs: number) => number;
61
+ //# sourceMappingURL=lambda.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda.utils.d.ts","sourceRoot":"","sources":["../../src/utils/lambda.utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAEpC,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAO,OAQtC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,QAAO,qBAgB3C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACpC,kBAAkB,MAAM,EACxB,kBAAkB,MAAM,KACvB,MAOF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACpC,gBAAgB,MAAM,EACtB,gBAAgB,MAAM,KACrB,MAOF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,GAAG,EACZ,qBAAqB,MAAM,EAC3B,WAAU,MAAa,KACtB,OAUF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC,GAAI,iBAAiB,MAAM,KAAG,MAO7E,CAAC"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLambdaOptimizedCredentialsBuffer = exports.hasEnoughLambdaTime = exports.getLambdaOptimizedRetries = exports.getLambdaOptimizedTimeout = exports.getLambdaEnvironmentInfo = exports.isLambdaEnvironment = void 0;
4
+ /**
5
+ * Detects if the current execution environment is AWS Lambda
6
+ *
7
+ * @returns {boolean} True if running in Lambda environment
8
+ */
9
+ const isLambdaEnvironment = () => {
10
+ return !!(process.env.AWS_LAMBDA_FUNCTION_NAME
11
+ || process.env.LAMBDA_RUNTIME_DIR
12
+ || process.env.AWS_EXECUTION_ENV?.startsWith('AWS_Lambda')
13
+ || process.env._HANDLER);
14
+ };
15
+ exports.isLambdaEnvironment = isLambdaEnvironment;
16
+ /**
17
+ * Gets Lambda environment information
18
+ *
19
+ * @returns {LambdaEnvironmentInfo} Lambda environment details
20
+ */
21
+ const getLambdaEnvironmentInfo = () => {
22
+ const isLambda = (0, exports.isLambdaEnvironment)();
23
+ if (!isLambda) {
24
+ return { isLambda: false };
25
+ }
26
+ return {
27
+ isLambda: true,
28
+ functionName: process.env.AWS_LAMBDA_FUNCTION_NAME,
29
+ functionVersion: process.env.AWS_LAMBDA_FUNCTION_VERSION,
30
+ logGroup: process.env.AWS_LAMBDA_LOG_GROUP_NAME,
31
+ logStream: process.env.AWS_LAMBDA_LOG_STREAM_NAME,
32
+ requestId: process.env.AWS_LAMBDA_REQUEST_ID,
33
+ };
34
+ };
35
+ exports.getLambdaEnvironmentInfo = getLambdaEnvironmentInfo;
36
+ /**
37
+ * Gets optimal timeout values for Lambda environment
38
+ *
39
+ * @param {number} defaultTimeoutMs - Default timeout for non-Lambda environments
40
+ * @param {number} lambdaTimeoutMs - Specific timeout for Lambda environments
41
+ *
42
+ * @returns {number} Optimal timeout in milliseconds
43
+ */
44
+ const getLambdaOptimizedTimeout = (defaultTimeoutMs, lambdaTimeoutMs) => {
45
+ if (!(0, exports.isLambdaEnvironment)()) {
46
+ return defaultTimeoutMs;
47
+ }
48
+ return lambdaTimeoutMs
49
+ || Math.min(defaultTimeoutMs, 15000);
50
+ };
51
+ exports.getLambdaOptimizedTimeout = getLambdaOptimizedTimeout;
52
+ /**
53
+ * Gets optimal retry count for Lambda environment
54
+ *
55
+ * @param {number} defaultRetries - Default retry count for non-Lambda environments
56
+ * @param {number} lambdaRetries - Specific retry count for Lambda environments
57
+ *
58
+ * @returns {number} Optimal retry count
59
+ */
60
+ const getLambdaOptimizedRetries = (defaultRetries, lambdaRetries) => {
61
+ if (!(0, exports.isLambdaEnvironment)()) {
62
+ return defaultRetries;
63
+ }
64
+ return lambdaRetries
65
+ || Math.min(defaultRetries, 2);
66
+ };
67
+ exports.getLambdaOptimizedRetries = getLambdaOptimizedRetries;
68
+ /**
69
+ * Checks if Lambda execution has enough remaining time for an operation
70
+ *
71
+ * @param {any} context - Lambda context object (if available)
72
+ * @param {number} estimatedDurationMs - Estimated duration of the operation
73
+ * @param {number} bufferMs - Safety buffer in milliseconds
74
+ *
75
+ * @returns {boolean} True if there's enough time remaining
76
+ */
77
+ const hasEnoughLambdaTime = (context, estimatedDurationMs, bufferMs = 5000) => {
78
+ if (!(0, exports.isLambdaEnvironment)()
79
+ || !context?.getRemainingTimeInMillis) {
80
+ return true;
81
+ }
82
+ const remainingTime = context.getRemainingTimeInMillis();
83
+ return remainingTime > (estimatedDurationMs + bufferMs);
84
+ };
85
+ exports.hasEnoughLambdaTime = hasEnoughLambdaTime;
86
+ /**
87
+ * Gets Lambda-optimized credentials cache buffer time
88
+ *
89
+ * @param {number} defaultBufferMs - Default buffer time for non-Lambda environments
90
+ *
91
+ * @returns {number} Optimal buffer time in milliseconds
92
+ */
93
+ const getLambdaOptimizedCredentialsBuffer = (defaultBufferMs) => {
94
+ if (!(0, exports.isLambdaEnvironment)()) {
95
+ return defaultBufferMs;
96
+ }
97
+ return Math.max(defaultBufferMs, 600000);
98
+ };
99
+ exports.getLambdaOptimizedCredentialsBuffer = getLambdaOptimizedCredentialsBuffer;
100
+ //# sourceMappingURL=lambda.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda.utils.js","sourceRoot":"","sources":["../../src/utils/lambda.utils.ts"],"names":[],"mappings":";;;AAcA;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,GAAY,EAAE;IAE/C,OAAO,CAAC,CAAC,CACP,OAAO,CAAC,GAAG,CAAC,wBAAwB;WACjC,OAAO,CAAC,GAAG,CAAC,kBAAkB;WAC9B,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,UAAU,CAAC,YAAY,CAAC;WACvD,OAAO,CAAC,GAAG,CAAC,QAAQ,CACxB,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,mBAAmB,uBAQ9B;AAEF;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,GAA0B,EAAE;IAElE,MAAM,QAAQ,GAAG,IAAA,2BAAmB,GAAE,CAAC;IAEvC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,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GAAG,CAAC,mBAAmB,GAAG,QAAQ,CAAC,CAAC;AAC1D,CAAC,CAAC;AAdW,QAAA,mBAAmB,uBAc9B;AAEF;;;;;;GAMG;AACI,MAAM,mCAAmC,GAAG,CAAC,eAAuB,EAAU,EAAE;IAErF,IAAI,CAAC,IAAA,2BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC,CAAC;AAPW,QAAA,mCAAmC,uCAO9C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicollasfrazao/liguelead-log-service",
3
- "version": "1.2.19",
3
+ "version": "1.3.1",
4
4
  "description": "A standalone logging service for Express applications with multi-destination storage (local files + S3 via Kinesis Firehose) and comprehensive request tracking using strategy pattern.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",