Skip to content

Commit 39db444

Browse files
authored
[SVLS-8152] Add Ruby 3.2, 3.3, and 3.4 support (#70)
* Add ruby support * Don't check in zip file * Fix README * Update layer versions * Cleanup * Bump ruby layer to 27
1 parent 8485356 commit 39db444

File tree

9 files changed

+259
-15
lines changed

9 files changed

+259
-15
lines changed

README.md

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module "lambda-datadog" {
3333
"DD_VERSION" : "1.0.0"
3434
}
3535
36-
datadog_extension_layer_version = 74
37-
datadog_python_layer_version = 106
36+
datadog_extension_layer_version = 90
37+
datadog_python_layer_version = 120
3838
}
3939
```
4040

@@ -59,8 +59,8 @@ module "lambda-datadog" {
5959
"DD_VERSION" : "1.0.0"
6060
}
6161
62-
datadog_extension_layer_version = 74
63-
datadog_node_layer_version = 123
62+
datadog_extension_layer_version = 90
63+
datadog_node_layer_version = 132
6464
}
6565
```
6666

@@ -85,8 +85,8 @@ module "lambda-datadog" {
8585
"DD_VERSION" : "1.0.0"
8686
}
8787
88-
datadog_extension_layer_version = 74
89-
datadog_dotnet_layer_version = 19
88+
datadog_extension_layer_version = 90
89+
datadog_dotnet_layer_version = 23
9090
}
9191
```
9292

@@ -111,8 +111,8 @@ module "lambda-datadog" {
111111
"DD_VERSION" : "1.0.0"
112112
}
113113
114-
datadog_extension_layer_version = 74
115-
datadog_java_layer_version = 19
114+
datadog_extension_layer_version = 90
115+
datadog_java_layer_version = 24
116116
}
117117
```
118118

