Skip to content

Commit f641b6b

Browse files
authored
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
1 parent 0dd0572 commit f641b6b

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

collector/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Alternatively, to configure the OpenTelemetry Lambda Extension via CloudFormatio
3333

3434
## Configuration
3535

36-
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.
36+
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.
3737

3838
Here is a sample configuration file:
3939

@@ -56,10 +56,10 @@ service:
5656
exporters: [logging, otlp]
5757
```
5858
59-
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:
59+
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:
6060

6161
```
62-
aws lambda update-function-configuration --function-name Function --environment Variables={OPENTELEMETRY_COLLECTOR_CONFIG_FILE=/var/task/collector.yaml}
62+
aws lambda update-function-configuration --function-name Function --environment Variables={OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/collector.yaml}
6363
```
6464
6565
You can configure environment variables via CloudFormation template as well:
@@ -71,11 +71,11 @@ You can configure environment variables via CloudFormation template as well:
7171
...
7272
Environment:
7373
Variables:
74-
OPENTELEMETRY_COLLECTOR_CONFIG_FILE: /var/task/collector.yaml
74+
OPENTELEMETRY_COLLECTOR_CONFIG_URI: /var/task/collector.yaml
7575
```
7676

7777
In addition to local files, the OpenTelemetry Collector Lambda layer may be configured through HTTP or S3 URIs
78-
provided in the `OPENTELEMETRY_COLLECTOR_CONFIG_FILE` environment variable. For instance, to load configuration
78+
provided in the `OPENTELEMETRY_COLLECTOR_CONFIG_URI` environment variable. For instance, to load configuration
7979
from an S3 object using a CloudFormation template:
8080

8181
```yaml
@@ -85,7 +85,7 @@ from an S3 object using a CloudFormation template:
8585
...
8686
Environment:
8787
Variables:
88-
OPENTELEMETRY_COLLECTOR_CONFIG_FILE: s3://<bucket_name>.s3.<region>.amazonaws.com/collector_config.yaml
88+
OPENTELEMETRY_COLLECTOR_CONFIG_URI: s3://<bucket_name>.s3.<region>.amazonaws.com/collector_config.yaml
8989
```
9090
9191
Loading configuration from S3 will require that the IAM role attached to your function includes read access to the relevant bucket.

collector/internal/collector/collector.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,25 @@ type Collector struct {
4848
}
4949

5050
func getConfig(logger *zap.Logger) string {
51-
val, ex := os.LookupEnv("OPENTELEMETRY_COLLECTOR_CONFIG_FILE")
52-
if !ex {
53-
return "/opt/collector-config/config.yaml"
51+
val, ex := os.LookupEnv("OPENTELEMETRY_COLLECTOR_CONFIG_URI")
52+
if ex {
53+
logger.Info("Using config URI from environment variable", zap.String("uri", val))
54+
return val
5455
}
55-
logger.Info("Using config URI from environment", zap.String("uri", val))
56-
return val
56+
57+
// The name of the environment variable was changed
58+
// This is the old name, kept for backwards compatibility
59+
oldVal, oldEx := os.LookupEnv("OPENTELEMETRY_COLLECTOR_CONFIG_FILE")
60+
if oldEx {
61+
logger.Info("Using config URI from deprecated environment variable", zap.String("uri", oldVal))
62+
logger.Warn("The OPENTELEMETRY_COLLECTOR_CONFIG_FILE environment variable is deprecated. Please use OPENTELEMETRY_COLLECTOR_CONFIG_URI instead.")
63+
return oldVal
64+
}
65+
66+
// If neither environment variable is set, use the default
67+
defaultVal := "/opt/collector-config/config.yaml"
68+
logger.Info("Using default config URI", zap.String("uri", defaultVal))
69+
return defaultVal
5770
}
5871

5972
func NewCollector(logger *zap.Logger, factories otelcol.Factories, version string) *Collector {

java/sample-apps/aws-sdk/deploy/agent/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ module "hello-lambda-function" {
2626
OTEL_METRICS_EXPORTER = "otlp",
2727
} :
2828
{
29-
AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler",
30-
OTEL_METRICS_EXPORTER = "otlp",
31-
OPENTELEMETRY_COLLECTOR_CONFIG_FILE = "/opt/config.yaml"
29+
AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler",
30+
OTEL_METRICS_EXPORTER = "otlp",
31+
OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml"
3232
})
3333

3434
tracing_mode = var.tracing_mode

java/sample-apps/sqs/deploy/agent/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ module "hello-lambda-function" {
2626
OTEL_METRICS_EXPORTER = "otlp",
2727
} :
2828
{
29-
AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler",
30-
OTEL_METRICS_EXPORTER = "otlp",
31-
OPENTELEMETRY_COLLECTOR_CONFIG_FILE = "/opt/config.yaml"
29+
AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-handler",
30+
OTEL_METRICS_EXPORTER = "otlp",
31+
OPENTELEMETRY_COLLECTOR_CONFIG_URI = "/opt/config.yaml"
3232
})
3333

3434
tracing_mode = var.tracing_mode

0 commit comments

Comments
 (0)