diff --git a/src/datadog-lambda.ts b/src/datadog-lambda.ts index 9d4beab1..1c591ba6 100644 --- a/src/datadog-lambda.ts +++ b/src/datadog-lambda.ts @@ -132,12 +132,12 @@ export class DatadogLambda extends Construct { applyEnvVariables(lambdaFunction, baseProps); setDDEnvVariables(lambdaFunction, this.props); setTagsForFunction(lambdaFunction, this.props); - } - this.transport.applyEnvVars(extractedLambdaFunctions); + this.transport.applyEnvVars(lambdaFunction); - if (baseProps.sourceCodeIntegration) { - this.addGitCommitMetadata(extractedLambdaFunctions); + if (baseProps.sourceCodeIntegration) { + this.addGitCommitMetadata([lambdaFunction]); + } } } diff --git a/src/transport.ts b/src/transport.ts index f45ea798..8ed5c02b 100644 --- a/src/transport.ts +++ b/src/transport.ts @@ -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); + } } }