Skip to content
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
3 changes: 2 additions & 1 deletion infra/live/global_vars.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ locals {
"application-autoscaling:*",
"cloudwatch:*",
"sqs:*",
"cloudfront:*"
"cloudfront:*",
"xray:*"
]
}

Expand Down
1 change: 1 addition & 0 deletions infra/live/prod/environment_vars.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ locals {
inputs = {
log_retention_days = local.log_retention_days
deploy_branches = local.deploy_branches
otel_sample_rate = 0.1 # 10% of traces sampled
}
11 changes: 11 additions & 0 deletions infra/modules/aws/_shared/lambda/data.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
data "aws_iam_policy_document" "lambda_xray" {
statement {
effect = "Allow"
actions = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
]
resources = ["*"]
}
}

data "aws_s3_bucket" "code_bucket" {
bucket = var.code_bucket
}
Expand Down
28 changes: 22 additions & 6 deletions infra/modules/aws/_shared/lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ resource "aws_s3_object" "bootstrap_lambda_zip" {
content_type = "application/zip"
}

resource "aws_lambda_function" "lambda" {
function_name = local.lambda_name
role = aws_iam_role.iam_for_lambda.arn
handler = local.lambda_handler
runtime = local.lambda_runtime
resource "aws_iam_policy" "lambda_xray" {
name = "${local.lambda_name}-xray"
policy = data.aws_iam_policy_document.lambda_xray.json
}

resource "aws_iam_role_policy_attachment" "lambda_xray" {
role = aws_iam_role.iam_for_lambda.name
policy_arn = aws_iam_policy.lambda_xray.arn
}

resource "aws_lambda_function" "lambda" {
function_name = local.lambda_name
role = aws_iam_role.iam_for_lambda.arn
handler = local.lambda_handler
runtime = local.lambda_runtime
reserved_concurrent_executions = local.pc_reserved_count

s3_bucket = data.aws_s3_bucket.code_bucket.bucket
Expand All @@ -44,8 +53,15 @@ resource "aws_lambda_function" "lambda" {
# publish ONE immutable version so we can create an alias
publish = true

tracing_config {
mode = "Active"
}

environment {
variables = var.environment_variables
variables = merge(var.environment_variables, {
OTEL_TRACES_SAMPLER = "parentbased_traceidratio"
OTEL_TRACES_SAMPLER_ARG = tostring(var.otel_sample_rate)
})
}

# tags for identifying the code deploy app and its deployment config. Used in CI/CD pipelines.
Expand Down
6 changes: 6 additions & 0 deletions infra/modules/aws/_shared/lambda/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
### start of static vars set in root.hcl ###
variable "otel_sample_rate" {
type = number
description = "OpenTelemetry trace sampling rate — 0.0 = no traces, 1.0 = 100% of traces sampled"
default = 1.0 # 100%
}

variable "project_name" {
type = string
description = "Project name used in naming resources"
Expand Down
7 changes: 4 additions & 3 deletions infra/modules/aws/api/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module "lambda_api" {
source = "../_shared/lambda"

project_name = var.project_name
environment = var.environment
code_bucket = var.code_bucket
project_name = var.project_name
environment = var.environment
code_bucket = var.code_bucket
otel_sample_rate = var.otel_sample_rate

lambda_name = local.lambda_name

Expand Down
6 changes: 6 additions & 0 deletions infra/modules/aws/api/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ variable "code_bucket" {
type = string
description = "Bucket where deployable code artifacts are uploaded"
}

variable "otel_sample_rate" {
type = number
description = "OpenTelemetry trace sampling rate — 0.0 = no traces, 1.0 = 100% of traces sampled"
default = 1.0 # 100%
}
### end of static vars set in root.hcl ###

variable "deployment_config" {
Expand Down
7 changes: 4 additions & 3 deletions infra/modules/aws/lambda_worker/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module "lambda_worker" {
source = "../_shared/lambda"

project_name = var.project_name
environment = var.environment
code_bucket = var.code_bucket
project_name = var.project_name
environment = var.environment
code_bucket = var.code_bucket
otel_sample_rate = var.otel_sample_rate

lambda_name = local.lambda_name

Expand Down
6 changes: 6 additions & 0 deletions infra/modules/aws/lambda_worker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ variable "code_bucket" {
type = string
description = "Bucket where deployable code artifacts are uploaded"
}

variable "otel_sample_rate" {
type = number
description = "OpenTelemetry trace sampling rate — 0.0 = no traces, 1.0 = 100% of traces sampled"
default = 1.0 # 100%
}
### end of static vars set in root.hcl ###

variable "sqs_queue_name" {
Expand Down
Loading