From f641b6b74892dba3e6ad29568b7e59dbea5e838c Mon Sep 17 00:00:00 2001 From: Glib Shpychka <23005347+gshpychka@users.noreply.github.com> Date: Sat, 14 Sep 2024 19:51:19 +0300 Subject: [PATCH] Rename OPENTELEMETRY_COLLECTOR_CONFIG_FILE to OPENTELEMETRY_COLLECTOR_CONFIG_URI (#1521) * Use new environment variable * Update README.md * Update main.tf * Update main.tf * fix: variable name * Update main.tf: formatting * Update main.tf: formatting * Update main.tf: formatting * Update main.tf: formatting --- collector/README.md | 12 +++++----- collector/internal/collector/collector.go | 23 +++++++++++++++---- java/sample-apps/aws-sdk/deploy/agent/main.tf | 6 ++--- java/sample-apps/sqs/deploy/agent/main.tf | 6 ++--- 4 files changed, 30 insertions(+), 17 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. diff --git a/collector/internal/collector/collector.go b/collector/internal/collector/collector.go index 76da891f13..951cb7fe46 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", val)) + 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 { diff --git a/java/sample-apps/aws-sdk/deploy/agent/main.tf b/java/sample-apps/aws-sdk/deploy/agent/main.tf index e2b871029f..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_FILE = "/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 diff --git a/java/sample-apps/sqs/deploy/agent/main.tf b/java/sample-apps/sqs/deploy/agent/main.tf index 5bdee7ab3a..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_FILE = "/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