From b60c79ef5087818dcf178d9cfab0f6dbf6823429 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:06:20 +0100 Subject: [PATCH 01/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 7c0a9a71d..febce9bf8 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -23,7 +23,7 @@ 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. +set +h dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 From a349234d246d2a59ad7307ee2a8865a95c2235e9 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:06:42 +0100 Subject: [PATCH 02/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index febce9bf8..43938812d 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -23,7 +23,7 @@ requests.get("http://example.com/baz") ' > script.py python3 script.py | grep -v -F '"parent_id": null,' | grep -- '/baz' || exit 1 -set +h +set +h # TODO if this works, integrate it into the python injection dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 From ded0b5b0f3a5b68ef194cd871ac39b9c906de060 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:36:40 +0100 Subject: [PATCH 03/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 43938812d..7eb0bc82d 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -23,7 +23,7 @@ requests.get("http://example.com/baz") ' > script.py python3 script.py | grep -v -F '"parent_id": null,' | grep -- '/baz' || exit 1 -set +h # TODO if this works, integrate it into the python injection +if [ "$SHELL" = bash ]; then set +h; fi # TODO if this works, integrate it into the python injection dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 From 9b975f0bba70d7f60782537d9966c02bad73bb65 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:27:47 +0100 Subject: [PATCH 04/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 7eb0bc82d..550d0e59c 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -25,6 +25,8 @@ python3 script.py | grep -v -F '"parent_id": null,' | grep -- '/baz' || exit 1 if [ "$SHELL" = bash ]; then set +h; fi # TODO if this works, integrate it into the python injection +set +h + dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate From 48173b64a2bf141cee8f4e373535c2e35f14513e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:28:19 +0100 Subject: [PATCH 05/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 550d0e59c..d199595af 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -23,9 +23,7 @@ requests.get("http://example.com/baz") ' > script.py python3 script.py | grep -v -F '"parent_id": null,' | grep -- '/baz' || exit 1 -if [ "$SHELL" = bash ]; then set +h; fi # TODO if this works, integrate it into the python injection - -set +h +if [ "$SHELL" != bash ]; then set +h; fi # TODO if this works, integrate it into the python injection dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 From 6ea6138f6ab5647dd35520fbd9f3ccdde3fd63e1 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 25 Dec 2024 23:07:09 +0100 Subject: [PATCH 06/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index d199595af..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 -if [ "$SHELL" != bash ]; then set +h; fi # TODO if this works, integrate it into the python injection - dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate From 62d91f23af382281633f0a3cc3eecb8de3e18357 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 25 Dec 2024 23:09:25 +0100 Subject: [PATCH 07/15] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index 94f47e51b..17cf782b3 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -132,7 +132,6 @@ _otel_list_aliased_commands() { _otel_list_builtin_commands() { \echo printf - \echo type \echo printenv \echo cd \echo pwd @@ -142,7 +141,6 @@ _otel_list_builtin_commands() { if \[ "$_otel_shell" = "bash" ]; then \echo pushd \echo popd - \echo hash \echo history fi } From 28c5325704951be9a799c09cfbd0ed97ad615cd9 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:34:01 +0100 Subject: [PATCH 08/15] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index bf19751c0..e6eec85ad 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -329,7 +329,7 @@ _otel_unalias_and_reinstrument() { _otel_hash_and_reinstrument() { shift local exit_code=0 - \hash "$@" || local exit_code="$?" + \hash "$@" # || local exit_code="$?" if \[ "$1" = -r ]; then local aliases_pre="$(\mktemp)" local aliases_new="$(\mktemp)" From 88a989023c9beed65318e4f06cccc1494606f3b6 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 30 Dec 2024 19:35:25 +0100 Subject: [PATCH 09/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index dcb5a4678..5744eab33 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -25,7 +25,9 @@ python3 script.py | grep -v -F '"parent_id": null,' | grep -- '/baz' || exit 1 dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 +set -x . "$dir"/venv/bin/activate +set +x pip install requests echo ' import requests From 9f8e2539661984524515757dc91191304a01cd17 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 30 Dec 2024 22:37:19 +0100 Subject: [PATCH 10/15] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index e6eec85ad..505ee7e28 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -78,7 +78,11 @@ _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 + else + _otel_alias_prepend export _otel_export_PATH_and_reinstrument + fi _otel_alias_prepend . _otel_instrument_and_source if \[ "$_otel_shell" = bash ]; then _otel_alias_prepend source _otel_instrument_and_source; fi @@ -329,7 +333,7 @@ _otel_unalias_and_reinstrument() { _otel_hash_and_reinstrument() { shift local exit_code=0 - \hash "$@" # || local exit_code="$?" + \hash "$@" || local exit_code="$?" if \[ "$1" = -r ]; then local aliases_pre="$(\mktemp)" local aliases_new="$(\mktemp)" @@ -345,6 +349,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 From a23a8470c47181cf9af936d96786b7b3d8f06bdb Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 30 Dec 2024 22:41:20 +0100 Subject: [PATCH 11/15] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index 505ee7e28..6298d4f6f 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -379,11 +379,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 @@ -395,10 +395,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 "$@" @@ -434,7 +434,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() { From 3ed045fdbf215bd74ceb6b9240cb9d225c54ba31 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 30 Dec 2024 22:42:12 +0100 Subject: [PATCH 12/15] Update api.sh --- src/usr/share/opentelemetry_shell/api.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 From cab0c804e719de3ec2fa0222ee49dad87472636e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 30 Dec 2024 22:42:25 +0100 Subject: [PATCH 13/15] Update agent.instrumentation.renovate.sh --- .../agent.instrumentation.renovate.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 From e576a2adc59c105a7a7288d5d0246a4823c0c451 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:04:56 +0100 Subject: [PATCH 14/15] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index 6298d4f6f..e21f6933e 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -80,9 +80,8 @@ _otel_auto_instrument() { _otel_alias_prepend unalias _otel_unalias_and_reinstrument if \type hash 1> /dev/null 2> /dev/null; then _otel_alias_prepend hash _otel_hash_and_reinstrument - else - _otel_alias_prepend export _otel_export_PATH_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 From 85dbc77a81bdc6fd97e92b07da2e15e51ae24b9a Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 31 Dec 2024 00:50:56 +0100 Subject: [PATCH 15/15] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 5744eab33..dcb5a4678 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -25,9 +25,7 @@ python3 script.py | grep -v -F '"parent_id": null,' | grep -- '/baz' || exit 1 dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 -set -x . "$dir"/venv/bin/activate -set +x pip install requests echo ' import requests