Skip to content

Commit

Permalink
chore: Make helpers take one, not multiple Lambda functions (7/x)
Browse files Browse the repository at this point in the history
  • Loading branch information
lym953 committed Nov 25, 2024
1 parent 0a93c29 commit 7761033
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/datadog-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ export class DatadogLambda extends Construct {
applyEnvVariables(lambdaFunction, baseProps);
setDDEnvVariables(lambdaFunction, this.props);
setTagsForFunctions(lambdaFunction, this.props);
}

this.transport.applyEnvVars(extractedLambdaFunctions);
this.transport.applyEnvVars(lambdaFunction);

if (baseProps.sourceCodeIntegration) {
this.addGitCommitMetadata(extractedLambdaFunctions);
if (baseProps.sourceCodeIntegration) {
this.addGitCommitMetadata([lambdaFunction]);
}
}
}

Expand Down
42 changes: 20 additions & 22 deletions src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,27 @@ export class Transport {
this.apiKmsKey = apiKmsKey;
}

applyEnvVars(lambdas: lambda.Function[]) {
applyEnvVars(lam: lambda.Function) {
log.debug(`Setting Datadog transport environment variables...`);
lambdas.forEach((lam) => {
lam.addEnvironment(FLUSH_METRICS_TO_LOGS_ENV_VAR, this.flushMetricsToLogs.toString());
if (this.site !== undefined && this.flushMetricsToLogs === false) {
lam.addEnvironment(SITE_URL_ENV_VAR, this.site);
}
if (this.apiKey !== undefined) {
lam.addEnvironment(API_KEY_ENV_VAR, this.apiKey);
}
if (this.apiKeySecretArn !== undefined) {
const isNode = runtimeLookup[lam.runtime.name] === RuntimeType.NODE;
const isSendingSynchronousMetrics = this.extensionLayerVersion === undefined && !this.flushMetricsToLogs;
if (isSendingSynchronousMetrics && isNode) {
throw new Error(
`\`apiKeySecretArn\` is not supported for Node runtimes when using Synchronous Metrics. Use either \`apiKey\` or \`apiKmsKey\`.`,
);
}
lam.addEnvironment(API_KEY_SECRET_ARN_ENV_VAR, this.apiKeySecretArn);
}
if (this.apiKmsKey !== undefined) {
lam.addEnvironment(KMS_API_KEY_ENV_VAR, this.apiKmsKey);
lam.addEnvironment(FLUSH_METRICS_TO_LOGS_ENV_VAR, this.flushMetricsToLogs.toString());
if (this.site !== undefined && this.flushMetricsToLogs === false) {
lam.addEnvironment(SITE_URL_ENV_VAR, this.site);
}
if (this.apiKey !== undefined) {
lam.addEnvironment(API_KEY_ENV_VAR, this.apiKey);
}
if (this.apiKeySecretArn !== undefined) {
const isNode = runtimeLookup[lam.runtime.name] === RuntimeType.NODE;
const isSendingSynchronousMetrics = this.extensionLayerVersion === undefined && !this.flushMetricsToLogs;
if (isSendingSynchronousMetrics && isNode) {
throw new Error(
`\`apiKeySecretArn\` is not supported for Node runtimes when using Synchronous Metrics. Use either \`apiKey\` or \`apiKmsKey\`.`,
);
}
});
lam.addEnvironment(API_KEY_SECRET_ARN_ENV_VAR, this.apiKeySecretArn);
}
if (this.apiKmsKey !== undefined) {
lam.addEnvironment(KMS_API_KEY_ENV_VAR, this.apiKmsKey);
}
}
}

0 comments on commit 7761033

Please sign in to comment.