Skip to content

Commit

Permalink
Set default Propagators list and bash script flags (#1226)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tylerbenson authored Mar 26, 2024
1 parent 87e2f04 commit 039caa5
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 3 deletions.
6 changes: 6 additions & 0 deletions java/layer-javaagent/scripts/otel-handler
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/bin/bash

set -ef -o pipefail

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

if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
fi

export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000

########################################
Expand Down
6 changes: 6 additions & 0 deletions java/layer-wrapper/scripts/otel-handler
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

set -ef -o pipefail

export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingRequestWrapper"

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

if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
fi

export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000

# java17 runtime puts the handler to run as a command line argument and seems to prefer
Expand Down
6 changes: 6 additions & 0 deletions java/layer-wrapper/scripts/otel-proxy-handler
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

set -ef -o pipefail

export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingRequestApiGatewayWrapper"

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

if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
fi

export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000

# java17 runtime puts the handler to run as a command line argument and seems to prefer
Expand Down
6 changes: 6 additions & 0 deletions java/layer-wrapper/scripts/otel-sqs-handler
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

set -ef -o pipefail

export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambdaevents.v2_2.TracingSqsEventWrapper"

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

if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
fi

export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000

# java17 runtime puts the handler to run as a command line argument and seems to prefer
Expand Down
6 changes: 6 additions & 0 deletions java/layer-wrapper/scripts/otel-stream-handler
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

set -ef -o pipefail

export OTEL_INSTRUMENTATION_AWS_LAMBDA_HANDLER="$_HANDLER"
export _HANDLER="io.opentelemetry.instrumentation.awslambdacore.v1_0.TracingRequestStreamWrapper"

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

if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
fi

export OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT=10000

# java17 runtime puts the handler to run as a command line argument and seems to prefer
Expand Down
6 changes: 6 additions & 0 deletions nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/bash

set -ef -o pipefail

export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"

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

if [[ -z "$OTEL_PROPAGATORS" ]]; then
export OTEL_PROPAGATORS="tracecontext,baggage,xray"
fi

exec "$@"
2 changes: 1 addition & 1 deletion python/sample-apps/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -euf -o pipefail

cp -r ../src/otel .
cp ../src/run.sh layer.sh
Expand Down
8 changes: 8 additions & 0 deletions python/src/otel/otel_sdk/otel-instrument
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -ef -o pipefail

# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -98,6 +100,12 @@ 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 the Resource Detectors (Resource Attributes)
#
# TODO: waiting on OTel Python support for configuring Resource Detectors from
Expand Down
3 changes: 1 addition & 2 deletions utils/sam/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

set -e
set -u
set -euf -o pipefail

echo_usage() {
echo "usage: Deploy Lambda layer/application by SAM"
Expand Down

0 comments on commit 039caa5

Please sign in to comment.