Skip to content

Commit

Permalink
chore: Make helpers take one, not multiple Lambda functions (6/x)
Browse files Browse the repository at this point in the history
  • Loading branch information
lym953 committed Dec 5, 2024
1 parent da42521 commit d78bde2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 43 deletions.
15 changes: 6 additions & 9 deletions src/datadog-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ export class DatadogLambda extends Construct {

addCdkConstructVersionTag(lambdaFunction);
applyEnvVariables(lambdaFunction, baseProps);
setDDEnvVariables(lambdaFunction, this.props);
setTagsForFunction(lambdaFunction, this.props);
}

setDDEnvVariables(extractedLambdaFunctions, this.props);
setTagsForFunctions(extractedLambdaFunctions, this.props);

this.transport.applyEnvVars(extractedLambdaFunctions);

if (baseProps.sourceCodeIntegration) {
Expand Down Expand Up @@ -177,12 +176,10 @@ export function addCdkConstructVersionTag(lambdaFunction: lambda.Function): void
});
}

function setTagsForFunctions(lambdaFunctions: lambda.Function[], props: DatadogLambdaProps): void {
lambdaFunctions.forEach((lambdaFunction) => {
if (props.forwarderArn) {
setTags(lambdaFunction, props);
}
});
function setTagsForFunction(lambdaFunction: lambda.Function, props: DatadogLambdaProps): void {
if (props.forwarderArn) {
setTags(lambdaFunction, props);
}
}

function grantReadLambda(secret: ISecret, lambdaFunction: lambda.Function): void {
Expand Down
66 changes: 32 additions & 34 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,42 +120,40 @@ export function applyEnvVariables(lam: lambda.Function, baseProps: DatadogLambda
}
}

export function setDDEnvVariables(lambdas: lambda.Function[], props: DatadogLambdaProps): void {
lambdas.forEach((lam) => {
if (props.extensionLayerVersion) {
if (props.env) {
lam.addEnvironment(DD_ENV_ENV_VAR, props.env);
}
if (props.service) {
lam.addEnvironment(DD_SERVICE_ENV_VAR, props.service);
}
if (props.version) {
lam.addEnvironment(DD_VERSION_ENV_VAR, props.version);
}
if (props.tags) {
lam.addEnvironment(DD_TAGS, props.tags);
}
}
if (props.enableColdStartTracing !== undefined) {
lam.addEnvironment(DD_COLD_START_TRACING, props.enableColdStartTracing.toString().toLowerCase());
}
if (props.minColdStartTraceDuration !== undefined) {
lam.addEnvironment(DD_MIN_COLD_START_DURATION, props.minColdStartTraceDuration.toString().toLowerCase());
}
if (props.coldStartTraceSkipLibs !== undefined) {
lam.addEnvironment(DD_COLD_START_TRACE_SKIP_LIB, props.coldStartTraceSkipLibs);
export function setDDEnvVariables(lam: lambda.Function, props: DatadogLambdaProps): void {
if (props.extensionLayerVersion) {
if (props.env) {
lam.addEnvironment(DD_ENV_ENV_VAR, props.env);
}
if (props.enableProfiling !== undefined) {
lam.addEnvironment(DD_PROFILING_ENABLED, props.enableProfiling.toString().toLowerCase());
if (props.service) {
lam.addEnvironment(DD_SERVICE_ENV_VAR, props.service);
}
if (props.encodeAuthorizerContext !== undefined) {
lam.addEnvironment(DD_ENCODE_AUTHORIZER_CONTEXT, props.encodeAuthorizerContext.toString().toLowerCase());
if (props.version) {
lam.addEnvironment(DD_VERSION_ENV_VAR, props.version);
}
if (props.decodeAuthorizerContext !== undefined) {
lam.addEnvironment(DD_DECODE_AUTHORIZER_CONTEXT, props.decodeAuthorizerContext.toString().toLowerCase());
if (props.tags) {
lam.addEnvironment(DD_TAGS, props.tags);
}
if (props.apmFlushDeadline !== undefined) {
lam.addEnvironment(DD_APM_FLUSH_DEADLINE_MILLISECONDS, props.apmFlushDeadline.toString().toLowerCase());
}
});
}
if (props.enableColdStartTracing !== undefined) {
lam.addEnvironment(DD_COLD_START_TRACING, props.enableColdStartTracing.toString().toLowerCase());
}
if (props.minColdStartTraceDuration !== undefined) {
lam.addEnvironment(DD_MIN_COLD_START_DURATION, props.minColdStartTraceDuration.toString().toLowerCase());
}
if (props.coldStartTraceSkipLibs !== undefined) {
lam.addEnvironment(DD_COLD_START_TRACE_SKIP_LIB, props.coldStartTraceSkipLibs);
}
if (props.enableProfiling !== undefined) {
lam.addEnvironment(DD_PROFILING_ENABLED, props.enableProfiling.toString().toLowerCase());
}
if (props.encodeAuthorizerContext !== undefined) {
lam.addEnvironment(DD_ENCODE_AUTHORIZER_CONTEXT, props.encodeAuthorizerContext.toString().toLowerCase());
}
if (props.decodeAuthorizerContext !== undefined) {
lam.addEnvironment(DD_DECODE_AUTHORIZER_CONTEXT, props.decodeAuthorizerContext.toString().toLowerCase());
}
if (props.apmFlushDeadline !== undefined) {
lam.addEnvironment(DD_APM_FLUSH_DEADLINE_MILLISECONDS, props.apmFlushDeadline.toString().toLowerCase());
}
}

0 comments on commit d78bde2

Please sign in to comment.