Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename OPENTELEMETRY_COLLECTOR_CONFIG_FILE to OPENTELEMETRY_COLLECTOR_CONFIG_URI #1521

Merged
merged 9 commits into from
Sep 14, 2024
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
12 changes: 6 additions & 6 deletions collector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -85,7 +85,7 @@ from an S3 object using a CloudFormation template:
...
Environment:
Variables:
OPENTELEMETRY_COLLECTOR_CONFIG_FILE: s3://<bucket_name>.s3.<region>.amazonaws.com/collector_config.yaml
OPENTELEMETRY_COLLECTOR_CONFIG_URI: s3://<bucket_name>.s3.<region>.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.
Expand Down
23 changes: 18 additions & 5 deletions collector/internal/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions java/sample-apps/aws-sdk/deploy/agent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions java/sample-apps/sqs/deploy/agent/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading