@@ -30,12 +30,21 @@ resource "aws_s3_object" "bootstrap_lambda_zip" {
3030 content_type = " application/zip"
3131}
3232
33- resource "aws_lambda_function" "lambda" {
34- function_name = local. lambda_name
35- role = aws_iam_role. iam_for_lambda . arn
36- handler = local. lambda_handler
37- runtime = local. lambda_runtime
33+ resource "aws_iam_policy" "lambda_xray" {
34+ name = " ${ local . lambda_name } -xray"
35+ policy = data. aws_iam_policy_document . lambda_xray . json
36+ }
37+
38+ resource "aws_iam_role_policy_attachment" "lambda_xray" {
39+ role = aws_iam_role. iam_for_lambda . name
40+ policy_arn = aws_iam_policy. lambda_xray . arn
41+ }
3842
43+ resource "aws_lambda_function" "lambda" {
44+ function_name = local. lambda_name
45+ role = aws_iam_role. iam_for_lambda . arn
46+ handler = local. lambda_handler
47+ runtime = local. lambda_runtime
3948 reserved_concurrent_executions = local. pc_reserved_count
4049
4150 s3_bucket = data. aws_s3_bucket . code_bucket . bucket
@@ -44,8 +53,15 @@ resource "aws_lambda_function" "lambda" {
4453 # publish ONE immutable version so we can create an alias
4554 publish = true
4655
56+ tracing_config {
57+ mode = " Active"
58+ }
59+
4760 environment {
48- variables = var. environment_variables
61+ variables = merge (var. environment_variables , {
62+ OTEL_TRACES_SAMPLER = " parentbased_traceidratio"
63+ OTEL_TRACES_SAMPLER_ARG = tostring (var. otel_sample_rate )
64+ })
4965 }
5066
5167 # tags for identifying the code deploy app and its deployment config. Used in CI/CD pipelines.
0 commit comments