@@ -137,10 +137,35 @@ module "lambda-datadog" {
137137
"DD_VERSION" : "1.0.0"
138138
}
139139
140-
datadog_extension_layer_version = 74
140+
datadog_extension_layer_version = 90
141141
}
142142
```
143143

144+
### Ruby
145+
```
146+
module "lambda-datadog" {
147+
source = "DataDog/lambda-datadog/aws"
148+
version = "4.1.1"
149+
150+
filename = "example.zip"
151+
function_name = "example-function"
152+
role = aws_iam_role.lambda_role.arn
153+
handler = "lambda_function.lambda_handler"
154+
runtime = "ruby3.4"
155+
memory_size = 256
156+
157+
environment_variables = {
158+
"DD_API_KEY_SECRET_ARN" : "arn:aws:secretsmanager:us-east-1:000000000000:secret:example-secret"
159+
"DD_ENV" : "dev"
160+
"DD_SERVICE" : "example-service"
161+
"DD_SITE": "datadoghq.com"
162+
"DD_VERSION" : "1.0.0"
163+
}
164+
165+
datadog_ruby_layer_version = 27
166+
datadog_extension_layer_version = 90
167+
}
168+
```
144169

145170
## Configuration
146171

@@ -211,6 +236,7 @@ Use the following variables to select the versions of the Datadog Lambda layers
211236
| `datadog_java_layer_version` | Version of the [Datadog Java Lambda layer](https://github.com/DataDog/datadog-lambda-java/releases) to install |
212237
| `datadog_node_layer_version` | Version of the [Datadog Node Lambda layer](https://github.com/DataDog/datadog-lambda-js/releases) to install |
213238
| `datadog_python_layer_version` | Version of the [Datadog Python Lambda layer](https://github.com/DataDog/datadog-lambda-python/releases) to install |
239+
| `datadog_ruby_layer_version` | Version of the [Datadog Ruby Lambda layer](https://github.com/DataDog/datadog-lambda-rb/releases) to install |
214240

215241
#### Selecting the Datadog Site
216242

@@ -226,6 +252,7 @@ Use Environment variables to configure Datadog Serverless Monitoring. Refer to t
226252
- [Java](https://docs.datadoghq.com/tracing/trace_collection/library_config/java/)
227253
- [Node](https://github.com/DataDog/datadog-lambda-js?tab=readme-ov-file#configuration)
228254
- [Python](https://github.com/DataDog/datadog-lambda-python?tab=readme-ov-file#configuration)
255+
- [Ruby](https://github.com/DataDog/datadog-lambda-rb?tab=readme-ov-file#configuration)
229256

230257
<!-- BEGIN_TF_DOCS -->
231258
## Requirements
@@ -258,11 +285,12 @@ No modules.
258285
|------|-------------|----------------|---------|:--------:|
259286
| <a name="input_architectures"></a> [architectures](#input\_architectures) | Instruction set architecture for your Lambda function. Valid values are ["x86\_64"] and ["arm64"]. | `list(string)` | <pre>["x86_64"]</pre> | no |
260287
| <a name="input_code_signing_config_arn"></a> [code\_signing\_config\_arn](#input\_code\_signing\_config\_arn) | To enable code signing for this function, specify the ARN of a code-signing configuration. A code-signing configuration includes a set of signing profiles, which define the trusted publishers for this function. | `string` | `null` | no |
261-
| <a name="input_datadog_extension_layer_version"></a> [datadog\_extension\_layer\_version](#input\_datadog\_extension\_layer\_version) | Version for the Datadog Extension Layer | `number` | `74` | no |
262-
| <a name="input_datadog_dotnet_layer_version"></a> [datadog\_dotnet\_layer\_version](#input\_datadog\_dotnet\_layer\_version) | Version for the Datadog .NET Layer | `number` | `19` | no |
263-
| <a name="input_datadog_java_layer_version"></a> [datadog\_java\_layer\_version](#input\_datadog\_java\_layer\_version) | Version for the Datadog Java Layer | `number` | `19` | no |
264-
| <a name="input_datadog_node_layer_version"></a> [datadog\_node\_layer\_version](#input\_datadog\_node\_layer\_version) | Version for the Datadog Node Layer | `number` | `123` | no |
265-
| <a name="input_datadog_python_layer_version"></a> [datadog\_python\_layer\_version](#input\_datadog\_python\_layer\_version) | Version for the Datadog Python Layer | `number` | `106` | no |
288+
| <a name="input_datadog_extension_layer_version"></a> [datadog\_extension\_layer\_version](#input\_datadog\_extension\_layer\_version) | Version for the Datadog Extension Layer | `number` | `90` | no |
289+
| <a name="input_datadog_dotnet_layer_version"></a> [datadog\_dotnet\_layer\_version](#input\_datadog\_dotnet\_layer\_version) | Version for the Datadog .NET Layer | `number` | `23` | no |
290+
| <a name="input_datadog_java_layer_version"></a> [datadog\_java\_layer\_version](#input\_datadog\_java\_layer\_version) | Version for the Datadog Java Layer | `number` | `24` | no |
291+
| <a name="input_datadog_node_layer_version"></a> [datadog\_node\_layer\_version](#input\_datadog\_node\_layer\_version) | Version for the Datadog Node Layer | `number` | `132` | no |
292+
| <a name="input_datadog_python_layer_version"></a> [datadog\_python\_layer\_version](#input\_datadog\_python\_layer\_version) | Version for the Datadog Python Layer | `number` | `120` | no |
293+
| <a name="input_datadog_ruby_layer_version"></a> [datadog\_ruby\_layer\_version](#input\_datadog\_ruby\_layer\_version) | Version for the Datadog Ruby Layer | `number` | `27` | no |
266294
| <a name="input_dead_letter_config_target_arn"></a> [dead\_letter\_config\_target\_arn](#input\_dead\_letter\_config\_target\_arn) | ARN of an SNS topic or SQS queue to notify when an invocation fails. | `string` | `null` | no |
267295
| <a name="input_description"></a> [description](#input\_description) | Description of what your Lambda Function does. | `string` | `null` | no |
268296
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | Map of environment variables that are accessible from the function code during execution. | `map(string)` | `{}` | no |

examples/ruby/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Ruby Example
2+
3+
A simple Ruby Lambda function with out of the box Datadog instrumentation.
4+
5+
## Usage
6+
7+
* Create a [Datadog API Key](https://app.datadoghq.com/organization-settings/api-keys)
8+
* Create a secret in [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) and add the Datadog API Key as the secret value in plaintext
9+
* Create a `terraform.tfvars` file
10+
- Set the `datadog_secret_arn` to the arn of the secret you just created
11+
- Set the `datadog_service_name` to the name of the service you want to use to filter for the resource in Datadog
12+
- Set the `datadog_site` to the [Datadog destination site](https://docs.datadoghq.com/getting_started/site/) for your metrics, traces, and logs
13+
* Run the following commands
14+
15+
```
16+
terraform init
17+
terraform plan
18+
terraform apply
19+
```
20+
21+
<!-- BEGIN_TF_DOCS -->
22+
## Requirements
23+
24+
| Name | Version |
25+
|------|---------|
26+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.0 |
27+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.77.0 |
28+
29+
## Providers
30+
31+
| Name | Version |
32+
|------|---------|
33+
| <a name="provider_archive"></a> [archive](#provider\_archive) | 2.4.2 |
34+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.77.0 |
35+
36+
## Modules
37+
38+
| Name | Source | Version |
39+
|------|--------|---------|
40+
| <a name="module_lambda-datadog"></a> [lambda-datadog](#module\_lambda-datadog) | ../../ | n/a |
41+
42+
## Resources
43+
44+
| Name | Type |
45+
|------|------|
46+
| [aws_iam_policy.secrets_manager_read_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
47+
| [aws_iam_role.lambda_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
48+
| [aws_iam_role_policy_attachment.attach_iam_policy_to_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
49+
| [aws_iam_role_policy_attachment.attach_secrets_manager_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
50+
| [archive_file.zip_code](https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file) | data source |
51+
52+
## Inputs
53+
54+
| Name | Description | Type | Default | Required |
55+
|------|-------------|------|---------|:--------:|
56+
| <a name="input_datadog_secret_arn"></a> [datadog\_secret\_arn](#input\_datadog\_secret\_arn) | Secret for Datadog API Key | `string` | n/a | yes |
57+
| <a name="input_datadog_service_name"></a> [datadog\_service\_name](#input\_datadog\_service\_name) | Service used to filter for resources in Datadog | `string` | n/a | yes |
58+
| <a name="input_datadog_site"></a> [datadog\_site](#input\_datadog\_site) | Destination site for your metrics, traces, and logs | `string` | n/a | yes |
59+
60+
## Outputs
61+
62+
| Name | Description |
63+
|------|-------------|
64+
| <a name="output_arn"></a> [arn](#output\_arn) | Amazon Resource Name (ARN) identifying your Lambda Function. |
65+
| <a name="output_function_name"></a> [function\_name](#output\_function\_name) | Unique name for your Lambda Function |
66+
| <a name="output_invoke_arn"></a> [invoke\_arn](#output\_invoke\_arn) | ARN to be used for invoking Lambda Function from API Gateway. |
67+
<!-- END_TF_DOCS -->

examples/ruby/main.tf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
resource "aws_iam_role" "lambda_role" {
2+
name = "terraform-example-ruby-${var.datadog_service_name}-role"
3+
assume_role_policy = jsonencode(
4+
{
5+
"Version" : "2012-10-17",
6+
"Statement" : [
7+
{
8+
"Sid" : "",
9+
"Effect" : "Allow",
10+
"Action" : "sts:AssumeRole",
11+
"Principal" : {
12+
"Service" : "lambda.amazonaws.com"
13+
}
14+
}
15+
]
16+
})
17+
}
18+
19+
resource "aws_iam_policy" "secrets_manager_read_policy" {
20+
name = "terraform-example-ruby-${var.datadog_service_name}-secrets-manager-policy"
21+
description = "Policy to allow read access to Secrets Manager"
22+
policy = jsonencode({
23+
Version = "2012-10-17"
24+
Statement = [
25+
{
26+
Sid = "ReadSecret"
27+
Effect = "Allow"
28+
Action = "secretsmanager:GetSecretValue"
29+
Resource = var.datadog_secret_arn
30+
}
31+
]
32+
})
33+
}
34+
35+
resource "aws_iam_role_policy_attachment" "attach_iam_policy_to_iam_role" {
36+
role = aws_iam_role.lambda_role.name
37+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
38+
}
39+
40+
resource "aws_iam_role_policy_attachment" "attach_secrets_manager_policy" {
41+
role = aws_iam_role.lambda_role.name
42+
policy_arn = aws_iam_policy.secrets_manager_read_policy.arn
43+
}
44+
45+
data "archive_file" "zip_code" {
46+
type = "zip"
47+
source_dir = "${path.module}/src/"
48+
output_path = "${path.module}/hello-ruby.zip"
49+
}
50+
51+
52+
53+
module "lambda-datadog" {
54+
source = "../../"
55+
56+
filename = "${path.module}/hello-ruby.zip"
57+
function_name = "terraform-example-ruby-${var.datadog_service_name}-function"
58+
role = aws_iam_role.lambda_role.arn
59+
handler = "rb_handler.hello"
60+
runtime = "ruby3.4"
61+
architectures = ["arm64"]
62+
memory_size = 256
63+
64+
environment_variables = {
65+
"DD_API_KEY_SECRET_ARN" : var.datadog_secret_arn
66+
"DD_ENV" : "dev"
67+
"DD_SERVICE" : var.datadog_service_name
68+
"DD_SITE": var.datadog_site
69+
"DD_VERSION" : "1.0.0"
70+
}
71+
}
72+

examples/ruby/outputs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "arn" {
2+
description = "Amazon Resource Name (ARN) identifying your Lambda Function."
3+
value = module.lambda-datadog.arn
4+
}
5+
6+
output "invoke_arn" {
7+
description = "ARN to be used for invoking Lambda Function from API Gateway."
8+
value = module.lambda-datadog.invoke_arn
9+
}
10+
11+
output "function_name" {
12+
description = "Unique name for your Lambda Function"
13+
value = module.lambda-datadog.function_name
14+
}

examples/ruby/src/rb_handler.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require 'datadog/lambda'
4+
5+
Datadog::Lambda.configure_apm do |c|
6+
end
7+
8+
def hello(event:, context:)
9+
Datadog::Lambda.wrap(event, context) do
10+
body = {
11+
'message' => "Datadog <3 Serverless!",
12+
'input' => event
13+
}
14+
15+
response = {
16+
'statusCode' => 200,
17+
'body' => body
18+
}
19+
20+
response
21+
end
22+
end

examples/ruby/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
variable "datadog_secret_arn" {
2+
description = "Secret for Datadog API Key"
3+
type = string
4+
}
5+
6+
variable "datadog_service_name" {
7+
description = "Service used to filter for resources in Datadog"
8+
type = string
9+
}
10+
11+
variable "datadog_site" {
12+
description = "Destination site for your metrics, traces, and logs"
13+
type = string
14+
}

examples/ruby/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.5.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.77.0"
8+
}
9+
}
10+
}

main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@ locals {
2020
python = {
2121
DD_LAMBDA_HANDLER = var.handler
2222
}
23+
ruby = {
24+
DD_LAMBDA_HANDLER = var.handler
25+
}
2326
}
2427
runtime_base_handler_map = {
2528
dotnet = var.handler
2629
java = var.handler
2730
nodejs = "/opt/nodejs/node_modules/datadog-lambda-js/handler.handler"
2831
python = "datadog_lambda.handler.handler"
32+
ruby = var.handler
2933
}
3034
runtime_base_layer_version_map = {
3135
dotnet = var.datadog_dotnet_layer_version
3236
java = var.datadog_java_layer_version
3337
nodejs = var.datadog_node_layer_version
3438
python = var.datadog_python_layer_version
39+
ruby = var.datadog_ruby_layer_version
3540
}
3641
runtime_layer_map = {
3742
"dotnet6" = "dd-trace-dotnet"
@@ -52,6 +57,9 @@ locals {
5257
"python3.12" = "Datadog-Python312"
5358
"python3.13" = "Datadog-Python313"
5459
"python3.14" = "Datadog-Python314"
60+
"ruby3.2" = "Datadog-Ruby3-2"
61+
"ruby3.3" = "Datadog-Ruby3-3"
62+
"ruby3.4" = "Datadog-Ruby3-4"
5563
}
5664
}
5765

@@ -120,6 +128,9 @@ check "runtime_support" {
120128
"python3.14",
121129
"provided.al2",
122130
"provided.al2023",
131+
"ruby3.2",
132+
"ruby3.3",
133+
"ruby3.4",
123134
],
124135
var.runtime)
125136
error_message = "${var.runtime} Lambda runtime is not supported by the lambda-datadog Terraform module"

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ variable "datadog_extension_layer_version" {
1111
variable "datadog_dotnet_layer_version" {
1212
description = "Version for the Datadog .NET Layer"
1313
type = number
14-
default = 22
14+
default = 23
1515
}
1616

1717
variable "datadog_java_layer_version" {
@@ -32,6 +32,12 @@ variable "datadog_python_layer_version" {
3232
default = 120
3333
}
3434

35+
variable "datadog_ruby_layer_version" {
36+
description = "Version for the Datadog Ruby Layer"
37+
type = number
38+
default = 27
39+
}
40+
3541
variable "fips" {
3642
description = "Enable FIPS mode for Datadog Lambda extension"
3743
type = bool

0 commit comments

Comments
 (0)