Skip to content

chore(all): fix doc typos and apply basic lint recommendations #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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;
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ class Tracer implements TracerInterface {
* @returns AWS - Instrumented AWS SDK
*/
public captureAWS<T>(aws: T): T {
if (this.isTracingEnabled() === false) return aws;
if (!this.isTracingEnabled()) return aws;

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

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

return this.provider.captureAWSv3Client(service);
}
Expand Down Expand Up @@ -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 ]);
}

Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -421,16 +421,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 @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -757,7 +757,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