diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh index 28a9ddbb9..a2d465981 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.renovate.sh @@ -1,17 +1,17 @@ #!/bin/false if _otel_string_contains "$(_otel_resolve_command_self)" /usr/local/bin/renovate || _otel_string_contains "$(_otel_resolve_command_self)" /usr/local/sbin/renovate; then # renovate looks at some very specific env vars to enable tracing - 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 + \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_ends_with "$OTEL_EXPORTER_OTLP_TRACES_ENDPOINT" /v1/traces; then - export OTEL_EXPORTER_OTLP_ENDPOINT="${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT%/v1/traces}" + \export OTEL_EXPORTER_OTLP_ENDPOINT="${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT%/v1/traces}" fi else - export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 + \export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 fi fi fi diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index bf19751c0..e21f6933e 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -78,7 +78,10 @@ _otel_auto_instrument() { # special instrumentations _otel_alias_prepend alias _otel_alias_and_instrument _otel_alias_prepend unalias _otel_unalias_and_reinstrument - _otel_alias_prepend hash _otel_hash_and_reinstrument + if \type hash 1> /dev/null 2> /dev/null; then + _otel_alias_prepend hash _otel_hash_and_reinstrument + fi + _otel_alias_prepend export _otel_export_PATH_and_reinstrument _otel_alias_prepend . _otel_instrument_and_source if \[ "$_otel_shell" = bash ]; then _otel_alias_prepend source _otel_instrument_and_source; fi @@ -345,6 +348,25 @@ _otel_hash_and_reinstrument() { return "$exit_code" } +_otel_export_PATH_and_reinstrument() { + shift + local exit_code=0 + \export "$@" || local exit_code="$?" + if \[ "$1" = PATH ] || _otel_string_starts_with "$1" PATH=; then + local aliases_pre="$(\mktemp)" + local aliases_new="$(\mktemp)" + \alias | \sed 's/^alias //' | \awk '{print "\\alias " $0 }' > "$aliases_pre" + \unalias -a + _otel_auto_instrument "$_otel_shell_auto_instrumentation_hint" + \alias | \sed 's/^alias //' | \awk '{print "\\alias " $0 }' > "$aliases_new" + \unalias -a + \. "$aliases_pre" + \. "$aliases_new" + \rm "$aliases_pre" "$aliases_new" + fi + return "$exit_code" +} + _otel_instrument_and_source() { local n="$1" shift @@ -356,11 +378,11 @@ _otel_instrument_and_source() { _otel_inject_and_exec_directly() { # this function assumes there is no fd fuckery if \[ "$#" = 1 ]; then - export OTEL_SHELL_CONSERVATIVE_EXEC=TRUE + \export OTEL_SHELL_CONSERVATIVE_EXEC=TRUE _otel_sdk_communicate 'SPAN_AUTO_END' if \[ -n "$_otel_commandline_override" ]; then - export OTEL_SHELL_COMMANDLINE_OVERRIDE="$_otel_commandline_override" - export OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="$PPID" + \export OTEL_SHELL_COMMANDLINE_OVERRIDE="$_otel_commandline_override" + \export OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="$PPID" fi \eval '"exec"' "$(\xargs -0 sh -c '. otelapi.sh; _otel_escape_args "$@"' sh < /proc/$$/cmdline)" fi @@ -372,10 +394,10 @@ _otel_inject_and_exec_directly() { # this function assumes there is no fd fucker otel_span_end "$span_id" _otel_sdk_communicate 'SPAN_AUTO_END' - export TRACEPARENT="$my_traceparent" - export OTEL_SHELL_AUTO_INJECTED=TRUE - export OTEL_SHELL_COMMANDLINE_OVERRIDE="$(_otel_command_self)" - export OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="$PPID" + \export TRACEPARENT="$my_traceparent" + \export OTEL_SHELL_AUTO_INJECTED=TRUE + \export OTEL_SHELL_COMMANDLINE_OVERRIDE="$(_otel_command_self)" + \export OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE="$PPID" shift \exec sh -c '. otel.sh eval "$(_otel_escape_args "$@")"' sh "$@" @@ -411,7 +433,7 @@ _otel_record_exec() { otel_span_deactivate "$span_id" otel_span_end "$span_id" _otel_sdk_communicate 'SPAN_AUTO_END' - export TRACEPARENT="$my_traceparent" + \export TRACEPARENT="$my_traceparent" } command() { diff --git a/src/usr/share/opentelemetry_shell/api.sh b/src/usr/share/opentelemetry_shell/api.sh index 04ff5b2fe..657830889 100755 --- a/src/usr/share/opentelemetry_shell/api.sh +++ b/src/usr/share/opentelemetry_shell/api.sh @@ -7,10 +7,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="" - export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta + \[ "$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="" + \export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta fi # check environment @@ -206,18 +206,18 @@ otel_span_traceparent() { otel_span_activate() { local span_handle="$1" - export TRACEPARENT_STACK="$TRACEPARENT/$TRACEPARENT_STACK" - export TRACEPARENT="$(otel_span_traceparent "$span_handle")" - if \[ -z "$TRACESTATE" ]; then export TRACESTATE=""; fi + \export TRACEPARENT_STACK="$TRACEPARENT/$TRACEPARENT_STACK" + \export TRACEPARENT="$(otel_span_traceparent "$span_handle")" + if \[ -z "$TRACESTATE" ]; then \export TRACESTATE=""; fi } otel_span_deactivate() { if _otel_string_contains "$TRACEPARENT_STACK" /; then - export TRACEPARENT="${TRACEPARENT_STACK%%/*}" - export TRACEPARENT_STACK="${TRACEPARENT_STACK#*/}" + \export TRACEPARENT="${TRACEPARENT_STACK%%/*}" + \export TRACEPARENT_STACK="${TRACEPARENT_STACK#*/}" else - export TRACEPARENT="$TRACEPARENT_STACK" - export TRACEPARENT_STACK="" + \export TRACEPARENT="$TRACEPARENT_STACK" + \export TRACEPARENT_STACK="" fi if \[ -z "$TRACEPARENT" ]; then unset TRACEPARENT_STACK diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 7c0a9a71d..dcb5a4678 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -23,8 +23,6 @@ requests.get("http://example.com/baz") ' > script.py python3 script.py | grep -v -F '"parent_id": null,' | grep -- '/baz' || exit 1 -\[ "$SHELL" = bash ] || exit 0 # TODO dashes on debian:stable (not oldstable, not testing or newer) seem to have a bug and not re-hash commands properly and therefore not reinstrument properly. - dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate