Skip to content

Commit 039caa5

Browse files
authored
Set default Propagators list and bash script flags (#1226)
We want the default propagators to include both w3c context and xray, so set `OTEL_PROPAGATORS=tracecontext,baggage,xray` if it isn't already set to something else. Users that send traces to X-Ray, especially if they enable Active Tracing, should override this value to `OTEL_PROPAGATORS=tracecontext,baggage,xray-lambda` to ensure proper span relationships. I also added some common bash flags to align with industry standard practice.
1 parent 87e2f04 commit 039caa5

File tree

9 files changed

+46
-3
lines changed

9 files changed

+46
-3
lines changed

java/layer-javaagent/scripts/otel-handler

+6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#!/bin/bash
22

3+
set -ef -o pipefail
4+
35
export JAVA_TOOL_OPTIONS="-javaagent:/opt/opentelemetry-javaagent.jar ${JAVA_TOOL_OPTIONS}"
46

57
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
68
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
79
fi
810

11+
if [[ -z "$OTEL_PROPAGATORS" ]]; then
12+
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
13+
fi
14+
915
export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000
1016

1117
########################################

java/layer-wrapper/scripts/otel-handler

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#!/bin/bash
22

3+
set -ef -o pipefail
4+
35
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
46
export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingRequestWrapper"
57

68
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
79
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
810
fi
911

12+
if [[ -z "$OTEL_PROPAGATORS" ]]; then
13+
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
14+
fi
15+
1016
export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000
1117

1218
# java17 runtime puts the handler to run as a command line argument and seems to prefer

java/layer-wrapper/scripts/otel-proxy-handler

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#!/bin/bash
22

3+
set -ef -o pipefail
4+
35
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
46
export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingRequestApiGatewayWrapper"
57

68
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
79
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
810
fi
911

12+
if [[ -z "$OTEL_PROPAGATORS" ]]; then
13+
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
14+
fi
15+
1016
export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000
1117

1218
# java17 runtime puts the handler to run as a command line argument and seems to prefer

java/layer-wrapper/scripts/otel-sqs-handler

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#!/bin/bash
22

3+
set -ef -o pipefail
4+
35
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
46
export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingSqsEventWrapper"
57

68
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
79
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
810
fi
911

12+
if [[ -z "$OTEL_PROPAGATORS" ]]; then
13+
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
14+
fi
15+
1016
export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000
1117

1218
# java17 runtime puts the handler to run as a command line argument and seems to prefer

java/layer-wrapper/scripts/otel-stream-handler

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#!/bin/bash
22

3+
set -ef -o pipefail
4+
35
export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
46
export _HANDLER="io.opentelemetry.instrumentation.awslambdacore.v1_0.TracingRequestStreamWrapper"
57

68
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
79
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
810
fi
911

12+
if [[ -z "$OTEL_PROPAGATORS" ]]; then
13+
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
14+
fi
15+
1016
export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000
1117

1218
# java17 runtime puts the handler to run as a command line argument and seems to prefer
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/bin/bash
22

3+
set -ef -o pipefail
4+
35
export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"
46

57
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
68
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
79
fi
810

11+
if [[ -z "$OTEL_PROPAGATORS" ]]; then
12+
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
13+
fi
14+
915
exec "$@"

python/sample-apps/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -e
2+
set -euf -o pipefail
33

44
cp -r ../src/otel .
55
cp ../src/run.sh layer.sh

python/src/otel/otel_sdk/otel-instrument

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -ef -o pipefail
4+
35
# Copyright The OpenTelemetry Authors
46
#
57
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -98,6 +100,12 @@ if [ -z "${OTEL_SERVICE_NAME}" ]; then
98100
export OTEL_SERVICE_NAME=$AWS_LAMBDA_FUNCTION_NAME;
99101
fi
100102

103+
# - Set the propagators
104+
105+
if [[ -z "$OTEL_PROPAGATORS" ]]; then
106+
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
107+
fi
108+
101109
# - Set the Resource Detectors (Resource Attributes)
102110
#
103111
# TODO: waiting on OTel Python support for configuring Resource Detectors from

utils/sam/run.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22

3-
set -e
4-
set -u
3+
set -euf -o pipefail
54

65
echo_usage() {
76
echo "usage: Deploy Lambda layer/application by SAM"

0 commit comments

Comments
 (0)