Skip to content

Commit

Permalink
Autodetect if modules hook is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSumislawski committed Apr 23, 2024
1 parent 483ece1 commit be53f90
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nodejs/packages/layer/scripts/otel-handler
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
echo "LAMBDA_TASK_ROOT=${LAMBDA_TASK_ROOT}"
echo "_HANDLER=${_HANDLER}"

possible_mjs_handler_file="${LAMBDA_TASK_ROOT}/${_HANDLER%.*}.mjs"
echo "possible_mjs_handler_file=${possible_mjs_handler_file}"

# If the handler is in an .mjs file we need to use a loader hook. We can't detect it here because the corresponding env vars are not available at this point
if [ "$OTEL_NODEJS_HOOK" == "modules" ]; then
if [ "$OTEL_NODEJS_HOOK" == "modules" ] || [ -f "$possible_mjs_handler_file" ]; then
export NODE_OPTIONS="${NODE_OPTIONS} --experimental-loader=@opentelemetry/instrumentation/hook.mjs"
# Disable node warnings caused by --experimental-loader
export NODE_NO_WARNINGS=1
Expand Down

0 comments on commit be53f90

Please sign in to comment.