diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f49ba62..b544851 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -772,6 +772,10 @@ jobs: mkdir -p "${GENERATED_DIR}" envsubst '$REPO_NAME' < templates/.Dockerfile-lambda-template.tmpl | tee "${GENERATED_DIR}/Dockerfile.lambda" envsubst < templates/.goreleaser-docker-lambda-template.yaml.tmpl | tee "${GENERATED_DIR}/.goreleaser.lambda.yaml" + # Copy collector config into caller repo for GoReleaser extra_files. + # Exclude from git to avoid dirty working tree detection. + cp collector.yaml ../_caller/collector.yaml + echo "collector.yaml" >> ../_caller/.git/info/exclude - name: Docker Login if: inputs.docker == true diff --git a/collector.yaml b/collector.yaml new file mode 100644 index 0000000..256b6e1 --- /dev/null +++ b/collector.yaml @@ -0,0 +1,29 @@ +# OpenTelemetry Collector configuration for Lambda connector extensions. +# The collector runs as a Lambda extension process, receiving telemetry from +# the connector via OTLP on localhost and forwarding it to the central +# collector before Lambda freezes or shuts down the execution environment. +receivers: + otlp: + protocols: + grpc: + endpoint: localhost:4317 + http: + endpoint: localhost:4318 + +exporters: + otlp: + endpoint: otel-collector:4317 + tls: + insecure_skip_verify: true + +service: + pipelines: + traces: + receivers: [otlp] + exporters: [otlp] + metrics: + receivers: [otlp] + exporters: [otlp] + logs: + receivers: [otlp] + exporters: [otlp] diff --git a/templates/.Dockerfile-lambda-template.tmpl b/templates/.Dockerfile-lambda-template.tmpl index 241fe5d..1f5faa9 100644 --- a/templates/.Dockerfile-lambda-template.tmpl +++ b/templates/.Dockerfile-lambda-template.tmpl @@ -1,3 +1,16 @@ +# Stage 1: Download and unpack the OpenTelemetry Collector Lambda extension +# https://github.com/open-telemetry/opentelemetry-lambda/tree/main/collector +FROM amazonlinux:2023 AS otel-layer +RUN yum install -y unzip && yum clean all +ADD https://github.com/open-telemetry/opentelemetry-lambda/releases/download/layer-collector%2F0.20.0/opentelemetry-collector-layer-arm64.zip /tmp/otel-layer.zip +RUN unzip /tmp/otel-layer.zip -d /otel && \ + chmod +x /otel/extensions/collector && \ + rm -f /tmp/otel-layer.zip + +# Stage 2: Final Lambda image with connector binary + OTel collector extension FROM public.ecr.aws/lambda/provided:al2023 +COPY ${REPO_NAME} /${REPO_NAME} +COPY --from=otel-layer /otel/extensions/collector /opt/extensions/collector +COPY collector.yaml /var/task/collector.yaml +ENV OPENTELEMETRY_COLLECTOR_CONFIG_URI=/var/task/collector.yaml ENTRYPOINT ["/${REPO_NAME}", "lambda"] -COPY ${REPO_NAME} /${REPO_NAME} \ No newline at end of file diff --git a/templates/.goreleaser-docker-lambda-template.yaml.tmpl b/templates/.goreleaser-docker-lambda-template.yaml.tmpl index 9376a81..091d17c 100644 --- a/templates/.goreleaser-docker-lambda-template.yaml.tmpl +++ b/templates/.goreleaser-docker-lambda-template.yaml.tmpl @@ -25,6 +25,8 @@ dockers: dockerfile: ${DOCKERFILE_LAMBDA_PATH} image_templates: - "168442440833.dkr.ecr.us-west-2.amazonaws.com/${REPO_NAME}:{{ .Version }}-arm64" + extra_files: + - collector.yaml build_flag_templates: - "--platform=linux/arm64" - "--label=org.opencontainers.image.created={{.Date}}"