Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -90,7 +90,7 @@ class Logger implements ClassThatLogs {
}

public static evaluateColdStartOnce(): void {
if (Logger.getColdStartEvaluatedValue() === false) {
if (!Logger.getColdStartEvaluatedValue()) {
Logger.evaluateColdStart();
}
}
Expand All @@ -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 ]);
};
};
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/log/LogItemInterface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogAttributes } from '../types/Log';
import { LogAttributes } from '../types';

interface LogItemInterface {

Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/types/formats/PowertoolLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 25 additions & 25 deletions packages/tracing/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ class Tracer implements TracerInterface {
* @param error - Error to serialize as metadata
*/
public addErrorAsMetadata(error: Error): void {
if (this.tracingEnabled === false) {
if (!this.tracingEnabled) {
return;
}

const subsegment = this.getSegment();
if (this.captureError === false) {
if (!this.captureError) {
subsegment.addErrorFlag();

return;
Expand All @@ -163,7 +163,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.tracingEnabled === false) {
if (data === undefined || !this.captureResponse || !this.tracingEnabled) {
return;
}

Expand All @@ -175,7 +175,7 @@ class Tracer implements TracerInterface {
*
*/
public addServiceNameAnnotation(): void {
if (this.tracingEnabled === false || this.serviceName === undefined) {
if (!this.tracingEnabled || this.serviceName === undefined) {
return;
}
this.putAnnotation('Service', this.serviceName);
Expand All @@ -184,17 +184,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.tracingEnabled === true) {
if (this.tracingEnabled) {
this.putAnnotation('ColdStart', Tracer.coldStart);
}
if (Tracer.coldStart === true) {
if (Tracer.coldStart) {
Tracer.coldStart = false;
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ class Tracer implements TracerInterface {
* @returns AWS - Instrumented AWS SDK
*/
public captureAWS<T>(aws: T): T {
if (this.tracingEnabled === false) return aws;
if (!this.tracingEnabled) return aws;

return this.provider.captureAWS(aws);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ class Tracer implements TracerInterface {
* @returns service - Instrumented AWS SDK v2 client
*/
public captureAWSClient<T>(service: T): T {
if (this.tracingEnabled === false) return service;
if (!this.tracingEnabled) return service;

return this.provider.captureAWSClient(service);
}
Expand Down Expand Up @@ -281,7 +281,7 @@ class Tracer implements TracerInterface {
* @returns service - Instrumented AWS SDK v3 client
*/
public captureAWSv3Client<T>(service: T): T {
if (this.tracingEnabled === false) return service;
if (!this.tracingEnabled) return service;

return this.provider.captureAWSv3Client(service);
}
Expand Down Expand Up @@ -322,7 +322,7 @@ class Tracer implements TracerInterface {
const originalMethod = descriptor.value;

descriptor.value = ((event, context, callback) => {
if (this.tracingEnabled === false) {
if (!this.tracingEnabled) {
return originalMethod?.apply(target, [ event, context, callback ]);
}

Expand Down Expand Up @@ -389,7 +389,7 @@ class Tracer implements TracerInterface {
const originalMethod = descriptor.value;

descriptor.value = (...args: unknown[]) => {
if (this.tracingEnabled === false) {
if (!this.tracingEnabled) {
return originalMethod?.apply(target, [...args]);
}

Expand Down Expand Up @@ -417,16 +417,16 @@ 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
*
* @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;
Expand Down Expand Up @@ -498,7 +498,7 @@ class Tracer implements TracerInterface {
* @param value - Value for annotation
*/
public putAnnotation(key: string, value: string | number | boolean): void {
if (this.tracingEnabled === false) return;
if (!this.tracingEnabled) return;

const document = this.getSegment();
if (document instanceof Segment) {
Expand Down Expand Up @@ -528,10 +528,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.tracingEnabled === false) return;
if (!this.tracingEnabled) return;

const document = this.getSegment();
if (document instanceof Segment) {
Expand Down Expand Up @@ -608,7 +608,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;
}

Expand Down Expand Up @@ -700,21 +700,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;
Expand All @@ -728,7 +728,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;
Expand All @@ -748,7 +748,7 @@ class Tracer implements TracerInterface {
return;
}

if (this.isLambdaSamCli() || this.isLambdaExecutionEnv() === false) {
if (this.isLambdaSamCli() || !this.isLambdaExecutionEnv()) {
this.tracingEnabled = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/src/middleware/middy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down