diff --git a/src/usr/share/opentelemetry_shell/agent.injection.netcat.handler.sh b/src/usr/share/opentelemetry_shell/agent.injection.netcat.handler.sh index 29b30b5df..0f2254d39 100755 --- a/src/usr/share/opentelemetry_shell/agent.injection.netcat.handler.sh +++ b/src/usr/share/opentelemetry_shell/agent.injection.netcat.handler.sh @@ -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" diff --git a/src/usr/share/opentelemetry_shell/agent.injection.netcat.sh b/src/usr/share/opentelemetry_shell/agent.injection.netcat.sh index e750c8071..4cab456e4 100755 --- a/src/usr/share/opentelemetry_shell/agent.injection.netcat.sh +++ b/src/usr/share/opentelemetry_shell/agent.injection.netcat.sh @@ -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 diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.bash.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.bash.sh index d17a67feb..e606d27f5 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.bash.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.bash.sh @@ -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 diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.curl.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.curl.sh index ea575dfd9..23553f068 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.curl.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.curl.sh @@ -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 & @@ -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 diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.docker.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.docker.sh index 02a985c26..a7a6dbc07 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.docker.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.docker.sh @@ -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" diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.inner.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.inner.sh index 0b9e5341a..6648bdfea 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.inner.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.inner.sh @@ -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" diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.netcat.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.netcat.sh index 8c2886e4a..3a20c2eac 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.netcat.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.netcat.sh @@ -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 @@ -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" diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.node.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.node.sh index 0ef525a36..fea6854db 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.node.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.node.sh @@ -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 @@ -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 diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.parallel.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.parallel.sh index 6118f6f11..5e539834a 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.parallel.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.parallel.sh @@ -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" diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index e977774d9..2ce9f2cdb 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -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 @@ -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 @@ -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 } diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh index 28a9ddbb9..d3b42e84b 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh @@ -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 diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.shells.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.shells.sh index 30797b394..25912f279 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.shells.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.shells.sh @@ -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; diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.wget.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.wget.sh index 9dc30dddd..12a9f618e 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.wget.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.wget.sh @@ -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 diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index bf19751c0..0a5ae274a 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -6,7 +6,7 @@ # All other functions and variables are for internal use only and therefore subject to change without notice! # ################################################################################################################ -if \[ "$_otel_shell_injected" = "TRUE" ]; then +if \[ "${_otel_shell_injected:-FALSE}" = "TRUE" ]; then return 0 fi _otel_shell_injected=TRUE @@ -15,13 +15,13 @@ case "$-" in *r*) \echo "WARNING OpenTelemetry for shell does not support restricted mode (set -r)!" >&2; return 0;; esac -_otel_shell_conservative_exec="$OTEL_SHELL_CONSERVATIVE_EXEC" +_otel_shell_conservative_exec="${OTEL_SHELL_CONSERVATIVE_EXEC:-FALSE}" unset OTEL_SHELL_CONSERVATIVE_EXEC \. /usr/share/opentelemetry_shell/api.sh _otel_package_version opentelemetry-shell > /dev/null # to build the cache outside a subshell -if \[ "$_otel_shell" = "bash" ] && \[ -n "$BASHPID" ] && \[ "$$" != "$BASHPID" ]; then +if \[ "$_otel_shell" = "bash" ] && \[ -n "${BASHPID:-}" ] && \[ "$$" != "$BASHPID" ]; then \echo "WARNING The OpenTelemetry shell file for auto-instrumentation is sourced in a subshell, automatic instrumentation will only be active within that subshell!" >&2 fi @@ -30,13 +30,13 @@ case "$-" in *) _otel_is_interactive=FALSE;; esac -if \[ -n "$OTEL_SHELL_AUTO_INSTRUMENTATION_HINT" ]; then +if \[ -n "${OTEL_SHELL_AUTO_INSTRUMENTATION_HINT:-}" ]; then _otel_shell_auto_instrumentation_hint="$OTEL_SHELL_AUTO_INSTRUMENTATION_HINT" unset OTEL_SHELL_AUTO_INSTRUMENTATION_HINT -elif \[ "$_otel_is_interactive" = "TRUE" ]; then - \echo "WARNING When using OpenTelemetry in an interactive shell for the first time after startup, it may take some time to create the instrumentation cache! Subsequent interactive shells will start faster. This performance impact does not apply in non-interactive shells, like scripts or invocations with -c." >&2 +elif \[ "$_otel_is_interactive" = TRUE ]; then + \echo "WARNING When using OpenTelemetry in an interactive shell for the first time after startup, it may take some time to create the instrumentation cache! Subsequent interactive shells will start faster. This performance impact does NOT apply in non-interactive shells, like scripts or invocations with -c." >&2 _otel_shell_auto_instrumentation_hint="" -elif \[ "$OTEL_SHELL_IS_DYNAMIC" = TRUE ]; then +elif \[ "${OTEL_SHELL_IS_DYNAMIC:-}" = TRUE ]; then _otel_shell_auto_instrumentation_hint="" unset OTEL_SHELL_IS_DYNAMIC elif \[ -f "$0" ] && \[ "$(\readlink -f "$0")" != "$(\readlink -f "/proc/$$/exe")" ]; then @@ -50,8 +50,8 @@ if \[ "$_otel_shell" = "bash" ]; then else _otel_source_file_resolver='$0' fi -_otel_source_line_resolver='$LINENO' -_otel_source_func_resolver='$FUNCNAME' +_otel_source_line_resolver='${LINENO:-}' +_otel_source_func_resolver='${FUNCNAME:-}' if \[ "$_otel_shell" = "bash" ]; then shopt -s expand_aliases 1> /dev/null 2> /dev/null @@ -67,7 +67,7 @@ _otel_auto_instrument() { ## (1) using the hint - will not work when scripts are changing or called the same but very fast! ## (2) using the resolved hint - will not work when new executables are added onto the system or their shebang changes or new bash.rc aliases are added ## (3) using the filtered list of commands - will work in every case but slowest - local cache_key="$({ _otel_list_path_commands | _otel_filter_commands_by_special | _otel_filter_commands_by_hint "$hint" | \sort -u; \alias; \echo "$PATH" "$_otel_shell_conservative_exec" "$OTEL_SHELL_CONFIG_INSTRUMENT_MINIMALLY"; } | \md5sum | \cut -d ' ' -f 1)" + local cache_key="$({ _otel_list_path_commands | _otel_filter_commands_by_special | _otel_filter_commands_by_hint "$hint" | \sort -u; \alias; \echo "$PATH" "$_otel_shell_conservative_exec" "${OTEL_SHELL_CONFIG_INSTRUMENT_MINIMALLY:-}"; } | \md5sum | \cut -d ' ' -f 1)" local cache_file="$TMPDIR/opentelemetry_shell_$(_otel_package_version opentelemetry-shell)"_"$_otel_shell"_instrumentation_cache_"$cache_key".aliases if \[ -f "$cache_file" ]; then \eval "$(\grep -vh '_otel_alias_prepend ' $(_otel_list_special_auto_instrument_files))" @@ -94,7 +94,7 @@ _otel_auto_instrument() { \alias .='_otel_instrument_and_source "$#" "$@" .' if \[ "$_otel_shell" = bash ]; then \alias source='_otel_instrument_and_source "$#" "$@" source'; fi if \[ "$_otel_shell_conservative_exec" = TRUE ]; then - if \[ -n "$LINENO" ]; then + if \[ -n "${LINENO:-}" ]; then \alias exec='eval "$(_otel_inject_and_exec_by_location "'$_otel_source_file_resolver'" "'$_otel_source_line_resolver'")"; exec' else \alias exec='_otel_record_exec; exec' @@ -178,7 +178,7 @@ _otel_filter_commands_by_instrumentation() { } _otel_filter_commands_by_mode() { - if \[ "$OTEL_SHELL_CONFIG_INSTRUMENT_MINIMALLY" = TRUE ]; then + if \[ "${OTEL_SHELL_CONFIG_INSTRUMENT_MINIMALLY:-FALSE}" = TRUE ]; then local non_internal_instrumentations="$(\alias | \grep OTEL_SHELL_SPAN_KIND_OVERRIDE | \grep -v OTEL_SHELL_SPAN_KIND_OVERRIDE=INTERNAL | \sed 's/^alias //g' | \cut -d = -f 1)" if \[ -n "$non_internal_instrumentations" ]; then \grep -F "$non_internal_instrumentations" @@ -280,7 +280,7 @@ _otel_alias_prepend() { fi while _otel_string_starts_with "$previous_command" "OTEL_"; do local previous_command="${previous_command#* }"; done local overrides="OTEL_SHELL_COMMAND_TYPE_OVERRIDE=$command_type" - if \[ -n "$span_kind" ]; then local overrides="$overrides OTEL_SHELL_SPAN_KIND_OVERRIDE=$span_kind"; fi + if \[ -n "${span_kind:-}" ]; then local overrides="$overrides OTEL_SHELL_SPAN_KIND_OVERRIDE=$span_kind"; fi local previous_otel_command="$(\printf '%s' "$previous_command" | _otel_line_split | \grep '^_otel_' | _otel_line_join)" local previous_alias_command="$(\printf '%s' "$previous_command" | _otel_line_split | \grep -v '^_otel_' | _otel_line_join)" case "$previous_alias_command" in @@ -438,13 +438,13 @@ _otel_inject() { _otel_start_script() { otel_init || return $? - if \[ -n "$SSH_CLIENT" ] && \[ -n "$SSH_CONNECTION" ] && \[ "$PPID" != 0 ] && \[ "$(\cat /proc/$PPID/cmdline | \tr -d '\000' | \cut -d ' ' -f 1)" = "sshd:" ]; then + if \[ -n "${SSH_CLIENT:-}" ] && \[ -n "${SSH_CONNECTION:-}" ] && \[ "${PPID:-}" != 0 ] && \[ "$(\cat /proc/$PPID/cmdline | \tr -d '\000' | \cut -d ' ' -f 1)" = "sshd:" ]; then _root_span_handle="$(otel_span_start SERVER ssh)" otel_span_attribute_typed $_root_span_handle string ssh.ip="$(\echo $SSH_CONNECTION | \cut -d ' ' -f 3)" otel_span_attribute_typed $_root_span_handle int ssh.port="$(\echo $SSH_CONNECTION | \cut -d ' ' -f 4)" otel_span_attribute_typed $_root_span_handle string network.peer.ip="$(\echo $SSH_CLIENT | \cut -d ' ' -f 1)" otel_span_attribute_typed $_root_span_handle int network.peer.port="$(\echo $SSH_CLIENT | \cut -d ' ' -f 2)" - elif \[ -n "$SERVER_SOFTWARE" ] && \[ -n "$SCRIPT_NAME" ] && \[ -n "$SERVER_NAME" ] && \[ -n "$SERVER_PROTOCOL" ] && ! \[ "$OTEL_SHELL_AUTO_INJECTED" = "TRUE" ] && \[ "$PPID" != 0 ] && \[ "$(\cat "/proc/$PPID/cmdline" | \tr '\000' ' ' | \cut -d ' ' -f 1 | \rev | \cut -d / -f 1 | \rev)" = "python3" ]; then + elif \[ -n "${SERVER_SOFTWARE:-}" ] && \[ -n "${SCRIPT_NAME:-}" ] && \[ -n "${SERVER_NAME:-}" ] && \[ -n "${SERVER_PROTOCOL:-}" ] && ! \[ "${OTEL_SHELL_AUTO_INJECTED:FALSE}" = "TRUE" ] && \[ "${PPID:-}" != 0 ] && \[ "$(\cat "/proc/$PPID/cmdline" | \tr '\000' ' ' | \cut -d ' ' -f 1 | \rev | \cut -d / -f 1 | \rev)" = "python3" ]; then _root_span_handle="$(otel_span_start SERVER GET)" otel_span_attribute_typed $_root_span_handle string network.protocol.name=http otel_span_attribute_typed $_root_span_handle string network.transport=tcp @@ -463,26 +463,26 @@ _otel_start_script() { _root_span_handle="$(otel_span_start SERVER "$(\echo "$cmdline" | \cut -d . -f 2- | \cut -d ' ' -f 1)")" otel_span_attribute_typed $_root_span_handle string debian.package.name="$(\echo "$cmdline" | \rev | \cut -d / -f 1 | \rev | \cut -d . -f 1)" otel_span_attribute_typed $_root_span_handle string debian.package.operation="$(\echo "$cmdline" | \cut -d . -f 2-)" - elif \[ "$GITHUB_ACTIONS" = true ] && \[ -n "$GITHUB_RUN_ID" ] && \[ -n "$GITHUB_WORKFLOW" ] && ( \[ "$OTEL_SHELL_IS_GITHUB_ACTION_ROOT" = TRUE ] || \[ "$PPID" != 0 ] && \[ "$(\cat /proc/$PPID/cmdline | \tr '\000-\037' ' ' | \cut -d ' ' -f 1 | \rev | \cut -d / -f 1 | \rev)" = "Runner.Worker" ] ); then + elif \[ "${GITHUB_ACTIONS:-false}" = true ] && \[ -n "${GITHUB_RUN_ID:-}" ] && \[ -n "${GITHUB_WORKFLOW:-}" ] && ( \[ "${OTEL_SHELL_IS_GITHUB_ACTION_ROOT:-FALSE}" = TRUE ] || \[ "${PPID:-}" != 0 ] && \[ "$(\cat /proc/$PPID/cmdline | \tr '\000-\037' ' ' | \cut -d ' ' -f 1 | \rev | \cut -d / -f 1 | \rev)" = "Runner.Worker" ] ); then unset OTEL_SHELL_IS_GITHUB_ACTION_ROOT local name="$GITHUB_WORKFLOW" local kind=CONSUMER - if \[ -n "$GITHUB_JOB" ]; then local name="$name / $GITHUB_JOB"; local kind=CONSUMER; fi - if \[ -n "$GITHUB_STEP" ]; then local name="$name / $GITHUB_STEP"; local kind=SERVER - elif \[ -n "$GITHUB_ACTION" ]; then local name="$name / $GITHUB_ACTION"; local kind=INTERNAL; fi + if \[ -n "${GITHUB_JOB:-}" ]; then local name="$name / $GITHUB_JOB"; local kind=CONSUMER; fi + if \[ -n "${GITHUB_STEP:-}" ]; then local name="$name / $GITHUB_STEP"; local kind=SERVER + elif \[ -n "${GITHUB_ACTION:-}" ]; then local name="$name / $GITHUB_ACTION"; local kind=INTERNAL; fi _root_span_handle="$(otel_span_start "$kind" "$name")" - elif ! \[ "$OTEL_SHELL_AUTO_INJECTED" = TRUE ] && \[ -z "$TRACEPARENT" ]; then + elif ! \[ "${OTEL_SHELL_AUTO_INJECTED:-FALSE}" = TRUE ] && \[ -z "${TRACEPARENT:-}" ]; then _root_span_handle="$(otel_span_start SERVER "$(_otel_command_self)")" - elif ! \[ "$OTEL_SHELL_AUTO_INJECTED" = TRUE ] && \[ -n "$TRACEPARENT" ]; then + elif ! \[ "${OTEL_SHELL_AUTO_INJECTED:-FALSE}" = TRUE ] && \[ -n "${TRACEPARENT:-}" ]; then _root_span_handle="$(otel_span_start INTERNAL "$(_otel_command_self)")" fi - if \[ -n "$_root_span_handle" ]; then otel_span_activate "$_root_span_handle"; fi + if \[ -n "${_root_span_handle:-}" ]; then otel_span_activate "$_root_span_handle"; fi unset OTEL_SHELL_AUTO_INJECTED } _otel_end_script() { local exit_code="$?" - if \[ -n "$_root_span_handle" ]; then + if \[ -n "${_root_span_handle:-}" ]; then if \[ "$exit_code" -ne 0 ]; then otel_span_error "$_root_span_handle" fi diff --git a/src/usr/share/opentelemetry_shell/api.observe.logs.sh b/src/usr/share/opentelemetry_shell/api.observe.logs.sh index 5b5f21673..0a9deaa98 100755 --- a/src/usr/share/opentelemetry_shell/api.observe.logs.sh +++ b/src/usr/share/opentelemetry_shell/api.observe.logs.sh @@ -10,7 +10,7 @@ _otel_call_and_record_logs() { local call_command="$1"; shift local traceparent="$TRACEPARENT" local stderr_logs="$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.stderr.logs.pipe" - \mkfifo $_otel_mkfifo_flags "$stderr_logs" + \mkfifo ${_otel_mkfifo_flags:-} "$stderr_logs" while IFS= \read -r line; do _otel_log_record "$traceparent" "$line"; \echo "$line" >&2; done < "$stderr_logs" & local stderr_pid="$!" local exit_code=0 diff --git a/src/usr/share/opentelemetry_shell/api.sh b/src/usr/share/opentelemetry_shell/api.sh index 04ff5b2fe..f747ee00b 100755 --- a/src/usr/share/opentelemetry_shell/api.sh +++ b/src/usr/share/opentelemetry_shell/api.sh @@ -6,10 +6,10 @@ ################################################################################################## # translate legacy config -if \[ -n "$OTEL_SHELL_TRACES_ENABLE" ] || \[ -n "$OTEL_SHELL_METRICS_ENABLE" ] || \[ -n "$OTEL_SHELL_LOGS_ENABLE" ]; then - \[ "$OTEL_SHELL_TRACES_ENABLE" = TRUE ] && export OTEL_TRACES_EXPORTER=otlp || export OTEL_TRACES_EXPORTER="" - \[ "$OTEL_SHELL_METRICS_ENABLE" = TRUE ] && export OTEL_METRICS_EXPORTER=otlp || export OTEL_METRICS_EXPORTER="" - \[ "$OTEL_SHELL_LOGS_ENABLE" = TRUE ] && export OTEL_LOGS_EXPORTER=otlp || export OTEL_LOGS_EXPORTER="" +if \[ -n "${OTEL_SHELL_TRACES_ENABLE:-}" ] || \[ -n "${OTEL_SHELL_METRICS_ENABLE:-}" ] || \[ -n "${OTEL_SHELL_LOGS_ENABLE:-}" ]; then + \[ "${OTEL_SHELL_TRACES_ENABLE:-FALSE}" = TRUE ] && export OTEL_TRACES_EXPORTER=otlp || export OTEL_TRACES_EXPORTER="" + \[ "${OTEL_SHELL_METRICS_ENABLE:-FALSE}" = TRUE ] && export OTEL_METRICS_EXPORTER=otlp || export OTEL_METRICS_EXPORTER="" + \[ "${OTEL_SHELL_LOGS_ENABLE:-FALSE}" = TRUE ] && export OTEL_LOGS_EXPORTER=otlp || export OTEL_LOGS_EXPORTER="" export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta fi @@ -19,14 +19,14 @@ case "$-" in esac # basic setup -if \[ -z "$TMPDIR" ]; then TMPDIR=/tmp; fi +if \[ -z "${TMPDIR:-}" ]; then TMPDIR=/tmp; fi _otel_shell_pipe_dir="${OTEL_SHELL_PIPE_DIR:-$TMPDIR}" _otel_remote_sdk_pipe="${OTEL_REMOTE_SDK_PIPE:-$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.pipe}" _otel_remote_sdk_fd="${OTEL_REMOTE_SDK_FD:-7}" _otel_shell="$(\readlink "/proc/$$/exe")" _otel_shell="${_otel_shell##*/}" if \[ "$_otel_shell" = busybox ]; then _otel_shell="busybox sh"; fi -if \[ "$OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE" = 0 ] || \[ "$OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE" = "$PPID" ] || \[ "$PPID" = 0 ] || \[ "$(\tr '\000-\037' ' ' < /proc/$PPID/cmdline)" = "$(\tr '\000-\037' ' ' < /proc/$OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE/cmdline)" ]; then _otel_commandline_override="$OTEL_SHELL_COMMANDLINE_OVERRIDE"; fi +if \[ "${OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE:-}" = 0 ] || \[ "${OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE:-}" = "$PPID" ] || \[ "${PPID:-}" = 0 ] || \[ "$(\tr '\000-\037' ' ' < /proc/$PPID/cmdline)" = "$(\tr '\000-\037' ' ' < /proc/${OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE:-}/cmdline)" ]; then _otel_commandline_override="$OTEL_SHELL_COMMANDLINE_OVERRIDE"; fi unset OTEL_SHELL_COMMANDLINE_OVERRIDE unset OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE unset OTEL_SHELL_COMMAND_TYPE_OVERRIDE @@ -50,7 +50,7 @@ else _otel_package_version "$_otel_shell" > /dev/null # several weird things going on in the next line, (1) using '((' fucks up the syntax highlighting in github while '( (' does not, and (2) &> causes weird buffering / late flushing behavior if \env --help 2>&1 | \grep -q 'ignore-signal'; then local extra_env_flags='--ignore-signal=INT --ignore-signal=HUP'; fi - ( (\env $extra_env_flags /opt/opentelemetry_shell/sdk/venv/bin/python /usr/share/opentelemetry_shell/sdk.py "shell" "$(_otel_package_version opentelemetry-shell)" < "$_otel_remote_sdk_pipe" 1> "$sdk_output" 2> "$sdk_output") &) + ( (\env ${extra_env_flags:-} /opt/opentelemetry_shell/sdk/venv/bin/python /usr/share/opentelemetry_shell/sdk.py "shell" "$(_otel_package_version opentelemetry-shell)" < "$_otel_remote_sdk_pipe" 1> "$sdk_output" 2> "$sdk_output") &) \eval "\\exec ${_otel_remote_sdk_fd}> \"$_otel_remote_sdk_pipe\"" _otel_resource_attributes _otel_sdk_communicate "INIT" @@ -107,9 +107,9 @@ _otel_resource_attributes() { _otel_resource_attribute string process.runtime.options="$-" _otel_resource_attribute string service.name="${OTEL_SERVICE_NAME:-unknown_service}" - _otel_resource_attribute string service.version="$OTEL_SERVICE_VERSION" - _otel_resource_attribute string service.namespace="$OTEL_SERVICE_NAMESPACE" - _otel_resource_attribute string service.instance.id="$OTEL_SERVICE_INSTANCE_ID" + _otel_resource_attribute string service.version="${OTEL_SERVICE_VERSION:-}" + _otel_resource_attribute string service.namespace="${OTEL_SERVICE_NAMESPACE:-}" + _otel_resource_attribute string service.instance.id="${OTEL_SERVICE_INSTANCE_ID:-}" } _otel_resource_attribute() { @@ -117,7 +117,7 @@ _otel_resource_attribute() { } _otel_command_self() { - if \[ -n "$_otel_commandline_override" ]; then + if \[ -n "${_otel_commandline_override:-}" ]; then \echo "$_otel_commandline_override" | \tr '\000-\037' ' ' else _otel_resolve_command_self @@ -134,7 +134,8 @@ if \[ "$_otel_shell" = bash ]; then local package_name="$1" local varname="OTEL_SHELL_PACKAGE_VERSION_CACHE_$package_name" local varname="${varname//-/_}" - if \[ -n "${!varname}" ]; then \echo "${!varname}"; return 0; fi + \eval "local varvalue=\${$varname:-}" + if \[ -n "$varvalue" ]; then \echo "$varvalue"; return 0; fi \export "$varname=$(_otel_resolve_package_version "$1")" \echo "${!varname}" } @@ -150,8 +151,8 @@ _otel_resolve_package_version() { otel_span_current() { local response_pipe="$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.span_handle.pipe" - \mkfifo $_otel_mkfifo_flags "$response_pipe" - _otel_sdk_communicate "SPAN_HANDLE" "$response_pipe" "$TRACEPARENT" + \mkfifo ${_otel_mkfifo_flags:-} "$response_pipe" + _otel_sdk_communicate "SPAN_HANDLE" "$response_pipe" "${TRACEPARENT:-}" \cat "$response_pipe" \rm "$response_pipe" 1> /dev/null 2> /dev/null } @@ -160,8 +161,8 @@ otel_span_start() { local kind="$1" local name="$2" local response_pipe="$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.span_handle.pipe" - \mkfifo $_otel_mkfifo_flags "$response_pipe" - _otel_sdk_communicate "SPAN_START" "$response_pipe" "$TRACEPARENT" "$TRACESTATE" "$kind" "$name" + \mkfifo ${_otel_mkfifo_flags:-} "$response_pipe" + _otel_sdk_communicate "SPAN_START" "$response_pipe" "${TRACEPARENT:-}" "${TRACESTATE:-}" "$kind" "$name" \cat "$response_pipe" \rm "$response_pipe" 1> /dev/null 2> /dev/null } @@ -198,7 +199,7 @@ otel_span_attribute_typed() { otel_span_traceparent() { local span_handle="$1" local response_pipe="$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.traceparent.pipe" - \mkfifo $_otel_mkfifo_flags "$response_pipe" + \mkfifo ${_otel_mkfifo_flags:-} "$response_pipe" _otel_sdk_communicate "SPAN_TRACEPARENT" "$response_pipe" "$span_handle" \cat "$response_pipe" \rm "$response_pipe" 1> /dev/null 2> /dev/null @@ -206,9 +207,9 @@ otel_span_traceparent() { otel_span_activate() { local span_handle="$1" - export TRACEPARENT_STACK="$TRACEPARENT/$TRACEPARENT_STACK" + export TRACEPARENT_STACK="${TRACEPARENT:-}/${TRACEPARENT_STACK:-}" export TRACEPARENT="$(otel_span_traceparent "$span_handle")" - if \[ -z "$TRACESTATE" ]; then export TRACESTATE=""; fi + if \[ -z "${TRACESTATE:-}" ]; then export TRACESTATE=""; fi } otel_span_deactivate() { @@ -229,7 +230,7 @@ otel_span_deactivate() { otel_event_create() { local event_name="$1" local response_pipe="$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.event_handle.pipe" - \mkfifo $_otel_mkfifo_flags "$response_pipe" + \mkfifo ${_otel_mkfifo_flags:-} "$response_pipe" _otel_sdk_communicate "EVENT_CREATE" "$response_pipe" "$event_name" \cat "$response_pipe" \rm "$response_pipe" 1> /dev/null 2> /dev/null @@ -258,7 +259,7 @@ otel_link_create() { local traceparent="$1" local tracestate="$2" local response_pipe="$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.link_handle.pipe" - \mkfifo $_otel_mkfifo_flags "$response_pipe" + \mkfifo ${_otel_mkfifo_flags:-} "$response_pipe" _otel_sdk_communicate "LINK_CREATE" "$response_pipe" "$traceparent" "$tracestate" END \cat "$response_pipe" \rm "$response_pipe" 1> /dev/null 2> /dev/null @@ -286,7 +287,7 @@ otel_link_add() { otel_metric_create() { local metric_name="$1" local response_pipe="$(\mktemp -u -p "$_otel_shell_pipe_dir")_opentelemetry_shell_$$.metric_handle.pipe" - \mkfifo $_otel_mkfifo_flags "$response_pipe" + \mkfifo ${_otel_mkfifo_flags:-} "$response_pipe" _otel_sdk_communicate "METRIC_CREATE" "$response_pipe" "$metric_name" \cat "$response_pipe" \rm "$response_pipe" 1> /dev/null 2> /dev/null @@ -320,8 +321,8 @@ otel_observe() { while _otel_string_starts_with "$command" "_otel_"; do local command="${command#* }"; done local command="${command#\\}" local kind="${OTEL_SHELL_SPAN_KIND_OVERRIDE:-INTERNAL}" - local attributes="$OTEL_SHELL_SPAN_ATTRIBUTES_OVERRIDE" - local command_type="$OTEL_SHELL_COMMAND_TYPE_OVERRIDE" + local attributes="${OTEL_SHELL_SPAN_ATTRIBUTES_OVERRIDE:-}" + local command_type="${OTEL_SHELL_COMMAND_TYPE_OVERRIDE:-}" unset OTEL_SHELL_SPAN_ATTRIBUTES_OVERRIDE unset OTEL_SHELL_COMMAND_TYPE_OVERRIDE @@ -329,7 +330,7 @@ otel_observe() { local span_handle="$(otel_span_start "$kind" "$command")" otel_span_attribute_typed "$span_handle" string shell.command_line="$command" if _otel_string_contains "$command" " "; then local command_name="${command%% *}"; else local command_name="$command"; fi # "$(\printf '%s' "$command" | \cut -sd ' ' -f 2-)" # this returns the command if there are no args, its the cut -s that cant be done via expansion alone - if \[ -z "$command_type" ]; then local command_type="$(_otel_command_type "$command_name")"; fi + if \[ -z "${command_type:-}" ]; then local command_type="$(_otel_command_type "$command_name")"; fi otel_span_attribute_typed "$span_handle" string shell.command="$command_name" otel_span_attribute_typed "$span_handle" string shell.command.type="$command_type" if _otel_string_contains "$command_name" /; then @@ -349,7 +350,7 @@ otel_observe() { local call_command=_otel_call if \[ "${OTEL_SHELL_CONFIG_OBSERVE_SUBPROCESSES:-FALSE}" = TRUE ] || \[ "${OTEL_SHELL_CONFIG_OBSERVE_SIGNALS:-FALSE}" = TRUE ]; then if ! _otel_string_starts_with "$1" _otel_ && \[ "$command_type" = file ] && \type strace 1> /dev/null 2> /dev/null; then local call_command="_otel_call_and_record_subprocesses $span_handle $call_command"; fi; fi if ! \[ -t 2 ] && ! _otel_string_contains "$-" x; then local call_command="_otel_call_and_record_logs $call_command"; fi - if ! \[ -t 0 ] && ! \[ -t 1 ] && ! \[ -t 2 ] && ! _otel_string_contains "$-" x && \[ "$OTEL_SHELL_CONFIG_OBSERVE_PIPES" = TRUE ]; then local call_command="_otel_call_and_record_pipes $span_handle $command_type $call_command"; fi + if ! \[ -t 0 ] && ! \[ -t 1 ] && ! \[ -t 2 ] && ! _otel_string_contains "$-" x && \[ "${OTEL_SHELL_CONFIG_OBSERVE_PIPES:-FALSE}" = TRUE ]; then local call_command="_otel_call_and_record_pipes $span_handle $command_type $call_command"; fi $call_command "$@" || local exit_code="$?" otel_span_deactivate "$span_handle" @@ -467,7 +468,7 @@ _otel_escape_arg() { esac fi if \[ "$do_escape" = 1 ]; then - if \[ "$no_quote" = 1 ]; then local format_string='%s'; else local format_string="'%s'"; fi + if \[ "${no_quote:-0}" = 1 ]; then local format_string='%s'; else local format_string="'%s'"; fi _otel_escape_arg_format "$format_string" "$1" else \printf '%s' "$1" diff --git a/tests/assert.sh b/tests/assert.sh index dfe6d4ce6..a539ad840 100755 --- a/tests/assert.sh +++ b/tests/assert.sh @@ -1,8 +1,8 @@ #!/bin/bash assert_equals() { - if [ "$1" != "$2" ]; then - \echo "ASSERT FAILED $1 != $2" 1>&2 + if [ "${1:-}" != "${2:-}" ]; then + \echo "ASSERT FAILED ${1:-} != ${2:-}" 1>&2 exit 1 fi } @@ -24,7 +24,7 @@ assert_ends_with() { } resolve_span() { - local selector="$1" + local selector="${1:-}" if [ -n "$selector" ]; then local selector=' | select('"$selector"')' fi diff --git a/tests/integration/test_integration__gitaptly.shell b/tests/integration/test_integration__gitaptly.shell index c4e30d08b..ac63ec743 100755 --- a/tests/integration/test_integration__gitaptly.shell +++ b/tests/integration/test_integration__gitaptly.shell @@ -2,8 +2,8 @@ if ! type sudo || ! type systemctl || ! type apt-get; then exit 0 fi -if [ -n "$GITHUB_TOKEN" ] && type debconf-set-selections; then - echo gitaptly gitaptly/GITHUB_API_TOKEN string $GITHUB_TOKEN | sudo debconf-set-selections +if [ -n "${GITHUB_TOKEN:-}" ] && type debconf-set-selections; then + echo gitaptly gitaptly/GITHUB_API_TOKEN string "$GITHUB_TOKEN" | sudo debconf-set-selections fi curl --fail --retry 16 --retry-all-errors https://api.github.com/repos/plengauer/abom-http/releases/latest | jq -r '.assets[].browser_download_url' | grep '.deb$' | xargs wget curl --fail --retry 16 --retry-all-errors https://api.github.com/repos/plengauer/gitaptly/releases/latest | jq -r '.assets[].browser_download_url' | grep '.deb$' | xargs wget \ diff --git a/tests/integration/test_integration_debconf_first.shell b/tests/integration/test_integration_debconf_first.shell index 8283151d0..e73c67363 100755 --- a/tests/integration/test_integration_debconf_first.shell +++ b/tests/integration/test_integration_debconf_first.shell @@ -1,5 +1,6 @@ . ./assert.sh if ! [ -f /usr/share/debconf/confmodule ]; then exit 0; fi +set +u . /usr/share/debconf/confmodule . /usr/bin/opentelemetry_shell.sh db_get $(debconf-show $(debconf-show --listowners | head -n1) | sed 's/^\* //' | sed 's/ //' | cut -d: -f1 | head -n1) diff --git a/tests/integration/test_integration_debconf_second.shell b/tests/integration/test_integration_debconf_second.shell index a09d1b87c..4f11aea7e 100755 --- a/tests/integration/test_integration_debconf_second.shell +++ b/tests/integration/test_integration_debconf_second.shell @@ -1,6 +1,7 @@ . ./assert.sh if ! [ -f /usr/share/debconf/confmodule ]; then exit 0; fi . /usr/bin/opentelemetry_shell.sh +set +u . /usr/share/debconf/confmodule db_get $(debconf-show $(debconf-show --listowners | head -n1) | sed 's/^\* //' | sed 's/ //' | cut -d: -f1 | head -n1) assert_equals 0 "$?" diff --git a/tests/run_tests.sh b/tests/run_tests.sh index b51f2f4ce..5fa276e6b 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -22,7 +22,7 @@ for dir in unit sdk auto integration; do ( while true; do cat $OTEL_SHELL_SDK_OUTPUT_REDIRECT >> $OTEL_EXPORT_LOCATION; done ) & echo "running $file" # export OTEL_SHELL_EXPERIMENTAL_OBSERVE_PIPES=TRUE - options='-f' + options='-u -f' if [ "$SHELL" = bash ]; then options="$options -p" fi diff --git a/tests/sdk/test_sdk_observe_exit.shell b/tests/sdk/test_sdk_observe_exit.shell index 2b930aa50..e96ef53db 100755 --- a/tests/sdk/test_sdk_observe_exit.shell +++ b/tests/sdk/test_sdk_observe_exit.shell @@ -5,11 +5,10 @@ otel_init func_fail() { return $1 } -otel_observe func_fail -func_fail 0 +otel_observe func_fail 0 assert_equals 0 $? -func_fail 1 +otel_observe func_fail 1 assert_equals 1 $? -func_fail 42 +otel_observe func_fail 42 assert_equals 42 $? otel_shutdown diff --git a/tests/sdk/test_sdk_traceparent.shell b/tests/sdk/test_sdk_traceparent.shell index 1ac33be0b..3eb433297 100755 --- a/tests/sdk/test_sdk_traceparent.shell +++ b/tests/sdk/test_sdk_traceparent.shell @@ -2,10 +2,10 @@ . /usr/bin/opentelemetry_shell_api.sh otel_init -assert_equals "" "$TRACEPARENT" +assert_equals "" "${TRACEPARENT:-}" span_id=$(otel_span_start INTERNAL myspan) -assert_equals "" "$TRACEPARENT" +assert_equals "" "${TRACEPARENT:-}" otel_span_activate $span_id traceparent=$TRACEPARENT @@ -22,6 +22,6 @@ assert_equals "$traceparent" "$TRACEPARENT" otel_span_deactivate $span_id otel_span_end $span_id -assert_equals "" "$TRACEPARENT" +assert_equals "" "${TRACEPARENT:-}" otel_shutdown