From a12cad6a9ca7af6109291a78ed3abaaf962e850a Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:43:08 +0300 Subject: [PATCH 1/9] Use new environment variable --- collector/internal/collector/collector.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/collector/internal/collector/collector.go b/collector/internal/collector/collector.go index 76da891f13..03eb7ddc20 100644 --- a/collector/internal/collector/collector.go +++ b/collector/internal/collector/collector.go @@ -48,12 +48,25 @@ type Collector struct { } func getConfig(logger *zap.Logger) string { - val, ex := os.LookupEnv("OPENTELEMETRY_COLLECTOR_CONFIG_FILE") - if !ex { - return "/opt/collector-config/config.yaml" + val, ex := os.LookupEnv("OPENTELEMETRY_COLLECTOR_CONFIG_URI") + if ex { + logger.Info("Using config URI from environment variable", zap.String("uri", newVal)) + return val } - logger.Info("Using config URI from environment", zap.String("uri", val)) - return val + + // The name of the environment variable was changed + // This is the old name, kept for backwards compatibility + oldVal, oldEx := os.LookupEnv("OPENTELEMETRY_COLLECTOR_CONFIG_FILE") + if oldEx { + logger.Info("Using config URI from deprecated environment variable", zap.String("uri", oldVal)) + logger.Warn("The OPENTELEMETRY_COLLECTOR_CONFIG_FILE environment variable is deprecated. Please use OPENTELEMETRY_COLLECTOR_CONFIG_URI instead.") + return oldVal + } + + // If neither environment variable is set, use the default + defaultVal := "/opt/collector-config/config.yaml" + logger.Info("Using default config URI", zap.String("uri", defaultVal)) + return defaultVal } func NewCollector(logger *zap.Logger, factories otelcol.Factories, version string) *Collector { From 36c95a57ab44d06ca4e7ac68cdbf91a1861166da Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:48:56 +0300 Subject: [PATCH 2/9] Update README.md --- collector/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/collector/README.md b/collector/README.md index 51a37b2512..d2f6248aa8 100644 --- a/collector/README.md +++ b/collector/README.md @@ -33,7 +33,7 @@ Alternatively, to configure the OpenTelemetry Lambda Extension via CloudFormatio ## Configuration -By default, OpenTelemetry Collector Lambda layer exports telemetry data to AWS backends. To customize the collector configuration, add a `collector.yaml` to your function and specify its location via the `OPENTELEMETRY_COLLECTOR_CONFIG_FILE` environment file. +By default, OpenTelemetry Collector Lambda layer exports telemetry data to AWS backends. To customize the collector configuration, add a `collector.yaml` to your function and specify its location via the `OPENTELEMETRY_COLLECTOR_CONFIG_URI` environment file. Here is a sample configuration file: @@ -56,10 +56,10 @@ service: exporters: [logging, otlp] ``` -Once the file has been deployed with a Lambda, configuring the `OPENTELEMETRY_COLLECTOR_CONFIG_FILE` will tell the OpenTelemetry extension where to find the collector configuration: +Once the file has been deployed with a Lambda, configuring the `OPENTELEMETRY_COLLECTOR_CONFIG_URI` will tell the OpenTelemetry extension where to find the collector configuration: ``` -aws lambda update-function-configuration --function-name Function --environment Variables={OPENTELEMETRY_COLLECTOR_CONFIG_FILE=/var/task/collector.yaml} +aws lambda update-function-configuration --function-name Function --environment Variables={OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/collector.yaml} ``` You can configure environment variables via CloudFormation template as well: @@ -71,11 +71,11 @@ You can configure environment variables via CloudFormation template as well: ... Environment: Variables: - OPENTELEMETRY_COLLECTOR_CONFIG_FILE: /var/task/collector.yaml + OPENTELEMETRY_COLLECTOR_CONFIG_URI: /var/task/collector.yaml ``` In addition to local files, the OpenTelemetry Collector Lambda layer may be configured through HTTP or S3 URIs -provided in the `OPENTELEMETRY_COLLECTOR_CONFIG_FILE` environment variable. For instance, to load configuration +provided in the `OPENTELEMETRY_COLLECTOR_CONFIG_URI` environment variable. For instance, to load configuration from an S3 object using a CloudFormation template: ```yaml @@ -85,7 +85,7 @@ from an S3 object using a CloudFormation template: ... Environment: Variables: - OPENTELEMETRY_COLLECTOR_CONFIG_FILE: s3://.s3..amazonaws.com/collector_config.yaml + OPENTELEMETRY_COLLECTOR_CONFIG_URI: s3://.s3..amazonaws.com/collector_config.yaml ``` Loading configuration from S3 will require that the IAM role attached to your function includes read access to the relevant bucket. From 32a286aa8e579623b13e29ac79b940a386c72643 Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:49:46 +0300 Subject: [PATCH 3/9] Update main.tf --- java/sample-apps/sqs/deploy/agent/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/sample-apps/sqs/deploy/agent/main.tf b/java/sample-apps/sqs/deploy/agent/main.tf index 5bdee7ab3a..602839ed0d 100644 --- a/java/sample-apps/sqs/deploy/agent/main.tf +++ b/java/sample-apps/sqs/deploy/agent/main.tf @@ -28,7 +28,7 @@ module "hello-lambda-function" { { AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", OTEL_METRICS_EXPORTER = "otlp", - OPENTELEMETRY_COLLECTOR_CONFIG_FILE = "/opt/config.yaml" + OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" }) tracing_mode = var.tracing_mode From f7d47a637405fe4eade992c121bd90f3a83546e2 Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:50:03 +0300 Subject: [PATCH 4/9] Update main.tf --- java/sample-apps/aws-sdk/deploy/agent/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/sample-apps/aws-sdk/deploy/agent/main.tf b/java/sample-apps/aws-sdk/deploy/agent/main.tf index e2b871029f..5e95786ae7 100644 --- a/java/sample-apps/aws-sdk/deploy/agent/main.tf +++ b/java/sample-apps/aws-sdk/deploy/agent/main.tf @@ -28,7 +28,7 @@ module "hello-lambda-function" { { AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", OTEL_METRICS_EXPORTER = "otlp", - OPENTELEMETRY_COLLECTOR_CONFIG_FILE = "/opt/config.yaml" + OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" }) tracing_mode = var.tracing_mode From a3e4cfe9191842247ff22a86cee649b90eed1e74 Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:01:59 +0300 Subject: [PATCH 5/9] fix: variable name --- collector/internal/collector/collector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/internal/collector/collector.go b/collector/internal/collector/collector.go index 03eb7ddc20..951cb7fe46 100644 --- a/collector/internal/collector/collector.go +++ b/collector/internal/collector/collector.go @@ -50,7 +50,7 @@ type Collector struct { func getConfig(logger *zap.Logger) string { val, ex := os.LookupEnv("OPENTELEMETRY_COLLECTOR_CONFIG_URI") if ex { - logger.Info("Using config URI from environment variable", zap.String("uri", newVal)) + logger.Info("Using config URI from environment variable", zap.String("uri", val)) return val } From 6bd2dc57a79753e502d4d7a7c523b86219d59703 Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:02:42 +0300 Subject: [PATCH 6/9] Update main.tf: formatting --- java/sample-apps/aws-sdk/deploy/agent/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/sample-apps/aws-sdk/deploy/agent/main.tf b/java/sample-apps/aws-sdk/deploy/agent/main.tf index 5e95786ae7..1f8b1cb227 100644 --- a/java/sample-apps/aws-sdk/deploy/agent/main.tf +++ b/java/sample-apps/aws-sdk/deploy/agent/main.tf @@ -28,7 +28,7 @@ module "hello-lambda-function" { { AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", OTEL_METRICS_EXPORTER = "otlp", - OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" + OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" }) tracing_mode = var.tracing_mode From 919e937d535c861929f502c3b2b307e83ec2c7d3 Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:03:06 +0300 Subject: [PATCH 7/9] Update main.tf: formatting --- java/sample-apps/sqs/deploy/agent/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/sample-apps/sqs/deploy/agent/main.tf b/java/sample-apps/sqs/deploy/agent/main.tf index 602839ed0d..3f3d1851a5 100644 --- a/java/sample-apps/sqs/deploy/agent/main.tf +++ b/java/sample-apps/sqs/deploy/agent/main.tf @@ -28,7 +28,7 @@ module "hello-lambda-function" { { AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", OTEL_METRICS_EXPORTER = "otlp", - OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" + OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" }) tracing_mode = var.tracing_mode From 06022c9a04225431636a029e6a8a1a2ce2a5426b Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:04:24 +0300 Subject: [PATCH 8/9] Update main.tf: formatting --- java/sample-apps/aws-sdk/deploy/agent/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/sample-apps/aws-sdk/deploy/agent/main.tf b/java/sample-apps/aws-sdk/deploy/agent/main.tf index 1f8b1cb227..a9515cda4c 100644 --- a/java/sample-apps/aws-sdk/deploy/agent/main.tf +++ b/java/sample-apps/aws-sdk/deploy/agent/main.tf @@ -26,9 +26,9 @@ module "hello-lambda-function" { OTEL_METRICS_EXPORTER = "otlp", } : { - AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", - OTEL_METRICS_EXPORTER = "otlp", - OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" + AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", + OTEL_METRICS_EXPORTER = "otlp", + OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" }) tracing_mode = var.tracing_mode From 4ea60a7cf349bc68ab3649beb4a115156e36ccf8 Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:04:35 +0300 Subject: [PATCH 9/9] Update main.tf: formatting --- java/sample-apps/sqs/deploy/agent/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java/sample-apps/sqs/deploy/agent/main.tf b/java/sample-apps/sqs/deploy/agent/main.tf index 3f3d1851a5..c8984576ac 100644 --- a/java/sample-apps/sqs/deploy/agent/main.tf +++ b/java/sample-apps/sqs/deploy/agent/main.tf @@ -26,9 +26,9 @@ module "hello-lambda-function" { OTEL_METRICS_EXPORTER = "otlp", } : { - AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", - OTEL_METRICS_EXPORTER = "otlp", - OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" + AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler", + OTEL_METRICS_EXPORTER = "otlp", + OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml" }) tracing_mode = var.tracing_mode