diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 352c243795..d88304b139 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -5,11 +5,11 @@ import cloneDeep from 'lodash.clonedeep'; import merge from 'lodash.merge'; import { ConfigServiceInterface, EnvironmentVariablesService } from './config'; import type { + ClassThatLogs, Environment, HandlerMethodDecorator, LambdaFunctionContext, LogAttributes, - ClassThatLogs, LoggerOptions, LogItemExtraInput, LogItemMessage, @@ -90,7 +90,7 @@ class Logger implements ClassThatLogs { } public static evaluateColdStartOnce(): void { - if (Logger.getColdStartEvaluatedValue() === false) { + if (!Logger.getColdStartEvaluatedValue()) { Logger.evaluateColdStart(); } } @@ -117,9 +117,8 @@ class Logger implements ClassThatLogs { descriptor.value = (event, context, callback) => { this.addContext(context); - const result = originalMethod?.apply(this, [ event, context, callback ]); - return result; + return originalMethod?.apply(this, [ event, context, callback ]); }; }; } @@ -181,7 +180,7 @@ class Logger implements ClassThatLogs { const coldStartValue = Logger.getColdStartValue(); if (typeof coldStartValue === 'undefined') { Logger.setColdStartValue(true); - } else if (coldStartValue === true) { + } else if (coldStartValue) { Logger.setColdStartValue(false); } else { Logger.setColdStartValue(false); diff --git a/packages/logger/src/log/LogItemInterface.ts b/packages/logger/src/log/LogItemInterface.ts index b41fabaab6..debb7038af 100644 --- a/packages/logger/src/log/LogItemInterface.ts +++ b/packages/logger/src/log/LogItemInterface.ts @@ -1,4 +1,4 @@ -import { LogAttributes } from '../types/Log'; +import { LogAttributes } from '../types'; interface LogItemInterface { diff --git a/packages/logger/src/types/formats/PowertoolLog.ts b/packages/logger/src/types/formats/PowertoolLog.ts index 8a632412e9..f3529a684f 100644 --- a/packages/logger/src/types/formats/PowertoolLog.ts +++ b/packages/logger/src/types/formats/PowertoolLog.ts @@ -37,7 +37,7 @@ type PowertoolLog = LogAttributes & { /** * message * - * Description: Log statement value. Unserializable JSON values will be casted to string. + * Description: Log statement value. Unserializable JSON values will be cast to string. * Example: "Collecting payment" */ message?: string diff --git a/packages/tracing/src/Tracer.ts b/packages/tracing/src/Tracer.ts index 26253209ea..2e60ef695f 100644 --- a/packages/tracing/src/Tracer.ts +++ b/packages/tracing/src/Tracer.ts @@ -144,12 +144,12 @@ class Tracer implements TracerInterface { * @param error - Error to serialize as metadata */ public addErrorAsMetadata(error: Error): void { - if (this.isTracingEnabled() === false) { + if (!this.isTracingEnabled()) { return; } const subsegment = this.getSegment(); - if (this.captureError === false) { + if (!this.captureError) { subsegment.addErrorFlag(); return; @@ -167,7 +167,7 @@ class Tracer implements TracerInterface { * @param methodName - Name of the method that is being traced */ public addResponseAsMetadata(data?: unknown, methodName?: string): void { - if (data === undefined || this.captureResponse === false || this.isTracingEnabled() === false) { + if (data === undefined || !this.captureResponse || !this.isTracingEnabled()) { return; } @@ -179,7 +179,7 @@ class Tracer implements TracerInterface { * */ public addServiceNameAnnotation(): void { - if (this.isTracingEnabled() === false || this.serviceName === undefined) { + if (!this.isTracingEnabled() || this.serviceName === undefined) { return; } this.putAnnotation('Service', this.serviceName); @@ -188,17 +188,17 @@ class Tracer implements TracerInterface { /** * Add ColdStart annotation to the current segment or subsegment. * - * If Tracer has been initialized outside of the Lambda handler then the same instance - * of Tracer will be reused throghout the lifecycle of that same Lambda execution environment + * If Tracer has been initialized outside the Lambda handler then the same instance + * of Tracer will be reused throughout the lifecycle of that same Lambda execution environment * and this method will annotate `ColdStart: false` after the first invocation. * * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html */ public annotateColdStart(): void { - if (this.isTracingEnabled() === true) { + if (this.isTracingEnabled()) { this.putAnnotation('ColdStart', Tracer.coldStart); } - if (Tracer.coldStart === true) { + if (Tracer.coldStart) { Tracer.coldStart = false; } } @@ -226,7 +226,7 @@ class Tracer implements TracerInterface { * @returns AWS - Instrumented AWS SDK */ public captureAWS(aws: T): T { - if (this.isTracingEnabled() === false) return aws; + if (!this.isTracingEnabled()) return aws; return this.provider.captureAWS(aws); } @@ -255,7 +255,7 @@ class Tracer implements TracerInterface { * @returns service - Instrumented AWS SDK v2 client */ public captureAWSClient(service: T): T { - if (this.isTracingEnabled() === false) return service; + if (!this.isTracingEnabled()) return service; return this.provider.captureAWSClient(service); } @@ -285,7 +285,7 @@ class Tracer implements TracerInterface { * @returns service - Instrumented AWS SDK v3 client */ public captureAWSv3Client(service: T): T { - if (this.isTracingEnabled() === false) return service; + if (!this.isTracingEnabled()) return service; return this.provider.captureAWSv3Client(service); } @@ -326,7 +326,7 @@ class Tracer implements TracerInterface { const originalMethod = descriptor.value; descriptor.value = ((event, context, callback) => { - if (this.isTracingEnabled() === false) { + if (!this.isTracingEnabled()) { return originalMethod?.apply(target, [ event, context, callback ]); } @@ -393,7 +393,7 @@ class Tracer implements TracerInterface { const originalMethod = descriptor.value; descriptor.value = (...args: unknown[]) => { - if (this.isTracingEnabled() === false) { + if (!this.isTracingEnabled()) { return originalMethod?.apply(target, [...args]); } @@ -421,8 +421,8 @@ class Tracer implements TracerInterface { /** * Retrieve the current value of `ColdStart`. * - * If Tracer has been initialized outside of the Lambda handler then the same instance - * of Tracer will be reused throghout the lifecycle of that same Lambda execution environment + * If Tracer has been initialized outside the Lambda handler then the same instance + * of Tracer will be reused throughout the lifecycle of that same Lambda execution environment * and this method will return `false` after the first invocation. * * @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html @@ -430,7 +430,7 @@ class Tracer implements TracerInterface { * @returns boolean - `true` if is cold start, otherwise `false` */ public static getColdStart(): boolean { - if (Tracer.coldStart === true) { + if (Tracer.coldStart) { Tracer.coldStart = false; return true; @@ -505,7 +505,7 @@ class Tracer implements TracerInterface { * @param value - Value for annotation */ public putAnnotation(key: string, value: string | number | boolean): void { - if (this.isTracingEnabled() === false) return; + if (!this.isTracingEnabled()) return; const document = this.getSegment(); if (document instanceof Segment) { @@ -535,10 +535,10 @@ class Tracer implements TracerInterface { * * @param key - Metadata key * @param value - Value for metadata - * @param timestamp - Namespace that metadata will lie under, if none is passed it will use the serviceName + * @param namespace - Namespace that metadata will lie under, if none is passed it will use the serviceName */ public putMetadata(key: string, value: unknown, namespace?: string | undefined): void { - if (this.isTracingEnabled() === false) return; + if (!this.isTracingEnabled()) return; const document = this.getSegment(); if (document instanceof Segment) { @@ -617,7 +617,7 @@ class Tracer implements TracerInterface { * * @param serviceName - Service name to validate */ - private isValidServiceName(serviceName?: string): boolean { + private static isValidServiceName(serviceName?: string): boolean { return typeof serviceName === 'string' && serviceName.trim().length > 0; } @@ -709,21 +709,21 @@ class Tracer implements TracerInterface { * @param serviceName - Name of the service to use */ private setServiceName(serviceName?: string): void { - if (serviceName !== undefined && this.isValidServiceName(serviceName)) { + if (serviceName !== undefined && Tracer.isValidServiceName(serviceName)) { this.serviceName = serviceName; return; } const customConfigValue = this.getCustomConfigService()?.getServiceName(); - if (customConfigValue !== undefined && this.isValidServiceName(customConfigValue)) { + if (customConfigValue !== undefined && Tracer.isValidServiceName(customConfigValue)) { this.serviceName = customConfigValue; return; } const envVarsValue = this.getEnvVarsService()?.getServiceName(); - if (envVarsValue !== undefined && this.isValidServiceName(envVarsValue)) { + if (envVarsValue !== undefined && Tracer.isValidServiceName(envVarsValue)) { this.serviceName = envVarsValue; return; @@ -737,7 +737,7 @@ class Tracer implements TracerInterface { * @param enabled - Whether or not tracing is enabled */ private setTracingEnabled(enabled?: boolean): void { - if (enabled !== undefined && enabled === false) { + if (enabled !== undefined && !enabled) { this.tracingEnabled = enabled; return; @@ -757,7 +757,7 @@ class Tracer implements TracerInterface { return; } - if (this.isLambdaSamCli() || this.isLambdaExecutionEnv() === false) { + if (this.isLambdaSamCli() || !this.isLambdaExecutionEnv()) { this.tracingEnabled = false; } } diff --git a/packages/tracing/src/middleware/middy.ts b/packages/tracing/src/middleware/middy.ts index b58580d942..064952c181 100644 --- a/packages/tracing/src/middleware/middy.ts +++ b/packages/tracing/src/middleware/middy.ts @@ -23,7 +23,7 @@ import { Segment, Subsegment } from 'aws-xray-sdk-core'; * }).use(captureLambdaHandler(tracer)); * ``` * - * @param tracer - The Tracer instance to use for tracing + * @param target - The Tracer instance to use for tracing * @returns middleware object - The middy middleware object */ const captureLambdaHandler = (target: Tracer): middy.MiddlewareObj => {