From c09824fd8e5a1bbca1d896c39b3edef7e35849ea Mon Sep 17 00:00:00 2001 From: Min Xia Date: Fri, 11 Oct 2024 10:37:25 -0700 Subject: [PATCH] Remove otel-instrument-est wraper (#103) *Issue #, if available:* *Description of changes:* Follow changes on https://github.com/aws-observability/aws-otel-js-instrumentation/pull/101. Instead of using a `otel-instrument-esm` wrapper which is redudent, we will have customer to use `HANDLER_IS_ESM` env var to enforce ESM instrumentation for the failed to detected cases. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --- .../packages/layer/scripts/otel-instrument | 4 +- .../layer/scripts/otel-instrument-esm | 46 ------------------- 2 files changed, 2 insertions(+), 48 deletions(-) delete mode 100644 lambda-layer/packages/layer/scripts/otel-instrument-esm diff --git a/lambda-layer/packages/layer/scripts/otel-instrument b/lambda-layer/packages/layer/scripts/otel-instrument index f5394e8..9366295 100644 --- a/lambda-layer/packages/layer/scripts/otel-instrument +++ b/lambda-layer/packages/layer/scripts/otel-instrument @@ -1,5 +1,5 @@ #!/bin/bash -isESMScript() { +_is_esm_handler() { # Lambda function root directory TASK_DIR="/var/task" @@ -28,7 +28,7 @@ isESMScript() { fi } -if isESMScript; then +if _is_esm_handler || [[ ${HANDLER_IS_ESM} == true ]]; then export NODE_OPTIONS="${NODE_OPTIONS} --import @aws/aws-distro-opentelemetry-node-autoinstrumentation/register --experimental-loader=@opentelemetry/instrumentation/hook.mjs" export HANDLER_IS_ESM=true else diff --git a/lambda-layer/packages/layer/scripts/otel-instrument-esm b/lambda-layer/packages/layer/scripts/otel-instrument-esm deleted file mode 100644 index c6e9511..0000000 --- a/lambda-layer/packages/layer/scripts/otel-instrument-esm +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -export NODE_OPTIONS="${NODE_OPTIONS} --import @aws/aws-distro-opentelemetry-node-autoinstrumentation/register --experimental-loader=@opentelemetry/instrumentation/hook.mjs" -export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION,faas.instance=$AWS_LAMBDA_LOG_STREAM_NAME,aws.log.group.names=$AWS_LAMBDA_LOG_GROUP_NAME"; -export HANDLER_IS_ESM=true - -# - If OTEL_EXPORTER_OTLP_PROTOCOL is not set by user, the default exporting protocol is http/protobuf. -if [ -z "${OTEL_EXPORTER_OTLP_PROTOCOL}" ]; then - export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf -fi - -# - If OTEL_NODE_ENABLED_INSTRUMENTATIONS is not set by user, use default instrumentation -if [ -z "${OTEL_NODE_ENABLED_INSTRUMENTATIONS}" ]; then - export OTEL_NODE_ENABLED_INSTRUMENTATIONS="aws-lambda,aws-sdk" -fi - -# - Set the service name -if [ -z "${OTEL_SERVICE_NAME}" ]; then - export OTEL_SERVICE_NAME=$AWS_LAMBDA_FUNCTION_NAME; -fi - -# - Set the propagators -if [[ -z "$OTEL_PROPAGATORS" ]]; then - export OTEL_PROPAGATORS="tracecontext,baggage,xray" -fi - -# - Set Application Signals configuration -if [ -z "${OTEL_AWS_APPLICATION_SIGNALS_ENABLED}" ]; then - export OTEL_AWS_APPLICATION_SIGNALS_ENABLED="true"; -fi - -if [ -z "${OTEL_METRICS_EXPORTER}" ]; then - export OTEL_METRICS_EXPORTER="none"; -fi - -# - Append Lambda Resource Attributes to OTel Resource Attribute List -if [ -z "${OTEL_RESOURCE_ATTRIBUTES}" ]; then - export OTEL_RESOURCE_ATTRIBUTES=$LAMBDA_RESOURCE_ATTRIBUTES; -else - export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES,$OTEL_RESOURCE_ATTRIBUTES"; -fi - -if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then - export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}" -fi - -exec "$@"