Skip to content

Commit

Permalink
Support set -u option
Browse files Browse the repository at this point in the history
  • Loading branch information
plengauer authored Jan 1, 2025
1 parent 4e671fe commit 7f6014e
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ span_handle="$(otel_span_start CONSUMER send/receive)"
_otel_netcat_parse_args 1 "$span_handle" $netcat_command_string > /dev/null
otel_span_activate "$span_handle"

if \[ "$OTEL_SHELL_CONFIG_NETCAT_ASSUME_REQUEST_RESPONSE" = TRUE ]; then
if \[ "${OTEL_SHELL_CONFIG_NETCAT_ASSUME_REQUEST_RESPONSE:-FALSE}" = TRUE ]; then
exit_code_file="$(\mktemp)"
\echo 0 > "$exit_code_file"
span_handle_file_0="$(\mktemp -u)_opentelemetry_shell_$$.netcat.request.span_handle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh -e
if [ "$OTEL_SHELL_AUTO_INJECTED" = TRUE ]; then
if [ "${OTEL_SHELL_AUTO_INJECTED:-FALSE}" = TRUE ]; then
exec "$@"
else
. otelapi.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ _otel_inject_shell_with_c_flag() {
return $exit_code
}

if \[ "$OTEL_SHELL_CONFIG_INSTRUMENT_ABSOLUTE_PATHS" = TRUE ]; then _otel_alias_prepend bash _otel_inject_shell_with_copy; else _otel_alias_prepend bash _otel_inject_shell_with_c_flag; fi
if \[ "${OTEL_SHELL_CONFIG_INSTRUMENT_ABSOLUTE_PATHS:-FALSE}" = TRUE ]; then _otel_alias_prepend bash _otel_inject_shell_with_copy; else _otel_alias_prepend bash _otel_inject_shell_with_c_flag; fi
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ _otel_propagate_curl() {
if \[ -f /opt/opentelemetry_shell/libinjecthttpheader.so ] && ! ( \[ "$_otel_shell" = 'busybox sh' ] && \help | \tail -n +3 | \grep -q curl ); then
export OTEL_SHELL_INJECT_HTTP_SDK_PIPE="$_otel_remote_sdk_pipe"
export OTEL_SHELL_INJECT_HTTP_HANDLE_FILE="$(\mktemp -u)_opentelemetry_shell_$$.curl.handle)"
local OLD_LD_PRELOAD="$LD_PRELOAD"
local OLD_LD_PRELOAD="${LD_PRELOAD:-}"
export LD_PRELOAD=/opt/opentelemetry_shell/libinjecthttpheader.so
if \[ -n "$OLD_PRELOAD" ]; then
if \[ -n "$OLD_LD_PRELOAD" ]; then
export LD_PRELOAD="$LD_PRELOAD:$OLD_LD_PRELOAD"
fi
fi
if _otel_string_contains "$(_otel_dollar_star "$@")" " -v "; then local is_verbose=1; fi
if _otel_string_contains "$(_otel_dollar_star "$@")" " -v "; then local is_verbose=1; else local is_verbose=0; fi
local stderr_pipe="$(\mktemp -u)_opentelemetry_shell_$$.stderr.curl.pipe"
\mkfifo "$stderr_pipe"
_otel_pipe_curl_stderr "$is_verbose" "$OTEL_SHELL_INJECT_HTTP_HANDLE_FILE" < "$stderr_pipe" >&2 &
Expand All @@ -26,7 +26,7 @@ _otel_propagate_curl() {
\wait "$stderr_pid"
\rm "$stderr_pipe"
if \[ -f /opt/opentelemetry_shell/libinjecthttpheader.so ]; then
if \[ -n "$OLD_LD_PRELOAD" ]; then
if \[ -n "${OLD_LD_PRELOAD:-}" ]; then
export LD_PRELOAD="$OLD_LD_PRELOAD"
else
unset LD_PRELOAD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ _otel_inject_docker_args() {
\echo -n ' '; _otel_escape_arg "$1"; shift
\echo -n ' '; _otel_escape_args -c '. otel.sh
eval _otel_inject "$(_otel_escape_args "$@")"' sh
\echo -n ' '; if \[ -n "$entrypoint_override" ]; then \echo "$entrypoint_override" | _otel_line_split; else "$executable" inspect "$image" | \jq -r '.[0].Config.Entrypoint[]?'; fi | _otel_escape_stdin
\echo -n ' '; if \[ -n "${entrypoint_override:-}" ]; then \echo "$entrypoint_override" | _otel_line_split; else "$executable" inspect "$image" | \jq -r '.[0].Config.Entrypoint[]?'; fi | _otel_escape_stdin
if \[ "$#" = 0 ]; then \echo -n ' '; "$executable" inspect "$image" | \jq -r '.[0].Config.Cmd[]?' | _otel_escape_stdin; fi
else
\echo -n ' '; _otel_escape_args --env TRACEPARENT="$TRACEPARENT" --env TRACESTATE="$TRACESTATE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_otel_inject_inner_command_args() {
local IFS='
'
local more_args="$OTEL_SHELL_INJECT_INNER_COMMAND_MORE_ARGS"
local more_args="${OTEL_SHELL_INJECT_INNER_COMMAND_MORE_ARGS:-}"
unset OTEL_SHELL_INJECT_INNER_COMMAND_MORE_ARGS
_otel_escape_arg "$1"
local command="$1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ _otel_netcat_parse_request() {
otel_span_attribute_typed "$span_handle" string[1] http.request.header."$key"="$value"
done < "$headers"
\printf '\r\n'
if \[ -n "$length" ]; then # TODO this shoudl transparently pipe the entire request through, even if it is not in line with content-length (or content-length hasn't been set at all)
if \[ -n "${length:-}" ]; then # TODO this should transparently pipe the entire request through, even if it is not in line with content-length (or content-length hasn't been set at all)
\head -c "$length"
fi
\rm "$headers" 2> /dev/null
Expand Down Expand Up @@ -183,7 +183,7 @@ _otel_netcat_parse_response() {
_otel_netcat_parse_args() {
local is_server_side="$1"; shift
local span_handle="$1"; shift
if \[ -n "$NCAT_PROTO" ]; then
if \[ -n "${NCAT_PROTO:-}" ]; then
otel_span_attribute_typed "$span_handle" string network.transport="$NCAT_PROTO"
otel_span_attribute_typed "$span_handle" string network.peer.address="$NCAT_REMOTE_ADDR"
otel_span_attribute_typed "$span_handle" int network.peer.port="$NCAT_REMOTE_PORT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ _otel_inject_node_args() {
elif _otel_string_starts_with "$1" -; then
_otel_escape_arg "$1"; shift
else
if \[ "$OTEL_SHELL_CONFIG_INJECT_DEEP" = TRUE ] && \[ -d "$(\readlink -f /usr/share/opentelemetry_shell/node_modules)" ]; then
if \[ "$next_is_code" = TRUE ]; then
if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] && \[ -d "$(\readlink -f /usr/share/opentelemetry_shell/node_modules)" ]; then
if \[ "${next_is_code:-FALSE}" = TRUE ]; then
_otel_escape_arg "$1"; \echo -n ' '
local base_dir="$(\echo "$1" | \rev | \cut -d / -f 2- | \rev)"
else
Expand All @@ -41,10 +41,10 @@ _otel_inject_node_args() {
if \[ -z "$dir" ]; then local dir="$base_dir"; fi
if _otel_is_node_injected "$dir"; then
_otel_escape_args --require /usr/share/opentelemetry_shell/agent.instrumentation.node.deep.link.js
elif \[ -z "$OTEL_TRACES_EXPORTER" ] || \[ "$OTEL_TRACES_EXPORTER" = console ] || \[ "$OTEL_TRACES_EXPORTER" = otlp ]; then
elif \[ -z "${OTEL_TRACES_EXPORTER:-}" ] || \[ "${OTEL_TRACES_EXPORTER:-}" = console ] || \[ "${OTEL_TRACES_EXPORTER:-}" = otlp ]; then
_otel_escape_args --require /usr/share/opentelemetry_shell/agent.instrumentation.node.deep.instrument.js
fi
if ! \[ "$next_is_code" = TRUE ]; then \echo -n ' '; _otel_escape_arg "$1"; fi
if ! \[ "${next_is_code:-FALSE}" = TRUE ]; then \echo -n ' '; _otel_escape_arg "$1"; fi
else
_otel_escape_arg "$1"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _otel_inject_parallel_gnu_arguments() {
local in_exec=1
\echo -n "-q $_otel_shell -c '. otel.sh
"
if \[ "$OTEL_SHELL_EXPERIMENTAL_INSTRUMENT_MINIMALLY" = TRUE ]; then
if \[ "${OTEL_SHELL_EXPERIMENTAL_INSTRUMENT_MINIMALLY:-}" = TRUE ]; then
no_quote=1 _otel_escape_arg "$arg"
else
no_quote=1 _otel_escape_arg "otel_observe $arg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/bin/false

_otel_inject_python() {
if \[ "$OTEL_SHELL_CONFIG_INJECT_DEEP" = TRUE ] && \[ -d "/opt/opentelemetry_shell/venv" ] && _otel_string_starts_with "$(\eval "$1 -V" | \cut -d ' ' -f 2)" "3." && ! _otel_string_ends_with "$2" /pip && ! _otel_string_ends_with "$2" /pip3; then
if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] && \[ -d "/opt/opentelemetry_shell/venv" ] && _otel_string_starts_with "$(\eval "$1 -V" | \cut -d ' ' -f 2)" "3." && ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3; then
local cmdline="$(_otel_dollar_star "$@")"
local cmdline="${cmdline#\\}"
if _otel_python_is_customize_injectable; then
local command="$1"; shift
set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@"
OTEL_SHELL_COMMANDLINE_OVERRIDE="$cmdline" OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="0" OTEL_SHELL_AUTO_INJECTED=TRUE PYTHONPATH=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$PYTHONPATH" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@"
OTEL_SHELL_COMMANDLINE_OVERRIDE="$cmdline" OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="0" OTEL_SHELL_AUTO_INJECTED=TRUE PYTHONPATH=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"${PYTHONPATH:-}" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@"
else
\eval "set -- $(_otel_python_inject_args "$@")"
local command="$1"; shift
set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@"
if \[ "$_otel_python_code_source" = stdin ]; then
if \[ "${_otel_python_code_source:-}" = stdin ]; then
unset _otel_python_code_source
{ \cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py; \cat; } | OTEL_SHELL_COMMANDLINE_OVERRIDE="$cmdline" OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="0" OTEL_SHELL_AUTO_INJECTED=TRUE PYTHONPATH=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$PYTHONPATH" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@"
{ \cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py; \cat; } | OTEL_SHELL_COMMANDLINE_OVERRIDE="$cmdline" OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="0" OTEL_SHELL_AUTO_INJECTED=TRUE PYTHONPATH=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"${PYTHONPATH:-}" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@"
else
OTEL_SHELL_COMMANDLINE_OVERRIDE="$cmdline" OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="0" OTEL_SHELL_AUTO_INJECTED=TRUE PYTHONPATH=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$PYTHONPATH" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@"
OTEL_SHELL_COMMANDLINE_OVERRIDE="$cmdline" OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="0" OTEL_SHELL_AUTO_INJECTED=TRUE PYTHONPATH=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"${PYTHONPATH:-}" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@"
fi
fi
else
Expand All @@ -29,7 +29,7 @@ _otel_inject_opentelemetry_instrument() {
local cmdline="$(_otel_dollar_star "$@")"
local cmdline="${cmdline#\\}"
\eval "set -- $(_otel_python_inject_args "$@")"
if \[ "$_otel_python_code_source" = stdin ]; then
if \[ "${_otel_python_code_source:-}" = stdin ]; then
unset _otel_python_code_source
{ \cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py; \cat; } | OTEL_SHELL_COMMANDLINE_OVERRIDE="$cmdline" OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="0" OTEL_SHELL_AUTO_INJECTED=TRUE OTEL_BSP_MAX_EXPORT_BATCH_SIZE="${OTEL_BSP_MAX_EXPORT_BATCH_SIZE:-1}" _otel_call "$@"
else
Expand Down Expand Up @@ -77,7 +77,7 @@ with open('$arg', 'r') as file: # SKIP_DEPENDENCY_CHECK
local injected=file
fi
done
if \[ -z "$injected" ]; then
if \[ -z "${injected:-}" ]; then
_otel_python_code_source=stdin
fi
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ if _otel_string_contains "$(_otel_resolve_command_self)" /usr/local/bin/renovate
export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE
export OTEL_SHELL_CONFIG_INSTRUMENT_ABSOLUTE_PATHS=TRUE
export OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1
if _otel_string_contains "$OTEL_TRACES_EXPORTER" console; then export RENOVATE_TRACING_CONSOLE_EXPORTER=true; fi
if \[ -z "$OTEL_EXPORTER_OTLP_ENDPOINT" ] && ( _otel_string_contains "$OTEL_TRACES_EXPORTER" otlp || \[ -z "$OTEL_TRACES_EXPORTER" ] ); then
if \[ -n "$OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" ]; then
if _otel_string_contains "${OTEL_TRACES_EXPORTER:-}" console; then export RENOVATE_TRACING_CONSOLE_EXPORTER=true; fi
if \[ -z "${OTEL_EXPORTER_OTLP_ENDPOINT:-}" ] && ( _otel_string_contains "${OTEL_TRACES_EXPORTER:-}" otlp || \[ -z "${OTEL_TRACES_EXPORTER:-}" ] ); then
if \[ -n "${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:-}" ]; then
if _otel_string_ends_with "$OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" /v1/traces; then
export OTEL_EXPORTER_OTLP_ENDPOINT="${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT%/v1/traces}"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ _otel_inject_shell_args_with_copy() {
\echo "OTEL_SHELL_AUTO_INSTRUMENTATION_HINT='$temporary_script'" >> "$temporary_script"
\echo ". otel.sh" >> "$temporary_script"
\echo "\set -- $(_otel_escape_args "$@")" >> "$temporary_script"
if \[ "$is_script" -eq 1 ]; then \cat "$command"; else \echo "$command"; fi | if \[ "$OTEL_SHELL_CONFIG_INSTRUMENT_ABSOLUTE_PATHS" = TRUE ]; then \awk '{
if \[ "$is_script" -eq 1 ]; then \cat "$command"; else \echo "$command"; fi | if \[ "${OTEL_SHELL_CONFIG_INSTRUMENT_ABSOLUTE_PATHS:-FALSE}" = TRUE ]; then \awk '{
gsub(/^[ \t]+/, "", $0);
if ($1 ~ /^\//) {
print "_otel_inject " $0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ _otel_propagate_wget() {
if \[ -f /opt/opentelemetry_shell/libinjecthttpheader.so ] && ! ( \[ "$_otel_shell" = 'busybox sh' ] && \help | \tail -n +3 | \grep -q wget ); then
export OTEL_SHELL_INJECT_HTTP_SDK_PIPE="$_otel_remote_sdk_pipe"
export OTEL_SHELL_INJECT_HTTP_HANDLE_FILE="$(\mktemp -u)_opentelemetry_shell_$$.wget.handle"
local OLD_LD_PRELOAD="$LD_PRELOAD"
local OLD_LD_PRELOAD="${LD_PRELOAD:-}"
export LD_PRELOAD=/opt/opentelemetry_shell/libinjecthttpheader.so
if \[ -n "$OLD_PRELOAD" ]; then
if \[ -n "$OLD_LD_PRELOAD" ]; then
export LD_PRELOAD="$LD_PRELOAD:$OLD_LD_PRELOAD"
fi
fi
local stderr_pipe="$(\mktemp -u)_opentelemetry_shell_$$.stderr.wget.pipe"
\mkfifo "$stderr_pipe"
_otel_pipe_wget_stderr "$OTEL_SHELL_INJECT_HTTP_HANDLE_FILE" < "$stderr_pipe" >&2 &
_otel_pipe_wget_stderr "${OTEL_SHELL_INJECT_HTTP_HANDLE_FILE:-}" < "$stderr_pipe" >&2 &
local stderr_pid="$!"
local exit_code=0
_otel_call "$@" --header="traceparent: $TRACEPARENT" --header="tracestate: $TRACESTATE" 2> "$stderr_pipe" || exit_code="$?"
\wait "$stderr_pid"
\rm "$stderr_pipe"
if \[ -f /opt/opentelemetry_shell/libinjecthttpheader.so ]; then
if \[ -n "$OLD_LD_PRELOAD" ]; then
if \[ -n "${OLD_LD_PRELOAD:-}" ]; then
export LD_PRELOAD="$OLD_LD_PRELOAD"
else
unset LD_PRELOAD
Expand Down
Loading

0 comments on commit 7f6014e

Please sign in to comment.