From aa840189ba3cc7bd7b4ef7fff57d2d3e6344a124 Mon Sep 17 00:00:00 2001 From: Prashant Srivastava <50466688+srprash@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:40:53 -0800 Subject: [PATCH] Renaming to otel-instrument and default configs (#956) --- lambda-layer/build-layer.sh | 2 +- lambda-layer/otel-handler | 24 ----------------------- lambda-layer/otel-instrument | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 25 deletions(-) delete mode 100644 lambda-layer/otel-handler create mode 100644 lambda-layer/otel-instrument diff --git a/lambda-layer/build-layer.sh b/lambda-layer/build-layer.sh index b99fce80c5..478ef68ba0 100755 --- a/lambda-layer/build-layer.sh +++ b/lambda-layer/build-layer.sh @@ -45,4 +45,4 @@ popd ## Copy ADOT Java Agent downloaded using Gradle task and bundle it with the Lambda handler script cp "$SOURCEDIR"/build/javaagent/aws-opentelemetry-agent*.jar ./opentelemetry-javaagent.jar -zip -qr opentelemetry-javaagent-layer.zip opentelemetry-javaagent.jar otel-handler +zip -qr opentelemetry-javaagent-layer.zip opentelemetry-javaagent.jar otel-instrument diff --git a/lambda-layer/otel-handler b/lambda-layer/otel-handler deleted file mode 100644 index 9104e2a7b2..0000000000 --- a/lambda-layer/otel-handler +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -export OTEL_INSTRUMENTATION_AWS_SDK_EXPERIMENTAL_SPAN_ATTRIBUTES=true - -export OTEL_PROPAGATORS="${OTEL_PROPAGATORS:-xray,tracecontext,b3,b3multi}" - -# Temporarily set OTEL_SERVICE_NAME variable to work around but in javaagent not handling -# OTEL_RESOURCE_ATTRIBUTES as set in otel-handler-upstream. It doesn't hurt to apply this -# to wrapper as well. -# TODO(anuraaga): Move to opentelemetry-lambda -export OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME:-${AWS_LAMBDA_FUNCTION_NAME}} - -export JAVA_TOOL_OPTIONS="-javaagent:/opt/opentelemetry-javaagent.jar ${JAVA_TOOL_OPTIONS}" - -if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then - export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}" -fi - -export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000 - -# Disable the Application Signals runtime metrics since we are on Lambda -export OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED=false - -exec "$@" diff --git a/lambda-layer/otel-instrument b/lambda-layer/otel-instrument new file mode 100644 index 0000000000..450eb925a5 --- /dev/null +++ b/lambda-layer/otel-instrument @@ -0,0 +1,38 @@ +#!/bin/bash + +export OTEL_INSTRUMENTATION_AWS_SDK_EXPERIMENTAL_SPAN_ATTRIBUTES=true + +export OTEL_PROPAGATORS="${OTEL_PROPAGATORS:-xray,tracecontext,b3,b3multi}" + +export OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME:-${AWS_LAMBDA_FUNCTION_NAME}} + +export JAVA_TOOL_OPTIONS="-javaagent:/opt/opentelemetry-javaagent.jar ${JAVA_TOOL_OPTIONS}" + +if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then + export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}" +fi + +export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000 + +# Disable the Application Signals runtime metrics since we are on Lambda +export OTEL_AWS_APPLICATION_SIGNALS_RUNTIME_ENABLED=false + +# Use OTLP traces exporter if not specified +export OTEL_TRACES_EXPORTER=${OTEL_TRACES_EXPORTER:-"otlp"} + +# Disable metrics and logs export by default if not specified +export OTEL_METRICS_EXPORTER=${OTEL_METRICS_EXPORTER:-"none"} +export OTEL_LOGS_EXPORTER=${OTEL_LOGS_EXPORTER:-"none"} + +# Enable Application Signals by default if not specified +export OTEL_AWS_APPLICATION_SIGNALS_ENABLED=${OTEL_AWS_APPLICATION_SIGNALS_ENABLED:-"true"} + +# Append Lambda Resource Attributes to OTel Resource Attribute List +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"; +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 + +exec "$@"