Skip to content
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

fix: revert "chore: rename Lambda related interfaces (#288)" #296

Merged
merged 1 commit into from
Sep 9, 2024
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
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export enum RuntimeType {
UNSUPPORTED,
}

export const DatadogLambdaDefaultProps = {
export const DefaultDatadogProps = {
addLayers: true,
enableDatadogTracing: true,
enableDatadogASM: false,
Expand Down
72 changes: 32 additions & 40 deletions src/datadog-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import {
addForwarderToLogGroups,
applyEnvVariables,
TagKeys,
DatadogLambdaStrictProps,
DatadogStrictProps,
setGitEnvironmentVariables,
setDDEnvVariables,
DatadogLambdaDefaultProps,
DatadogLambdaProps,
DefaultDatadogProps,
DatadogProps,
Transport,
} from "./index";
import { LambdaFunction } from "./interfaces";
Expand All @@ -32,10 +32,10 @@ const versionJson = require("../version.json");

export class DatadogLambda extends Construct {
scope: Construct;
props: DatadogLambdaProps;
props: DatadogProps;
transport: Transport;
constructor(scope: Construct, id: string, props: DatadogLambdaProps) {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() === "true") {
constructor(scope: Construct, id: string, props: DatadogProps) {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() === "true") {
Expected '===' and instead saw '=='. (...read more)

In JavaScript, == and != comparisons do type coercion, which can be confusing and may introduce potential errors. Use the type-safe equality operators === and !== instead.

View in Datadog  Leave us feedback  Documentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() === "true") {
Expected '===' and instead saw '=='. (...read more)

In JavaScript, == and != comparisons do type coercion, which can be confusing and may introduce potential errors. Use the type-safe equality operators === and !== instead.

View in Datadog  Leave us feedback  Documentation

log.setLevel("debug");
}
super(scope, id);
Expand All @@ -58,8 +58,8 @@ export class DatadogLambda extends Construct {

public addLambdaFunctions(lambdaFunctions: LambdaFunction[], construct?: Construct): void {
// baseProps contains all properties set by the user, with default values for properties
// defined in DatadogLambdaDefaultProps (if not set by user)
const baseProps: DatadogLambdaStrictProps = handleSettingPropDefaults(this.props);
// defined in DefaultDatadogProps (if not set by user)
const baseProps: DatadogStrictProps = handleSettingPropDefaults(this.props);

const extractedLambdaFunctions = extractSingletonFunctions(lambdaFunctions);

Expand Down Expand Up @@ -160,7 +160,7 @@ export function addCdkConstructVersionTag(lambdaFunctions: lambda.Function[]): v
});
}

function setTags(lambdaFunctions: lambda.Function[], props: DatadogLambdaProps): void {
function setTags(lambdaFunctions: lambda.Function[], props: DatadogProps): void {
log.debug(`Adding datadog tags`);
lambdaFunctions.forEach((functionName) => {
if (props.forwarderArn) {
Expand Down Expand Up @@ -214,7 +214,7 @@ function isSingletonFunction(fn: LambdaFunction): fn is lambda.SingletonFunction
return fn.hasOwnProperty("lambdaFunction");
}

export function validateProps(props: DatadogLambdaProps, apiKeyArnOverride = false): void {
export function validateProps(props: DatadogProps, apiKeyArnOverride = false): void {
log.debug("Validating props...");

checkForMultipleApiKeys(props, apiKeyArnOverride);
Expand Down Expand Up @@ -268,7 +268,7 @@ export function validateProps(props: DatadogLambdaProps, apiKeyArnOverride = fal
}
}

export function checkForMultipleApiKeys(props: DatadogLambdaProps, apiKeyArnOverride = false): void {
export function checkForMultipleApiKeys(props: DatadogProps, apiKeyArnOverride = false): void {
let multipleApiKeysMessage;
const apiKeyArnOrOverride = props.apiKeySecretArn !== undefined || apiKeyArnOverride;
if (props.apiKey !== undefined && props.apiKmsKey !== undefined && apiKeyArnOrOverride) {
Expand All @@ -286,7 +286,7 @@ export function checkForMultipleApiKeys(props: DatadogLambdaProps, apiKeyArnOver
}
}

export function handleSettingPropDefaults(props: DatadogLambdaProps): DatadogLambdaStrictProps {
export function handleSettingPropDefaults(props: DatadogProps): DatadogStrictProps {
let addLayers = props.addLayers;
let enableDatadogTracing = props.enableDatadogTracing;
let enableDatadogASM = props.enableDatadogASM;
Expand All @@ -301,59 +301,51 @@ export function handleSettingPropDefaults(props: DatadogLambdaProps): DatadogLam
const extensionLayerVersion = props.extensionLayerVersion;

if (addLayers === undefined) {
log.debug(`No value provided for addLayers, defaulting to ${DatadogLambdaDefaultProps.addLayers}`);
addLayers = DatadogLambdaDefaultProps.addLayers;
log.debug(`No value provided for addLayers, defaulting to ${DefaultDatadogProps.addLayers}`);
addLayers = DefaultDatadogProps.addLayers;
}
if (enableDatadogTracing === undefined) {
log.debug(
`No value provided for enableDatadogTracing, defaulting to ${DatadogLambdaDefaultProps.enableDatadogTracing}`,
);
enableDatadogTracing = DatadogLambdaDefaultProps.enableDatadogTracing;
log.debug(`No value provided for enableDatadogTracing, defaulting to ${DefaultDatadogProps.enableDatadogTracing}`);
enableDatadogTracing = DefaultDatadogProps.enableDatadogTracing;
}
if (enableDatadogASM === undefined) {
log.debug(`No value provided for enableDatadogASM, defaulting to ${DatadogLambdaDefaultProps.enableDatadogASM}`);
enableDatadogASM = DatadogLambdaDefaultProps.enableDatadogASM;
log.debug(`No value provided for enableDatadogASM, defaulting to ${DefaultDatadogProps.enableDatadogASM}`);
enableDatadogASM = DefaultDatadogProps.enableDatadogASM;
}
if (enableMergeXrayTraces === undefined) {
log.debug(
`No value provided for enableMergeXrayTraces, defaulting to ${DatadogLambdaDefaultProps.enableMergeXrayTraces}`,
`No value provided for enableMergeXrayTraces, defaulting to ${DefaultDatadogProps.enableMergeXrayTraces}`,
);
enableMergeXrayTraces = DatadogLambdaDefaultProps.enableMergeXrayTraces;
enableMergeXrayTraces = DefaultDatadogProps.enableMergeXrayTraces;
}
if (injectLogContext === undefined) {
log.debug(`No value provided for injectLogContext, defaulting to ${DatadogLambdaDefaultProps.injectLogContext}`);
injectLogContext = DatadogLambdaDefaultProps.injectLogContext;
log.debug(`No value provided for injectLogContext, defaulting to ${DefaultDatadogProps.injectLogContext}`);
injectLogContext = DefaultDatadogProps.injectLogContext;
}
if (logLevel === undefined) {
log.debug(`No value provided for logLevel`);
}
if (enableDatadogLogs === undefined) {
log.debug(`No value provided for enableDatadogLogs, defaulting to ${DatadogLambdaDefaultProps.enableDatadogLogs}`);
enableDatadogLogs = DatadogLambdaDefaultProps.enableDatadogLogs;
log.debug(`No value provided for enableDatadogLogs, defaulting to ${DefaultDatadogProps.enableDatadogLogs}`);
enableDatadogLogs = DefaultDatadogProps.enableDatadogLogs;
}
if (captureLambdaPayload === undefined) {
log.debug(
`No value provided for captureLambdaPayload, default to ${DatadogLambdaDefaultProps.captureLambdaPayload}`,
);
captureLambdaPayload = DatadogLambdaDefaultProps.captureLambdaPayload;
log.debug(`No value provided for captureLambdaPayload, default to ${DefaultDatadogProps.captureLambdaPayload}`);
captureLambdaPayload = DefaultDatadogProps.captureLambdaPayload;
}
if (sourceCodeIntegration === undefined) {
log.debug(
`No value provided for sourceCodeIntegration, default to ${DatadogLambdaDefaultProps.sourceCodeIntegration}`,
);
sourceCodeIntegration = DatadogLambdaDefaultProps.sourceCodeIntegration;
log.debug(`No value provided for sourceCodeIntegration, default to ${DefaultDatadogProps.sourceCodeIntegration}`);
sourceCodeIntegration = DefaultDatadogProps.sourceCodeIntegration;
}

if (redirectHandler === undefined) {
log.debug(`No value provided for redirectHandler, default to ${DatadogLambdaDefaultProps.redirectHandler}`);
redirectHandler = DatadogLambdaDefaultProps.redirectHandler;
log.debug(`No value provided for redirectHandler, default to ${DefaultDatadogProps.redirectHandler}`);
redirectHandler = DefaultDatadogProps.redirectHandler;
}

if (grantSecretReadAccess === undefined) {
log.debug(
`No value provided for grantSecretReadAccess, default to ${DatadogLambdaDefaultProps.grantSecretReadAccess}`,
);
grantSecretReadAccess = DatadogLambdaDefaultProps.grantSecretReadAccess;
log.debug(`No value provided for grantSecretReadAccess, default to ${DefaultDatadogProps.grantSecretReadAccess}`);
grantSecretReadAccess = DefaultDatadogProps.grantSecretReadAccess;
}

return {
Expand Down
5 changes: 0 additions & 5 deletions src/datadog.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { DatadogLambda } from "./datadog-lambda";

/**
* For backward compatibility. To be deprecated.
* It's recommended to use DatadogLambda for users who want to add Datadog
* monitoring for Lambda functions.
*/
export class Datadog extends DatadogLambda {}
6 changes: 3 additions & 3 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as lambda from "aws-cdk-lib/aws-lambda";
import log from "loglevel";
import { DatadogLambdaProps, DatadogLambdaStrictProps } from "./interfaces";
import { DatadogProps, DatadogStrictProps } from "./interfaces";

export const AWS_LAMBDA_EXEC_WRAPPER_KEY = "AWS_LAMBDA_EXEC_WRAPPER";
export const AWS_LAMBDA_EXEC_WRAPPER_VAL = "/opt/datadog_wrapper";
Expand Down Expand Up @@ -98,7 +98,7 @@ function filterSensitiveInfoFromRepository(repositoryUrl: string): string {
}
}

export function applyEnvVariables(lambdas: lambda.Function[], baseProps: DatadogLambdaStrictProps): void {
export function applyEnvVariables(lambdas: lambda.Function[], baseProps: DatadogStrictProps): void {
log.debug(`Setting environment variables...`);
lambdas.forEach((lam) => {
lam.addEnvironment(ENABLE_DD_TRACING_ENV_VAR, baseProps.enableDatadogTracing.toString().toLowerCase());
Expand All @@ -122,7 +122,7 @@ export function applyEnvVariables(lambdas: lambda.Function[], baseProps: Datadog
});
}

export function setDDEnvVariables(lambdas: lambda.Function[], props: DatadogLambdaProps): void {
export function setDDEnvVariables(lambdas: lambda.Function[], props: DatadogProps): void {
lambdas.forEach((lam) => {
if (props.extensionLayerVersion) {
if (props.env) {
Expand Down
12 changes: 3 additions & 9 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as secrets from "aws-cdk-lib/aws-secretsmanager";

export interface DatadogLambdaProps {
export interface DatadogProps {
readonly dotnetLayerVersion?: number;
readonly pythonLayerVersion?: number;
readonly nodeLayerVersion?: number;
Expand Down Expand Up @@ -48,16 +48,10 @@ export interface DatadogLambdaProps {
readonly useLayersFromAccount?: string;
}

/**
* For backward compatibility. It's recommended to use DatadogLambdaProps for
* users who want to add Datadog monitoring for Lambda functions.
*/
export type DatadogProps = DatadogLambdaProps;

/*
* Makes fields shared with DatadogLambdaDefaultProps (in constants file) required.
* Makes fields shared with DefaultDatadogProps (in constants file) required.
*/
export interface DatadogLambdaStrictProps {
export interface DatadogStrictProps {
readonly addLayers: boolean;
readonly enableDatadogLogs: boolean;
readonly captureLambdaPayload: boolean;
Expand Down
Loading