Skip to content

Commit

Permalink
Merge branch 'main' into fix-upstream-platform-empty-logrecord-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrytfleung authored Sep 16, 2024
2 parents f5ba5ae + f641b6b commit e5e62fa
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 18 deletions.
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
1 change: 1 addition & 0 deletions collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ require (
go.opentelemetry.io/collector/consumer v0.107.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.107.0 // indirect
go.opentelemetry.io/collector/exporter v0.107.0 // indirect
go.opentelemetry.io/collector/exporter/debugexporter v0.107.0 // indirect
go.opentelemetry.io/collector/exporter/loggingexporter v0.107.0 // indirect
go.opentelemetry.io/collector/exporter/otlpexporter v0.107.0 // indirect
go.opentelemetry.io/collector/exporter/otlphttpexporter v0.107.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions collector/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ go.opentelemetry.io/collector/consumer/consumertest v0.107.0 h1:BfjFHHAqbTmCN32a
go.opentelemetry.io/collector/consumer/consumertest v0.107.0/go.mod h1:qNMedscdVyuxbV+wWUt4yGKQM3c0YEgQJTFeAtGZjRY=
go.opentelemetry.io/collector/exporter v0.107.0 h1:Ioi2LfB+0HwU8A4kZsL/Lf1PghNlpEdShJal4DRkJ6g=
go.opentelemetry.io/collector/exporter v0.107.0/go.mod h1:BpiJI2e8qY6kkkF0xpmEgbO102N+VTWd7qBYDFrnm0M=
go.opentelemetry.io/collector/exporter/debugexporter v0.107.0 h1:q095py+9wKZhAPz2e7LWBAdeAgwelinfGEgTW9iGKMM=
go.opentelemetry.io/collector/exporter/debugexporter v0.107.0/go.mod h1:Wb4bs9P75pZTsZiabeXbfHm1gzTm0R3aX1vFWivFQZE=
go.opentelemetry.io/collector/exporter/loggingexporter v0.107.0 h1:R0+duooEsbeInhgnPOFqQb4MNNuO61Qj9wtxx3MWCnE=
go.opentelemetry.io/collector/exporter/loggingexporter v0.107.0/go.mod h1:PmuS64CkJWmtgWFsb55aVoNlErUYG4ggHizegSjoMuo=
go.opentelemetry.io/collector/exporter/otlpexporter v0.107.0 h1:4YTLYaihBZh8AdBcEDWrJTYXHtHu3JQagTa53Wu8iKQ=
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
2 changes: 2 additions & 0 deletions collector/lambdacomponents/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/spanprocessor"
"github.com/open-telemetry/opentelemetry-lambda/collector/processor/decoupleprocessor"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/debugexporter"
"go.opentelemetry.io/collector/exporter/loggingexporter"
"go.opentelemetry.io/collector/exporter/otlpexporter"
"go.opentelemetry.io/collector/exporter/otlphttpexporter"
Expand Down Expand Up @@ -52,6 +53,7 @@ func Components(extensionID string) (otelcol.Factories, error) {
}

exporters, err := exporter.MakeFactoryMap(
debugexporter.NewFactory(),
loggingexporter.NewFactory(),
otlpexporter.NewFactory(),
otlphttpexporter.NewFactory(),
Expand Down
1 change: 1 addition & 0 deletions collector/lambdacomponents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/open-telemetry/opentelemetry-lambda/collector/processor/decoupleprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-lambda/collector/receiver/telemetryapireceiver v0.98.0
go.opentelemetry.io/collector/exporter v0.107.0
go.opentelemetry.io/collector/exporter/debugexporter v0.107.0
go.opentelemetry.io/collector/exporter/loggingexporter v0.107.0
go.opentelemetry.io/collector/exporter/otlpexporter v0.107.0
go.opentelemetry.io/collector/exporter/otlphttpexporter v0.107.0
Expand Down
2 changes: 2 additions & 0 deletions collector/lambdacomponents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ go.opentelemetry.io/collector/consumer/consumertest v0.107.0 h1:BfjFHHAqbTmCN32a
go.opentelemetry.io/collector/consumer/consumertest v0.107.0/go.mod h1:qNMedscdVyuxbV+wWUt4yGKQM3c0YEgQJTFeAtGZjRY=
go.opentelemetry.io/collector/exporter v0.107.0 h1:Ioi2LfB+0HwU8A4kZsL/Lf1PghNlpEdShJal4DRkJ6g=
go.opentelemetry.io/collector/exporter v0.107.0/go.mod h1:BpiJI2e8qY6kkkF0xpmEgbO102N+VTWd7qBYDFrnm0M=
go.opentelemetry.io/collector/exporter/debugexporter v0.107.0 h1:q095py+9wKZhAPz2e7LWBAdeAgwelinfGEgTW9iGKMM=
go.opentelemetry.io/collector/exporter/debugexporter v0.107.0/go.mod h1:Wb4bs9P75pZTsZiabeXbfHm1gzTm0R3aX1vFWivFQZE=
go.opentelemetry.io/collector/exporter/loggingexporter v0.107.0 h1:R0+duooEsbeInhgnPOFqQb4MNNuO61Qj9wtxx3MWCnE=
go.opentelemetry.io/collector/exporter/loggingexporter v0.107.0/go.mod h1:PmuS64CkJWmtgWFsb55aVoNlErUYG4ggHizegSjoMuo=
go.opentelemetry.io/collector/exporter/otlpexporter v0.107.0 h1:4YTLYaihBZh8AdBcEDWrJTYXHtHu3JQagTa53Wu8iKQ=
Expand Down
3 changes: 2 additions & 1 deletion collector/processor/coldstartprocessor/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/open-telemetry/opentelemetry-lambda/collector/processor/coldstartprocessor

go 1.21
go 1.21.0

toolchain go1.22.5

require (
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

0 comments on commit e5e62fa

Please sign in to comment.