From 5617f559b6f5bfc172d9321a4885fbac71e2317b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:11:32 +0100 Subject: [PATCH 001/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 3dc7d8bab..1947978aa 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -9,34 +9,34 @@ new_context = propagator.extract(carrier=carrier) attach(new_context) -# import subprocess -# import functools -# -# def inject_arguments(*args): -# return [ '/bin/sh', '-c', '. otel.sh\n' + args[0] + ' "$@"', 'python' ] + args[1:] -# -# TODO get current span and set traceparent and tracestate as env var -# TODO set additional env var like auto injection, ... -# -# def observed_subprocess_run(original_subprocess_run, *args, **kwargs): -# if len(args) > 0: -# args = inject_arguments(args) -# return original_subprocess_run(*args, **kwargs) -# -# def observed_subprocess_call(original_subprocess_call, *args, **kwargs): -# if len(args) > 0: -# args = inject_arguments(args) -# return original_subprocess_call(*args, **kwargs) -# -# def observed_subprocess_Popen___init__(original_subprocess_call, *args, **kwargs): -# if len(args) > 0: -# args = inject_arguments(args) -# return observed_subprocess_Popen___init__(*args, **kwargs) -# -# def instrument(observed_function, original_function): -# # functools.update_wrapper(observed_function, original_function) # TODO why do we need this? -# return functools.partial(observed_function, original_function) -# -# subprocess.run = instrument(observed_subprocess_run, subprocess.run) -# subprocess.call = instrument(observed_subprocess_call, subprocess.call) -# subprocess.Popen.__init__ = instrument(observed_subprocess_Popen___init__, subprocess.Popen.__init__) +import subprocess +import functools + +def inject_arguments(*args): + return [ '/bin/sh', '-c', '. otel.sh\n' + args[0] + ' "$@"', 'python' ] + args[1:] + +TODO get current span and set traceparent and tracestate as env var +TODO set additional env var like auto injection, ... + +def observed_subprocess_run(original_subprocess_run, *args, **kwargs): + if len(args) > 0: + args = inject_arguments(args) + return original_subprocess_run(*args, **kwargs) + +def observed_subprocess_call(original_subprocess_call, *args, **kwargs): + if len(args) > 0: + args = inject_arguments(args) + return original_subprocess_call(*args, **kwargs) + +def observed_subprocess_Popen___init__(original_subprocess_call, *args, **kwargs): + if len(args) > 0: + args = inject_arguments(args) + return observed_subprocess_Popen___init__(*args, **kwargs) + +def instrument(observed_function, original_function): + # functools.update_wrapper(observed_function, original_function) # TODO why do we need this? + return functools.partial(observed_function, original_function) + +subprocess.run = instrument(observed_subprocess_run, subprocess.run) +subprocess.call = instrument(observed_subprocess_call, subprocess.call) +subprocess.Popen.__init__ = instrument(observed_subprocess_Popen___init__, subprocess.Popen.__init__) From c24e7a41f0a8dbdd576192621867e30ce13a1296 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:18:02 +0100 Subject: [PATCH 002/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 1947978aa..024124984 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -15,8 +15,8 @@ def inject_arguments(*args): return [ '/bin/sh', '-c', '. otel.sh\n' + args[0] + ' "$@"', 'python' ] + args[1:] -TODO get current span and set traceparent and tracestate as env var -TODO set additional env var like auto injection, ... +# TODO get current span and set traceparent and tracestate as env var +# TODO set additional env var like auto injection, ... def observed_subprocess_run(original_subprocess_run, *args, **kwargs): if len(args) > 0: From 1147e745da1a86f092acd9e90cd176211965f9de Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 4 Jan 2025 16:56:06 +0100 Subject: [PATCH 003/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 62 ++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 7c0a9a71d..eff4db4b5 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,10 +3,68 @@ if ! which python3; then exit 0; fi . otel.sh -#TODO test subprocesses - export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE +echo ' +import os +os.execl('/bin/echo', 'echo', 'hello', 'world', '0') +' | python3 +echo ' +import os +os.execv('/bin/echo', [ 'echo', 'hello', 'world', '1' ]) +' | python3 + +echo ' +import os +os.spawnl(os.P_WAIT, '/bin/echo', 'echo', 'hello', 'world', '2') +' | python3 +echo ' +import os +os.spawnlp(os.P_WAIT, 'echo', 'echo', 'hello', 'world', '3') +' | python3 +echo ' +import os +os.spawnv(os.P_WAIT, '/bin/echo', ['echo', 'hello', 'world', '4']) +' | python3 +echo ' +import os +os.spawnvp(os.P_WAIT, 'echo', ['echo', 'hello', 'world', '5']) +' | python3 + + +echo ' +import subprocess +subprocess.run(['echo', 'hello', 'world', '6']) +' | python3 +echo ' +import subprocess +subprocess.run('echo "hello" "world" "7"', shell=True) +' | python3 + + +printf '%s' ' +import subprocess +with subprocess.Popen(['echo', 'hello', 'world', '8'], stdout=subprocess.DEVNULL) as proc: + pass +' | python3 +printf '%s' ' +import subprocess +with subprocess.Popen(['echo', 'hello', 'world', '9'], stdout=subprocess.DEVNULL) as proc: + pass +' | python3 + + + + + + + + + + + + + echo ' import requests requests.get("http://example.com/foo") From c4264a7ac02de1cb88171ac28d2915453a72f60b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 4 Jan 2025 20:34:34 +0100 Subject: [PATCH 004/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index eff4db4b5..d87b48572 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -9,6 +9,11 @@ echo ' import os os.execl('/bin/echo', 'echo', 'hello', 'world', '0') ' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 0"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') + echo ' import os os.execv('/bin/echo', [ 'echo', 'hello', 'world', '1' ]) From 3d6f8aea8d8770bca9222b633b9633100be6f837 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:25:12 +0100 Subject: [PATCH 005/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 024124984..fb6859d2b 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -1,4 +1,4 @@ -import os +import opentelemetry from opentelemetry.context import attach from opentelemetry.trace.propagation import tracecontext @@ -9,34 +9,34 @@ new_context = propagator.extract(carrier=carrier) attach(new_context) -import subprocess +import os import functools -def inject_arguments(*args): - return [ '/bin/sh', '-c', '. otel.sh\n' + args[0] + ' "$@"', 'python' ] + args[1:] +inject_file(file): + return '/bin/sh' -# TODO get current span and set traceparent and tracestate as env var -# TODO set additional env var like auto injection, ... +inject_arguments(file, args): + return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] -def observed_subprocess_run(original_subprocess_run, *args, **kwargs): - if len(args) > 0: - args = inject_arguments(args) - return original_subprocess_run(*args, **kwargs) +inject_env(env): + if not env: + env = os.environ.copy() + carrier = {} + tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) + if 'traceparent' in carrier + env["OTEL_TRACEPARENT"] = carrier['traceparent'] + if 'tracestate' in carrier + env["OTEL_TRACESTATE"] = carrier['tracestate'] + return env; -def observed_subprocess_call(original_subprocess_call, *args, **kwargs): - if len(args) > 0: - args = inject_arguments(args) - return original_subprocess_call(*args, **kwargs) +def observed_os_execvp(original_os_execvpe, file, args): + return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) -def observed_subprocess_Popen___init__(original_subprocess_call, *args, **kwargs): - if len(args) > 0: - args = inject_arguments(args) - return observed_subprocess_Popen___init__(*args, **kwargs) +def observed_os_execvpe(original_os_execvpe, file, args, env): + return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) def instrument(observed_function, original_function): - # functools.update_wrapper(observed_function, original_function) # TODO why do we need this? return functools.partial(observed_function, original_function) -subprocess.run = instrument(observed_subprocess_run, subprocess.run) -subprocess.call = instrument(observed_subprocess_call, subprocess.call) -subprocess.Popen.__init__ = instrument(observed_subprocess_Popen___init__, subprocess.Popen.__init__) +os.execvp = instrument(observed_os_execvp, os.execvpe) +os.execvpe = instrument(observed_os_execvpe, os.execvpe) From c85f655b902e140bbac07b11ac14e99ca7f72b1a Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:26:57 +0100 Subject: [PATCH 006/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 55 +++++++++++++++------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index d87b48572..0095391ba 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -18,57 +18,84 @@ echo ' import os os.execv('/bin/echo', [ 'echo', 'hello', 'world', '1' ]) ' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 1"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os os.spawnl(os.P_WAIT, '/bin/echo', 'echo', 'hello', 'world', '2') ' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 2"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') + echo ' import os os.spawnlp(os.P_WAIT, 'echo', 'echo', 'hello', 'world', '3') ' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 3"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') + echo ' import os os.spawnv(os.P_WAIT, '/bin/echo', ['echo', 'hello', 'world', '4']) ' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 4"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') + echo ' import os os.spawnvp(os.P_WAIT, 'echo', ['echo', 'hello', 'world', '5']) ' | python3 - +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 5"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import subprocess subprocess.run(['echo', 'hello', 'world', '6']) ' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 6"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') + echo ' import subprocess subprocess.run('echo "hello" "world" "7"', shell=True) ' | python3 - +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 7"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') printf '%s' ' import subprocess with subprocess.Popen(['echo', 'hello', 'world', '8'], stdout=subprocess.DEVNULL) as proc: pass ' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 8"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') + printf '%s' ' import subprocess with subprocess.Popen(['echo', 'hello', 'world', '9'], stdout=subprocess.DEVNULL) as proc: pass ' | python3 - - - - - - - - - - - - +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 9"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import requests From 747067c791aa87b4aaaa694f8afe6cccb52ca571 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Mon, 6 Jan 2025 16:55:45 +0100 Subject: [PATCH 007/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 0095391ba..db7a1eb39 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -7,7 +7,7 @@ export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE echo ' import os -os.execl('/bin/echo', 'echo', 'hello', 'world', '0') +os.execl("/bin/echo", "echo", "hello", "world", "0") ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 0"')" @@ -16,7 +16,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os -os.execv('/bin/echo', [ 'echo', 'hello', 'world', '1' ]) +os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 1"')" @@ -25,7 +25,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os -os.spawnl(os.P_WAIT, '/bin/echo', 'echo', 'hello', 'world', '2') +os.spawnl(os.P_WAIT, "/bin/echo", "echo", "hello", "world", "2") ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 2"')" @@ -34,7 +34,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os -os.spawnlp(os.P_WAIT, 'echo', 'echo', 'hello', 'world', '3') +os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 3"')" @@ -43,7 +43,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os -os.spawnv(os.P_WAIT, '/bin/echo', ['echo', 'hello', 'world', '4']) +os.spawnv(os.P_WAIT, "/bin/echo", ["echo", "hello", "world", "4"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 4"')" @@ -52,7 +52,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os -os.spawnvp(os.P_WAIT, 'echo', ['echo', 'hello', 'world', '5']) +os.spawnvp(os.P_WAIT, "echo", ["echo", "hello", "world", "5"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 5"')" @@ -61,7 +61,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import subprocess -subprocess.run(['echo', 'hello', 'world', '6']) +subprocess.run(["echo", "hello", "world", "6"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 6"')" @@ -70,7 +70,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import subprocess -subprocess.run('echo "hello" "world" "7"', shell=True) +subprocess.run("echo hello world 7", shell=True) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 7"')" @@ -79,7 +79,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') printf '%s' ' import subprocess -with subprocess.Popen(['echo', 'hello', 'world', '8'], stdout=subprocess.DEVNULL) as proc: +with subprocess.Popen(["echo", "hello", "world", "8"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 assert_equals 0 $? @@ -89,7 +89,7 @@ assert_not_equals null $(\echo "$span" | jq -r '.parent_id') printf '%s' ' import subprocess -with subprocess.Popen(['echo', 'hello', 'world', '9'], stdout=subprocess.DEVNULL) as proc: +with subprocess.Popen(["echo", "hello", "world", "9"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 assert_equals 0 $? From e4bac092fa8880fd5723ea0debaf8d587e1ffc65 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 09:54:38 +0100 Subject: [PATCH 008/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index fb6859d2b..d83b60d90 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -12,27 +12,29 @@ import os import functools -inject_file(file): +def inject_file(file): return '/bin/sh' -inject_arguments(file, args): +def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] -inject_env(env): +def inject_env(env): if not env: env = os.environ.copy() carrier = {} tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) - if 'traceparent' in carrier + if 'traceparent' in carrier: env["OTEL_TRACEPARENT"] = carrier['traceparent'] - if 'tracestate' in carrier + if 'tracestate' in carrier: env["OTEL_TRACESTATE"] = carrier['tracestate'] return env; def observed_os_execvp(original_os_execvpe, file, args): + print('EXECVP: ' + file + ' ' + ','.join(args), file=sys.stderr); return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execvpe(original_os_execvpe, file, args, env): + print('EXECVPE: ' + file + ' ' + ','.join(args), file=sys.stderr); return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) def instrument(observed_function, original_function): From 58400e4ec434ca767b943a65c8b2b885e598081e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:11:18 +0100 Subject: [PATCH 009/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index db7a1eb39..1d8b4bd69 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -5,14 +5,14 @@ if ! which python3; then exit 0; fi export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE -echo ' -import os -os.execl("/bin/echo", "echo", "hello", "world", "0") -' | python3 -assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 0"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +# echo ' +# import os +# os.execl("/bin/echo", "echo", "hello", "world", "0") +# ' | python3 +# assert_equals 0 $? +# span="$(resolve_span '.name == "echo hello world 0"')" +# assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +# assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os From 3340f04ffe57394fc0ac73184cb4edbad32df8be Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:25:43 +0100 Subject: [PATCH 010/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 1d8b4bd69..d1bbf362e 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -14,14 +14,14 @@ export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE # assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') # assert_not_equals null $(\echo "$span" | jq -r '.parent_id') -echo ' -import os -os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) -' | python3 -assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 1"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +# echo ' +# import os +# os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) +# ' | python3 +# assert_equals 0 $? +# span="$(resolve_span '.name == "echo hello world 1"')" +# assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +# assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os From 52d71c4a8504cdefaa7587c88245137cc06c322b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:44:11 +0100 Subject: [PATCH 011/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index d83b60d90..b4fab75a2 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -29,16 +29,16 @@ def inject_env(env): env["OTEL_TRACESTATE"] = carrier['tracestate'] return env; -def observed_os_execvp(original_os_execvpe, file, args): - print('EXECVP: ' + file + ' ' + ','.join(args), file=sys.stderr); - return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) +def observed_os_execv(original_os_execve, file, args): + print('EXECV: ' + file + ' ' + ','.join(args), file=sys.stderr); + return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) -def observed_os_execvpe(original_os_execvpe, file, args, env): - print('EXECVPE: ' + file + ' ' + ','.join(args), file=sys.stderr); - return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) +def observed_os_execve(original_os_execve, file, args, env): + print('EXECVE: ' + file + ' ' + ','.join(args), file=sys.stderr); + return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) -os.execvp = instrument(observed_os_execvp, os.execvpe) -os.execvpe = instrument(observed_os_execvpe, os.execvpe) +os.execv = instrument(observed_os_execv, os.execve) +os.execve = instrument(observed_os_execve, os.execve) From 9a9727be48de35d12dc8cd809c63048821c54bda Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:56:32 +0100 Subject: [PATCH 012/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index d1bbf362e..db7a1eb39 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -5,23 +5,23 @@ if ! which python3; then exit 0; fi export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE -# echo ' -# import os -# os.execl("/bin/echo", "echo", "hello", "world", "0") -# ' | python3 -# assert_equals 0 $? -# span="$(resolve_span '.name == "echo hello world 0"')" -# assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -# assert_not_equals null $(\echo "$span" | jq -r '.parent_id') - -# echo ' -# import os -# os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) -# ' | python3 -# assert_equals 0 $? -# span="$(resolve_span '.name == "echo hello world 1"')" -# assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -# assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +echo ' +import os +os.execl("/bin/echo", "echo", "hello", "world", "0") +' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 0"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') + +echo ' +import os +os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) +' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 1"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') +assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os From f5179f75cd057229bab62e8b3df4a961a8180fc8 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:15:09 +0100 Subject: [PATCH 013/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index db7a1eb39..7b353261e 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -7,19 +7,19 @@ export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE echo ' import os -os.execl("/bin/echo", "echo", "hello", "world", "0") +os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 0"')" +span="$(resolve_span '.name == "echo hello world 1"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') assert_not_equals null $(\echo "$span" | jq -r '.parent_id') echo ' import os -os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) +os.execl("/bin/echo", "echo", "hello", "world", "0") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 1"')" +span="$(resolve_span '.name == "echo hello world 0"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') assert_not_equals null $(\echo "$span" | jq -r '.parent_id') From f73968dd4017274f266498c2af285a9e499c3361 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:30:12 +0100 Subject: [PATCH 014/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index b4fab75a2..fa44e11e9 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -30,15 +30,21 @@ def inject_env(env): return env; def observed_os_execv(original_os_execve, file, args): - print('EXECV: ' + file + ' ' + ','.join(args), file=sys.stderr); return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('EXECVE: ' + file + ' ' + ','.join(args), file=sys.stderr); return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) +def observed_os_execvp(original_os_execvp, file, args): + return original_os_execvp(inject_file(file), inject_arguments(file, args), inject_env(None)) + +def observed_os_execvpe(original_os_execvpe, file, args, env): + return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) + def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) os.execv = instrument(observed_os_execv, os.execve) os.execve = instrument(observed_os_execve, os.execve) +os.execvp = instrument(observed_os_execvp, os.execvp) +os.execvpe = instrument(observed_os_execvpe, os.execvpe) From 051eeb0c2197e557f96dde7d6b9ae98a01b3ded9 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:34:56 +0100 Subject: [PATCH 015/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index fa44e11e9..58b0bc2be 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -35,8 +35,8 @@ def observed_os_execv(original_os_execve, file, args): def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -def observed_os_execvp(original_os_execvp, file, args): - return original_os_execvp(inject_file(file), inject_arguments(file, args), inject_env(None)) +def observed_os_execvp(original_os_execvpe, file, args): + return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execvpe(original_os_execvpe, file, args, env): return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) @@ -46,5 +46,5 @@ def instrument(observed_function, original_function): os.execv = instrument(observed_os_execv, os.execve) os.execve = instrument(observed_os_execve, os.execve) -os.execvp = instrument(observed_os_execvp, os.execvp) +os.execvp = instrument(observed_os_execvp, os.execvpe) os.execvpe = instrument(observed_os_execvpe, os.execvpe) From 54098a8b15d59bc1f57880c1f6527508aa168f53 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:43:08 +0100 Subject: [PATCH 016/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 58b0bc2be..609cb4eff 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -48,3 +48,4 @@ def instrument(observed_function, original_function): os.execve = instrument(observed_os_execve, os.execve) os.execvp = instrument(observed_os_execvp, os.execvpe) os.execvpe = instrument(observed_os_execvpe, os.execvpe) +print('INSTRUMENTED', file=sys.stderr) From ab8b7a8941cf34d796b2a5e9b7369589ab02a968 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 11:57:12 +0100 Subject: [PATCH 017/162] Update agent.instrumentation.python.sh --- .../opentelemetry_shell/agent.instrumentation.python.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 2ce9f2cdb..7e1d5d945 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -1,9 +1,9 @@ #!/bin/false _otel_inject_python() { + local cmdline="$(_otel_dollar_star "$@")" + local cmdline="${cmdline#\\}" 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#\\}" "$@" @@ -20,7 +20,7 @@ _otel_inject_python() { fi fi else - _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_call "$@" fi } From 588f2da1ad7d2d71f538b51d5515a9b39a7342f8 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 12:31:02 +0100 Subject: [PATCH 018/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 609cb4eff..35105059c 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -1,13 +1,31 @@ -import opentelemetry -from opentelemetry.context import attach -from opentelemetry.trace.propagation import tracecontext - -traceparent = os.getenv("TRACEPARENT") -if traceparent: - propagator = tracecontext.TraceContextTextMapPropagator() - carrier = { "traceparent": traceparent } - new_context = propagator.extract(carrier=carrier) - attach(new_context) +try: + import opentelemetry + from opentelemetry.context import attach + from opentelemetry.trace.propagation import tracecontext + + traceparent = os.getenv("TRACEPARENT") + if traceparent: + propagator = tracecontext.TraceContextTextMapPropagator() + carrier = { "traceparent": traceparent } + new_context = propagator.extract(carrier=carrier) + attach(new_context) + + def inject_env(env): + if not env: + env = os.environ.copy() + carrier = {} + tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) + if 'traceparent' in carrier: + env["OTEL_TRACEPARENT"] = carrier["traceparent"] + if 'tracestate' in carrier: + env["OTEL_TRACESTATE"] = carrier["tracestate"] + return env; + +except ModuleNotFoundError: + def inject_env(env): + if not env: + env = os.environ.copy() + return env import os import functools @@ -18,34 +36,23 @@ def inject_file(file): def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] -def inject_env(env): - if not env: - env = os.environ.copy() - carrier = {} - tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) - if 'traceparent' in carrier: - env["OTEL_TRACEPARENT"] = carrier['traceparent'] - if 'tracestate' in carrier: - env["OTEL_TRACESTATE"] = carrier['tracestate'] - return env; - def observed_os_execv(original_os_execve, file, args): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -def observed_os_execvp(original_os_execvpe, file, args): - return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) +# def observed_os_execvp(original_os_execvpe, file, args): +# return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) -def observed_os_execvpe(original_os_execvpe, file, args, env): - return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) +# def observed_os_execvpe(original_os_execvpe, file, args, env): +# return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) os.execv = instrument(observed_os_execv, os.execve) os.execve = instrument(observed_os_execve, os.execve) -os.execvp = instrument(observed_os_execvp, os.execvpe) -os.execvpe = instrument(observed_os_execvpe, os.execvpe) +# os.execvp = instrument(observed_os_execvp, os.execvpe) +# os.execvpe = instrument(observed_os_execvpe, os.execvpe) print('INSTRUMENTED', file=sys.stderr) From 16409db542ba13df589571e57f12871cff256811 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 12:57:06 +0100 Subject: [PATCH 019/162] Update agent.instrumentation.python.sh --- .../agent.instrumentation.python.sh | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 7e1d5d945..9f6a295bf 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -1,26 +1,30 @@ #!/bin/false _otel_inject_python() { - local cmdline="$(_otel_dollar_star "$@")" - local cmdline="${cmdline#\\}" - 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 - 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 "$@" - 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 - 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 "$@" - else + if _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_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] + 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 "$@" + 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 + 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 "$@" + 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 "$@" + fi fi + 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_call "$@" fi 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_call "$@" + _otel_call "$@" fi } From 42d40f457952e0c9ba9b62e16a66c0a25db4701b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:16:10 +0100 Subject: [PATCH 020/162] Update agent.instrumentation.python.sh --- .../agent.instrumentation.python.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 9f6a295bf..23e410253 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -4,22 +4,23 @@ _otel_inject_python() { if _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_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] 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 "$@" + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + local command="$1"; shift + set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" + fi 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_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + local command="$1"; shift + set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" + fi 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 "$@" 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 "$@" fi - fi 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_call "$@" fi From 4b52c831c34ff028fbcc6c81bb1ac08f40960d64 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:18:16 +0100 Subject: [PATCH 021/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 23e410253..a954a0d90 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -37,9 +37,6 @@ _otel_inject_opentelemetry_instrument() { 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 - 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 "$@" - fi else _otel_call "$@" fi From d9a7d7eb27eed58eb18fd28705725112ce8c6be0 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:28:25 +0100 Subject: [PATCH 022/162] Update agent.instrumentation.python.sh --- .../agent.instrumentation.python.sh | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index a954a0d90..a2f31d3e5 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -4,25 +4,24 @@ _otel_inject_python() { if _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 - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then - local command="$1"; shift - set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" - fi 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 "$@")" - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then - local command="$1"; shift - set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" - fi - 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 "$@" - 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 "$@" - fi + if _otel_python_is_customize_injectable; then + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + local command="$1"; shift + set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" + fi + 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_call "$@" + \eval "set -- $(_otel_python_inject_args "$@")" + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + local command="$1"; shift + set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" + fi + 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 "$@" + 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 "$@" + fi fi else _otel_call "$@" From 0c965d0c90effc78d3e72b9e91996b80f5408007 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:32:49 +0100 Subject: [PATCH 023/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index a2f31d3e5..526a40b9d 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -5,14 +5,14 @@ _otel_inject_python() { local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" if _otel_python_is_customize_injectable; then - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] && \[ -d "/opt/opentelemetry_shell/venv" ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi 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 "$@")" - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] && \[ -d "/opt/opentelemetry_shell/venv" ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi From 21aa8e9de128926349b3db2cb4b545fd3a5bbc66 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:39:41 +0100 Subject: [PATCH 024/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 526a40b9d..66659fa83 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -36,6 +36,9 @@ _otel_inject_opentelemetry_instrument() { 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 + 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 "$@" + fi else _otel_call "$@" fi From 9d0b095ebe92c88be9d2ae395c086735d4807744 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:05:19 +0100 Subject: [PATCH 025/162] Update agent.instrumentation.python.sh --- .../opentelemetry_shell/agent.instrumentation.python.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 66659fa83..5a55e7060 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -1,18 +1,18 @@ #!/bin/false _otel_inject_python() { - if _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 \[ -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 - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] && \[ -d "/opt/opentelemetry_shell/venv" ]; then + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi 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 "$@")" - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ] && \[ -d "/opt/opentelemetry_shell/venv" ]; then + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi From 7c3de108bedeb2d20b998e4ffbcb37136b4d2dce Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:39:32 +0100 Subject: [PATCH 026/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 7b353261e..e93bb93c0 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,8 +3,6 @@ if ! which python3; then exit 0; fi . otel.sh -export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE - echo ' import os os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) @@ -97,6 +95,8 @@ span="$(resolve_span '.name == "echo hello world 9"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE + echo ' import requests requests.get("http://example.com/foo") From 6b3e275c076dad8dca41340cd33783b76d4f0d11 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:56:32 +0100 Subject: [PATCH 027/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 5a55e7060..fcd9c1016 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -4,7 +4,7 @@ _otel_inject_python() { if \[ -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 + if _otel_python_is_customize_injectable && \false; then if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" From 1ca45cfa176611aee2ef4b2d93c7725c4acb0f5a Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:16:36 +0100 Subject: [PATCH 028/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index e93bb93c0..771ba44ce 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,10 +3,12 @@ if ! which python3; then exit 0; fi . otel.sh -echo ' +set -s +\echo ' import os os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 +set +x assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 1"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') From 08ecc0490ec0c8d20c9d372b44b7c684f88015e7 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:26:31 +0100 Subject: [PATCH 029/162] 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 771ba44ce..36b520e18 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,7 +3,7 @@ if ! which python3; then exit 0; fi . otel.sh -set -s +set -x \echo ' import os os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) From 8c822daeb92e6152f58d7bbf46306d0ef6fd5ccc Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:41:42 +0100 Subject: [PATCH 030/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index fcd9c1016..f41cd7fee 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -11,6 +11,7 @@ _otel_inject_python() { fi 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_python_inject_args "$@" > /dev/null \eval "set -- $(_otel_python_inject_args "$@")" if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift From d7eb502c85fef7fe08e12a4d16ea270d29665d12 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:54:48 +0100 Subject: [PATCH 031/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 35105059c..8fee6753d 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -1,3 +1,5 @@ +import os + try: import opentelemetry from opentelemetry.context import attach @@ -27,7 +29,6 @@ def inject_env(env): env = os.environ.copy() return env -import os import functools def inject_file(file): From 03c4e11b3cf688c46e1a26b66c6ceda7dbf357ae Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:09:24 +0100 Subject: [PATCH 032/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 8fee6753d..92633f05a 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -1,3 +1,4 @@ +import sys import os try: From 5c7c1bc40b1b3b253d02691acf668c9c4f6d3c81 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:22:55 +0100 Subject: [PATCH 033/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 92633f05a..fcd980bad 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -39,10 +39,12 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) + print('os.execv', file=sys.stderr) + return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) + print('os.execve', file=sys.stderr) + return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): # return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) From 329a82ef35f93c6e51f4d9e1624ea075737c575e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:23:16 +0100 Subject: [PATCH 034/162] 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 36b520e18..047316a27 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,12 +3,10 @@ if ! which python3; then exit 0; fi . otel.sh -set -x \echo ' import os os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 -set +x assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 1"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') From 3b3a9fa484f114fee58ec94d88160fa19ae6303f Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:35:43 +0100 Subject: [PATCH 035/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index fcd980bad..a946579d2 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -36,7 +36,7 @@ def inject_file(file): return '/bin/sh' def inject_arguments(file, args): - return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] + return [ args[0], '-x', '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): print('os.execv', file=sys.stderr) From 76414cec320a292672fe21ff92be52c4a4707913 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:59:56 +0100 Subject: [PATCH 036/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index a946579d2..7172316be 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -36,14 +36,14 @@ def inject_file(file): return '/bin/sh' def inject_arguments(file, args): - return [ args[0], '-x', '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] + return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - print('os.execv', file=sys.stderr) + print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_args(args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execve', file=sys.stderr) + print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_args(args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From b88c968ae9b88ea57d9c459e39c095a3c1a4f571 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:13:35 +0100 Subject: [PATCH 037/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 7172316be..56c0ef1d8 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -39,11 +39,11 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_args(args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_args(args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From 844334737eb3c8cadd43aafed86c125a7e8d4abc Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:25:07 +0100 Subject: [PATCH 038/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 56c0ef1d8..aa734c08b 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -39,11 +39,11 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From ad975d36908cde14c09809d3f9092b6e1324daa7 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:37:44 +0100 Subject: [PATCH 039/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index aa734c08b..b86f3d924 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -36,7 +36,7 @@ def inject_file(file): return '/bin/sh' def inject_arguments(file, args): - return [ args[0], '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args[1:] + return [ args[0], '-c', '. otel.sh\n_otel_inject "' + file + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) From 4e02c22688f86ad9d2ea4e3f221bfff999843c6b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:55:53 +0100 Subject: [PATCH 040/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index b86f3d924..ee15a47c7 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -39,11 +39,11 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n_otel_inject "' + file + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + # print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + # print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): @@ -59,4 +59,4 @@ def instrument(observed_function, original_function): os.execve = instrument(observed_os_execve, os.execve) # os.execvp = instrument(observed_os_execvp, os.execvpe) # os.execvpe = instrument(observed_os_execvpe, os.execvpe) -print('INSTRUMENTED', file=sys.stderr) +# print('INSTRUMENTED', file=sys.stderr) From 8952c97a4b88408d814801f9df4a517b2467398e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:52:42 +0100 Subject: [PATCH 041/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index ee15a47c7..a74831b28 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -39,11 +39,11 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n_otel_inject "' + file + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - # print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + print('os.execv(' + str(file) + ', ' + str(args) + ') => os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - # print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + print('os.execv(' + str(file) + ', ' + str(args) + ', ' + str(env) + ') => os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From a5e7d62e133681768d2938457a7d46709df86ad2 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:53:25 +0100 Subject: [PATCH 042/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index a74831b28..79a6046e1 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -39,11 +39,13 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n_otel_inject "' + file + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - print('os.execv(' + str(file) + ', ' + str(args) + ') => os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) + print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execv(' + str(file) + ', ' + str(args) + ', ' + str(env) + ') => os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + print('os.execv(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) + print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From e4900fbd3ae4eea4e6056d6f1fe85c26a07a945e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:11:34 +0100 Subject: [PATCH 043/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 79a6046e1..7329215a9 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -36,6 +36,8 @@ def inject_file(file): return '/bin/sh' def inject_arguments(file, args): + if type(args) is tuple: + args = list(args) return [ args[0], '-c', '. otel.sh\n_otel_inject "' + file + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): From 189694d647b0ed9724d7362a23e95d0f03856454 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:35:49 +0100 Subject: [PATCH 044/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 7329215a9..0698c7955 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -12,7 +12,7 @@ carrier = { "traceparent": traceparent } new_context = propagator.extract(carrier=carrier) attach(new_context) - + def inject_env(env): if not env: env = os.environ.copy() @@ -38,7 +38,7 @@ def inject_file(file): def inject_arguments(file, args): if type(args) is tuple: args = list(args) - return [ args[0], '-c', '. otel.sh\n_otel_inject "' + file + '" "$@"', 'python' ] + args[1:] + return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) @@ -46,8 +46,8 @@ def observed_os_execv(original_os_execve, file, args): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execv(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) - print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) + print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From fa6d8a819005c24a99caca8fb1e69a3378b92348 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:54:32 +0100 Subject: [PATCH 045/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 047316a27..0480cb5e3 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,21 +3,21 @@ if ! which python3; then exit 0; fi . otel.sh -\echo ' +echo ' import os -os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) +os.execl("/bin/echo", "echo", "hello", "world", "0") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 1"')" +span="$(resolve_span '.name == "echo hello world 0"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') assert_not_equals null $(\echo "$span" | jq -r '.parent_id') -echo ' +\echo ' import os -os.execl("/bin/echo", "echo", "hello", "world", "0") +os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 0"')" +span="$(resolve_span '.name == "echo hello world 1"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') assert_not_equals null $(\echo "$span" | jq -r '.parent_id') From b027be5e4c8f1175363fcbd2358c204a08004e92 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:00:27 +0100 Subject: [PATCH 046/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 0698c7955..666791b5d 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -36,18 +36,22 @@ def inject_file(file): return '/bin/sh' def inject_arguments(file, args): + try: + file = file.decode() + except (UnicodeDecodeError, AttributeError): + pass if type(args) is tuple: args = list(args) return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) - print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + # print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) + # print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) - print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + # print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) + # print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From 961f0eca4987b8a6253b5a91ca5017e90a58f691 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:15:05 +0100 Subject: [PATCH 047/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 40 ++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 0480cb5e3..d846527b3 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -9,8 +9,8 @@ os.execl("/bin/echo", "echo", "hello", "world", "0") ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 0"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') \echo ' import os @@ -18,8 +18,8 @@ os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 1"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import os @@ -27,8 +27,8 @@ os.spawnl(os.P_WAIT, "/bin/echo", "echo", "hello", "world", "2") ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 2"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import os @@ -36,8 +36,8 @@ os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 3"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import os @@ -45,8 +45,8 @@ os.spawnv(os.P_WAIT, "/bin/echo", ["echo", "hello", "world", "4"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 4"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import os @@ -54,8 +54,8 @@ os.spawnvp(os.P_WAIT, "echo", ["echo", "hello", "world", "5"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 5"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import subprocess @@ -63,8 +63,8 @@ subprocess.run(["echo", "hello", "world", "6"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 6"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import subprocess @@ -72,8 +72,8 @@ subprocess.run("echo hello world 7", shell=True) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 7"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') printf '%s' ' import subprocess @@ -82,8 +82,8 @@ with subprocess.Popen(["echo", "hello", "world", "8"], stdout=subprocess.DEVNULL ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 8"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') printf '%s' ' import subprocess @@ -92,8 +92,8 @@ with subprocess.Popen(["echo", "hello", "world", "9"], stdout=subprocess.DEVNULL ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 9"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | jq -r '.kind') -assert_not_equals null $(\echo "$span" | jq -r '.parent_id') +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE From 48a6c793ccca901cbc7af02f0d8d95c4d3055ba0 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:15:49 +0100 Subject: [PATCH 048/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index d846527b3..2dc78c7b2 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,6 +3,20 @@ if ! which python3; then exit 0; fi . otel.sh + + +echo ' +import os +os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") +' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 3"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') + + + + echo ' import os os.execl("/bin/echo", "echo", "hello", "world", "0") From 25f4115542fa4de1e6f1f931bb6fa0be00bf7260 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:16:09 +0100 Subject: [PATCH 049/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 666791b5d..23e8d0cd2 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -45,13 +45,13 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - # print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) - # print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) + print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - # print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) - # print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) + print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From 14326bf9b358701d151e81a4ae8229247974f915 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:33:29 +0100 Subject: [PATCH 050/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 23e8d0cd2..a24b0fc61 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -42,16 +42,16 @@ def inject_arguments(file, args): pass if type(args) is tuple: args = list(args) - return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] + return [ args[0], '-x', '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) - print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) + # print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) + # print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) - print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) + # print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) + # print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) # def observed_os_execvp(original_os_execvpe, file, args): From ecf4eb0e879b5ef5be70e7387c2d903e0cb1efc3 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:58:05 +0100 Subject: [PATCH 051/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 2dc78c7b2..d3364829e 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,7 +3,9 @@ if ! which python3; then exit 0; fi . otel.sh - +which echo +ls -la /snap/bin/echo +readlink -f /snap/bin/echo echo ' import os From 833c18ba7c775708a19a82e7a55f780bebbc1ff0 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:43:49 +0100 Subject: [PATCH 052/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index a24b0fc61..8517a9cfe 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -42,6 +42,8 @@ def inject_arguments(file, args): pass if type(args) is tuple: args = list(args) + if '/' in file and (not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK)): + raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used return [ args[0], '-x', '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): From b32865fe24931c7b0b2dcef57e4afc91fd76ef73 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:57:11 +0100 Subject: [PATCH 053/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 8517a9cfe..9eebc9e25 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -44,7 +44,7 @@ def inject_arguments(file, args): args = list(args) if '/' in file and (not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK)): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used - return [ args[0], '-x', '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] + return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): # print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) From 515463c7a7d561e6a5911f97ce55dd7e30b02b1e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:01:36 +0100 Subject: [PATCH 054/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index d3364829e..bbdc87cca 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,16 +3,12 @@ if ! which python3; then exit 0; fi . otel.sh -which echo -ls -la /snap/bin/echo -readlink -f /snap/bin/echo - echo ' import os os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 3"')" +span="$(resolve_span '.name == "/usr/bin/echo hello world 3"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -51,7 +47,7 @@ import os os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 3"')" +span="$(resolve_span '.name == "/usr/bin/echo hello world 3"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -69,7 +65,7 @@ import os os.spawnvp(os.P_WAIT, "echo", ["echo", "hello", "world", "5"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 5"')" +span="$(resolve_span '.name == "/usr/bin/echo hello world 5"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') From d3b0fa27fd2e4f88486e33864f0d1e1693b7e77b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:59:44 +0100 Subject: [PATCH 055/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index bbdc87cca..d846527b3 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,18 +3,6 @@ if ! which python3; then exit 0; fi . otel.sh -echo ' -import os -os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") -' | python3 -assert_equals 0 $? -span="$(resolve_span '.name == "/usr/bin/echo hello world 3"')" -assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') -assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') - - - - echo ' import os os.execl("/bin/echo", "echo", "hello", "world", "0") @@ -47,7 +35,7 @@ import os os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/usr/bin/echo hello world 3"')" +span="$(resolve_span '.name == "echo hello world 3"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -65,7 +53,7 @@ import os os.spawnvp(os.P_WAIT, "echo", ["echo", "hello", "world", "5"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/usr/bin/echo hello world 5"')" +span="$(resolve_span '.name == "echo hello world 5"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') From 2543e72e5a5ef4d9b79bbef8fed9f463597bc774 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:41:51 +0100 Subject: [PATCH 056/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index d846527b3..fd36e1c74 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -57,38 +57,38 @@ span="$(resolve_span '.name == "echo hello world 5"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') -echo ' +printf '%s' ' import subprocess -subprocess.run(["echo", "hello", "world", "6"]) +with subprocess.Popen(["echo", "hello", "world", "6"], stdout=subprocess.DEVNULL) as proc: + pass ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 6"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') -echo ' +printf '%s' ' import subprocess -subprocess.run("echo hello world 7", shell=True) +with subprocess.Popen(["echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: + pass ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 7"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') -printf '%s' ' +echo ' import subprocess -with subprocess.Popen(["echo", "hello", "world", "8"], stdout=subprocess.DEVNULL) as proc: - pass +subprocess.run(["echo", "hello", "world", "8"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 8"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') -printf '%s' ' +echo ' import subprocess -with subprocess.Popen(["echo", "hello", "world", "9"], stdout=subprocess.DEVNULL) as proc: - pass +subprocess.run("echo hello world 9", shell=True) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 9"')" From d80bbec6ac84808c65992528193c4aaca6e43a5b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:34:08 +0100 Subject: [PATCH 057/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 9eebc9e25..73430cd9f 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -47,26 +47,19 @@ def inject_arguments(file, args): return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - # print('os.execv(' + str(file) + ', ' + str(args) + ')', file=sys.stderr) - # print('os.execv(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(None)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - # print('os.execve(' + str(file) + ', ' + str(args) + ', ' + str(env) + ')', file=sys.stderr) - # print('os.execve(' + inject_file(file) + ', [' + ','.join(inject_arguments(file, args)) + '], ' + str(inject_env(env)) + ')', file=sys.stderr) return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -# def observed_os_execvp(original_os_execvpe, file, args): -# return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(None)) - -# def observed_os_execvpe(original_os_execvpe, file, args, env): -# return original_os_execvpe(inject_file(file), inject_arguments(file, args), inject_env(env)) +def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, args, **kwargs) { + kwargs['env'] = inject_env(kwargs.get('env', None)) + return original_subprocess_Popen___init__(self, [ inject_file(args[0]) ] + inject_arguments(args[0], args[1:]), **kwargs); +} def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) os.execv = instrument(observed_os_execv, os.execve) os.execve = instrument(observed_os_execve, os.execve) -# os.execvp = instrument(observed_os_execvp, os.execvpe) -# os.execvpe = instrument(observed_os_execvpe, os.execvpe) -# print('INSTRUMENTED', file=sys.stderr) +subprocess.Popen.__init__ = instrument(observed_subprocess_Popen___init__, subprocess.Popen.__init__); From 9f1fb40cab6484d585938bf961e328d2e551287a Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:44:13 +0100 Subject: [PATCH 058/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 73430cd9f..d441428bd 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -52,10 +52,9 @@ def observed_os_execv(original_os_execve, file, args): def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, args, **kwargs) { +def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, args, **kwargs): kwargs['env'] = inject_env(kwargs.get('env', None)) return original_subprocess_Popen___init__(self, [ inject_file(args[0]) ] + inject_arguments(args[0], args[1:]), **kwargs); -} def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) From 5ee0452606fe4753286c5142b281876f0b2ac654 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:07:35 +0100 Subject: [PATCH 059/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index d441428bd..08039e8c7 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -1,5 +1,6 @@ import sys import os +import subprocess try: import opentelemetry From 29c415c1429a87a8cc38b369186aa21ec0d3d3ea Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:32:10 +0100 Subject: [PATCH 060/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 08039e8c7..810bc8c6c 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -53,7 +53,7 @@ def observed_os_execv(original_os_execve, file, args): def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, args, **kwargs): +def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, *args, **kwargs): kwargs['env'] = inject_env(kwargs.get('env', None)) return original_subprocess_Popen___init__(self, [ inject_file(args[0]) ] + inject_arguments(args[0], args[1:]), **kwargs); From 1114f5af9636d1948cc4fe73c7b7f2d54a9f7654 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:12:37 +0100 Subject: [PATCH 061/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 810bc8c6c..6c17f8b14 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -55,7 +55,7 @@ def observed_os_execve(original_os_execve, file, args, env): def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, *args, **kwargs): kwargs['env'] = inject_env(kwargs.get('env', None)) - return original_subprocess_Popen___init__(self, [ inject_file(args[0]) ] + inject_arguments(args[0], args[1:]), **kwargs); + return original_subprocess_Popen___init__(self, *([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])), **kwargs); def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) From fa899bbc8a162e18a6266582b12bb901eb1cf7d3 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:24:42 +0100 Subject: [PATCH 062/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 6c17f8b14..7442f9f75 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -34,31 +34,33 @@ def inject_env(env): import functools def inject_file(file): - return '/bin/sh' + return '/bin/sh' def inject_arguments(file, args): - try: - file = file.decode() - except (UnicodeDecodeError, AttributeError): - pass - if type(args) is tuple: - args = list(args) - if '/' in file and (not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK)): - raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used - return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] + try: + file = file.decode() + except (UnicodeDecodeError, AttributeError): + pass + if type(args) is tuple: + args = list(args) + if '/' in file and (not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK)): + raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used + return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): - return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) + return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) + return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, *args, **kwargs): - kwargs['env'] = inject_env(kwargs.get('env', None)) - return original_subprocess_Popen___init__(self, *([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])), **kwargs); + kwargs['env'] = inject_env(kwargs.get('env', None)) + args = tolist(args) + args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) + return original_subprocess_Popen___init__(self, *args, **kwargs); def instrument(observed_function, original_function): - return functools.partial(observed_function, original_function) + return functools.partial(observed_function, original_function) os.execv = instrument(observed_os_execv, os.execve) os.execve = instrument(observed_os_execve, os.execve) From 0090bfc6b81ecba4ddd62535733a8a0d0c8a7143 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:40:32 +0100 Subject: [PATCH 063/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 7442f9f75..00a805666 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -20,9 +20,9 @@ def inject_env(env): carrier = {} tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) if 'traceparent' in carrier: - env["OTEL_TRACEPARENT"] = carrier["traceparent"] + env["OTEL_TRACEPARENT"] = carrier["traceparent"] if 'tracestate' in carrier: - env["OTEL_TRACESTATE"] = carrier["tracestate"] + env["OTEL_TRACESTATE"] = carrier["tracestate"] return env; except ModuleNotFoundError: @@ -40,11 +40,13 @@ def inject_arguments(file, args): try: file = file.decode() except (UnicodeDecodeError, AttributeError): - pass + pass + if not '/' in file: + file = './' + file + if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): + raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used if type(args) is tuple: args = list(args) - if '/' in file and (not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK)): - raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] def observed_os_execv(original_os_execve, file, args): @@ -54,8 +56,9 @@ def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, *args, **kwargs): + # TODO handle shell kwargs['env'] = inject_env(kwargs.get('env', None)) - args = tolist(args) + args = list(args) args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) return original_subprocess_Popen___init__(self, *args, **kwargs); From 9d0b84dcbf853ba3b691bcf7a6d82f8dc9d83d2b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 10:46:34 +0100 Subject: [PATCH 064/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 00a805666..663b6fae6 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -57,10 +57,12 @@ def observed_os_execve(original_os_execve, file, args, env): def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, *args, **kwargs): # TODO handle shell - kwargs['env'] = inject_env(kwargs.get('env', None)) args = list(args) + print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) + kwargs['env'] = inject_env(kwargs.get('env', None)) args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) - return original_subprocess_Popen___init__(self, *args, **kwargs); + print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) + return original_subprocess_Popen___init__(self, args, **kwargs); def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) From e1c4fc6005dd1f959193c4329daac0b20235a387 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:02:58 +0100 Subject: [PATCH 065/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 663b6fae6..de608d4c8 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -56,8 +56,9 @@ def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, *args, **kwargs): - # TODO handle shell + print('subprocess.Popen(' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) args = list(args) + # TODO handle shell print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) kwargs['env'] = inject_env(kwargs.get('env', None)) args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) From 5285a77ccdb9a241a0059cf25a13eedd6149a884 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:25:41 +0100 Subject: [PATCH 066/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index de608d4c8..1765191a9 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -55,7 +55,8 @@ def observed_os_execv(original_os_execve, file, args): def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, *args, **kwargs): +def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, **kwargs): + print('subprocess.Popen(' + str(kwargs) + ')', file=sys.stderr) print('subprocess.Popen(' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) args = list(args) # TODO handle shell From b4d24754054768d0165c8e67d32ab0826068deae Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:38:13 +0100 Subject: [PATCH 067/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 1765191a9..7b3aba1f2 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -55,9 +55,8 @@ def observed_os_execv(original_os_execve, file, args): def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, **kwargs): - print('subprocess.Popen(' + str(kwargs) + ')', file=sys.stderr) - print('subprocess.Popen(' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) +def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, args, **kwargs): + print('subprocess.Popen(' + str(self) + ', ' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) args = list(args) # TODO handle shell print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) From 78b11b6d978e81596f7c43a7e6f0040a133d47f2 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:40:06 +0100 Subject: [PATCH 068/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 7b3aba1f2..8ce6c1534 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -55,8 +55,15 @@ def observed_os_execv(original_os_execve, file, args): def observed_os_execve(original_os_execve, file, args, env): return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) -def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, args, **kwargs): - print('subprocess.Popen(' + str(self) + ', ' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) +def instrument(observed_function, original_function): + return functools.partial(observed_function, original_function) + +os.execv = instrument(observed_os_execv, os.execve) +os.execve = instrument(observed_os_execve, os.execve) + +original_subprocess_Popen___init__ = subprocess.Popen.__init__ +def observed_subprocess_Popen___init__(self, *args, **kwargs): + print('subprocess.Popen(' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) args = list(args) # TODO handle shell print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) @@ -64,10 +71,4 @@ def observed_subprocess_Popen___init__(original_subprocess_Popen___init__, self, args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); - -def instrument(observed_function, original_function): - return functools.partial(observed_function, original_function) - -os.execv = instrument(observed_os_execv, os.execve) -os.execve = instrument(observed_os_execve, os.execve) -subprocess.Popen.__init__ = instrument(observed_subprocess_Popen___init__, subprocess.Popen.__init__); +subprocess.Popen.__init__ = observed_subprocess_Popen___init__ From 99120915e0aae7394256ed6bd31f87b65b30bbd0 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:52:14 +0100 Subject: [PATCH 069/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 8ce6c1534..f91ea5186 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -63,8 +63,8 @@ def instrument(observed_function, original_function): original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_subprocess_Popen___init__(self, *args, **kwargs): - print('subprocess.Popen(' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) args = list(args) + print('subprocess.Popen(' + ','.join(args) + ', ' + str(kwargs) + ')', file=sys.stderr) # TODO handle shell print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) kwargs['env'] = inject_env(kwargs.get('env', None)) From 332ae792669a331463b7cb4e9420d48c9a893ee9 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:06:29 +0100 Subject: [PATCH 070/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index f91ea5186..3f32c49bd 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -63,6 +63,7 @@ def instrument(observed_function, original_function): original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_subprocess_Popen___init__(self, *args, **kwargs): + print('subprocess.Popen(' + type(self) + ', ' + type(args) + ', ' + type(kwargs) + ')', file=sys.stderr) args = list(args) print('subprocess.Popen(' + ','.join(args) + ', ' + str(kwargs) + ')', file=sys.stderr) # TODO handle shell From d8b6876e48ec2211d7a2b0e5ea55a97e2f31f9c6 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:17:12 +0100 Subject: [PATCH 071/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 3f32c49bd..9a14b804d 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -63,7 +63,7 @@ def instrument(observed_function, original_function): original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_subprocess_Popen___init__(self, *args, **kwargs): - print('subprocess.Popen(' + type(self) + ', ' + type(args) + ', ' + type(kwargs) + ')', file=sys.stderr) + print('subprocess.Popen(' + str(type(self)) + ', ' + str(type(args)) + ', ' + str(type(kwargs)) + ')', file=sys.stderr) args = list(args) print('subprocess.Popen(' + ','.join(args) + ', ' + str(kwargs) + ')', file=sys.stderr) # TODO handle shell From 833ab54f110bc114cf074c1e5cd27ef37e67c069 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:35:46 +0100 Subject: [PATCH 072/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 9a14b804d..3692e29de 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -64,8 +64,8 @@ def instrument(observed_function, original_function): original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_subprocess_Popen___init__(self, *args, **kwargs): print('subprocess.Popen(' + str(type(self)) + ', ' + str(type(args)) + ', ' + str(type(kwargs)) + ')', file=sys.stderr) + print('subprocess.Popen([' + ','.join(list(args)) + '], ' + str(kwargs) + ')', file=sys.stderr) args = list(args) - print('subprocess.Popen(' + ','.join(args) + ', ' + str(kwargs) + ')', file=sys.stderr) # TODO handle shell print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) kwargs['env'] = inject_env(kwargs.get('env', None)) From bbd8f297045913ba1ebfbd8721cafe6302eca861 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:47:01 +0100 Subject: [PATCH 073/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 3692e29de..041c00afd 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -64,6 +64,7 @@ def instrument(observed_function, original_function): original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_subprocess_Popen___init__(self, *args, **kwargs): print('subprocess.Popen(' + str(type(self)) + ', ' + str(type(args)) + ', ' + str(type(kwargs)) + ')', file=sys.stderr) + print('subprocess.Popen(' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) print('subprocess.Popen([' + ','.join(list(args)) + '], ' + str(kwargs) + ')', file=sys.stderr) args = list(args) # TODO handle shell From 859f7a51c4d745fdf1fd180265f710ef94d1c358 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:53:05 +0100 Subject: [PATCH 074/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 041c00afd..d34f44d15 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -63,11 +63,9 @@ def instrument(observed_function, original_function): original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_subprocess_Popen___init__(self, *args, **kwargs): - print('subprocess.Popen(' + str(type(self)) + ', ' + str(type(args)) + ', ' + str(type(kwargs)) + ')', file=sys.stderr) - print('subprocess.Popen(' + str(args) + ', ' + str(kwargs) + ')', file=sys.stderr) - print('subprocess.Popen([' + ','.join(list(args)) + '], ' + str(kwargs) + ')', file=sys.stderr) args = list(args) - # TODO handle shell + if len(args) > 0 and type(args[0]) is list: + args = args[0] print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) kwargs['env'] = inject_env(kwargs.get('env', None)) args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) From fc8612a55dd6acc4768224b348a245d16d68a9d7 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:11:51 +0100 Subject: [PATCH 075/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 333fada13..5680aca72 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -59,7 +59,7 @@ assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') printf '%s' ' import subprocess -with subprocess.Popen(["echo", "hello", "world", "6"], stdout=subprocess.DEVNULL) as proc: +with subprocess.Popen(["/usr/bin/echo", "hello", "world", "6"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 assert_equals 0 $? @@ -69,7 +69,7 @@ assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') printf '%s' ' import subprocess -with subprocess.Popen(["echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: +with subprocess.Popen(["/usr/bin/echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 assert_equals 0 $? @@ -79,7 +79,7 @@ assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import subprocess -subprocess.run(["echo", "hello", "world", "8"]) +subprocess.run(["/usr/bin/echo", "hello", "world", "8"]) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 8"')" From 5a56b9baa3aac0b0600d275b2850dd90b4daf24c Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:25:05 +0100 Subject: [PATCH 076/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index d34f44d15..d2329c835 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -68,7 +68,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = args[0] print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) kwargs['env'] = inject_env(kwargs.get('env', None)) - args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) + args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args)) print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); subprocess.Popen.__init__ = observed_subprocess_Popen___init__ From a29de8f0f59f20b77a2ff9b998987939c141e826 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:28:48 +0100 Subject: [PATCH 077/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index d2329c835..a745bed72 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -47,13 +47,13 @@ def inject_arguments(file, args): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used if type(args) is tuple: args = list(args) - return [ args[0], '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args[1:] + return [ '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args def observed_os_execv(original_os_execve, file, args): - return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(None)) + return original_os_execve(inject_file(file), args[0] + inject_arguments(file, args[1:]), inject_env(None)) def observed_os_execve(original_os_execve, file, args, env): - return original_os_execve(inject_file(file), inject_arguments(file, args), inject_env(env)) + return original_os_execve(inject_file(file), args[0] + inject_arguments(file, args[1:]), inject_env(env)) def instrument(observed_function, original_function): return functools.partial(observed_function, original_function) @@ -68,7 +68,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = args[0] print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) kwargs['env'] = inject_env(kwargs.get('env', None)) - args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args)) + args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); subprocess.Popen.__init__ = observed_subprocess_Popen___init__ From f8af5af58a104a5d94a6de1733aca2be8bf7a68a Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:43:56 +0100 Subject: [PATCH 078/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index a745bed72..9f1836de5 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -45,23 +45,21 @@ def inject_arguments(file, args): file = './' + file if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used - if type(args) is tuple: - args = list(args) return [ '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args -def observed_os_execv(original_os_execve, file, args): +original_os_execve = os.execve +original_subprocess_Popen___init__ = subprocess.Popen.__init__ + +def observed_os_execv(file, args): + if type(args) is tuple: + args = list(args) return original_os_execve(inject_file(file), args[0] + inject_arguments(file, args[1:]), inject_env(None)) -def observed_os_execve(original_os_execve, file, args, env): +def observed_os_execve(file, args, env): + if type(args) is tuple: + args = list(args) return original_os_execve(inject_file(file), args[0] + inject_arguments(file, args[1:]), inject_env(env)) -def instrument(observed_function, original_function): - return functools.partial(observed_function, original_function) - -os.execv = instrument(observed_os_execv, os.execve) -os.execve = instrument(observed_os_execve, os.execve) - -original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = list(args) if len(args) > 0 and type(args[0]) is list: @@ -71,4 +69,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); + +os.execv = observed_os_execv +os.execve = observed_os_execve subprocess.Popen.__init__ = observed_subprocess_Popen___init__ From e6a79cfe444c72d98a70c11c7f4265c7a68010d5 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:56:26 +0100 Subject: [PATCH 079/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 9f1836de5..ff144edf9 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -53,12 +53,12 @@ def inject_arguments(file, args): def observed_os_execv(file, args): if type(args) is tuple: args = list(args) - return original_os_execve(inject_file(file), args[0] + inject_arguments(file, args[1:]), inject_env(None)) + return original_os_execve(inject_file(file), [ args[0] ] + inject_arguments(file, args[1:]), inject_env(None)) def observed_os_execve(file, args, env): if type(args) is tuple: args = list(args) - return original_os_execve(inject_file(file), args[0] + inject_arguments(file, args[1:]), inject_env(env)) + return original_os_execve(inject_file(file), [ args[0] ] + inject_arguments(file, args[1:]), inject_env(env)) def observed_subprocess_Popen___init__(self, *args, **kwargs): args = list(args) From 76fa64d65ba4820413ee8aa57529ae080e17f8ef Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:09:36 +0100 Subject: [PATCH 080/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 5680aca72..3a9f57b66 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -67,11 +67,18 @@ span="$(resolve_span '.name == "echo hello world 6"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') +dir=$(mktemp -d) +python3 -m venv --system-site-packages "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip3 install requests +pip3 install opentelemetry-distro opentelemetry-exporter-otlp +opentelemetry-bootstrap --action install || exit 1 printf '%s' ' import subprocess with subprocess.Popen(["/usr/bin/echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 +deactivate assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 7"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') From 80bf900dfbe38cb011f9c6266f6cd1e28ed216f2 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:10:17 +0100 Subject: [PATCH 081/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index f41cd7fee..08b8dc00e 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -4,7 +4,7 @@ _otel_inject_python() { if \[ -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 && \false; then + if _otel_python_is_customize_injectable; then if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" From a9c28565607c89f2449980701326ef929bb29c83 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:23:17 +0100 Subject: [PATCH 082/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 08b8dc00e..f41cd7fee 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -4,7 +4,7 @@ _otel_inject_python() { if \[ -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 + if _otel_python_is_customize_injectable && \false; then if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" From 97949f0b5a2892ee37230a48d64d1074b0c6ee7b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:08:15 +0100 Subject: [PATCH 083/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 3a9f57b66..67cdad60a 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -70,7 +70,6 @@ assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate -pip3 install requests pip3 install opentelemetry-distro opentelemetry-exporter-otlp opentelemetry-bootstrap --action install || exit 1 printf '%s' ' From 6af92ed46198c13834d39515e2a8b4fb370a197e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:27:29 +0100 Subject: [PATCH 084/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 67cdad60a..4e467bccd 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -67,17 +67,17 @@ span="$(resolve_span '.name == "echo hello world 6"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') -dir=$(mktemp -d) -python3 -m venv --system-site-packages "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate -pip3 install opentelemetry-distro opentelemetry-exporter-otlp -opentelemetry-bootstrap --action install || exit 1 +# dir=$(mktemp -d) +# python3 -m venv --system-site-packages "$dir"/venv || exit 1 +# . "$dir"/venv/bin/activate +# pip3 install opentelemetry-distro opentelemetry-exporter-otlp +# opentelemetry-bootstrap --action install || exit 1 printf '%s' ' import subprocess with subprocess.Popen(["/usr/bin/echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 -deactivate +# deactivate assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 7"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') From 51b1cf3dd07d5e177b2414e11883b00e85292cc0 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:38:06 +0100 Subject: [PATCH 085/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index ff144edf9..7e9f0311a 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -36,16 +36,18 @@ def inject_env(env): def inject_file(file): return '/bin/sh' -def inject_arguments(file, args): +def inject_arguments(file, args, is_file=True): try: file = file.decode() except (UnicodeDecodeError, AttributeError): pass - if not '/' in file: - file = './' + file - if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): - raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used - return [ '-c', '. otel.sh\n_otel_inject "' + str(file) + '" "$@"', 'python' ] + args + if is_file: + if not '/' in file: + file = './' + file + if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): + raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used + file = '_otel_inject "' + file + "'" + return [ '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args original_os_execve = os.execve original_subprocess_Popen___init__ = subprocess.Popen.__init__ @@ -65,8 +67,9 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if len(args) > 0 and type(args[0]) is list: args = args[0] print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) + args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:], kwargs.get('shell', False))) kwargs['env'] = inject_env(kwargs.get('env', None)) - args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:])) + kwargs['shell'] = False # TODO commandline override and no auto injection like node print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); From 0a63df1fc0f4aaf213a67e183151e07f550a6aaf Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 19:38:28 +0100 Subject: [PATCH 086/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 7e9f0311a..33bf45e2f 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -46,7 +46,7 @@ def inject_arguments(file, args, is_file=True): file = './' + file if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used - file = '_otel_inject "' + file + "'" + file = "_otel_inject '" + file + "'" return [ '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args original_os_execve = os.execve From 199fbae3957ba16ab18dd8d2ce16db14f41254fa Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:52:42 +0100 Subject: [PATCH 087/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 33bf45e2f..9bc0d52dc 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -67,7 +67,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if len(args) > 0 and type(args[0]) is list: args = args[0] print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) - args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:], kwargs.get('shell', False))) + args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:], not kwargs.get('shell', False))) kwargs['env'] = inject_env(kwargs.get('env', None)) kwargs['shell'] = False # TODO commandline override and no auto injection like node print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) From 6176cbbd89ed67e9d69f15199e236fbca77fc326 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:03:16 +0100 Subject: [PATCH 088/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 4e467bccd..736d04ae7 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -101,6 +101,15 @@ span="$(resolve_span '.name == "echo hello world 9"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') +echo ' +import subprocess +subprocess.run(["echo", "hello", "world", 10"], shell=True) +' | python3 +assert_equals 0 $? +span="$(resolve_span '.name == "echo hello world 10"')" +assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') +assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') + export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE echo ' From 23bc76595c45f52248bcb50e42fbcf65ed16229b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:27:36 +0100 Subject: [PATCH 089/162] 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 736d04ae7..a77eca412 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -103,7 +103,7 @@ assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import subprocess -subprocess.run(["echo", "hello", "world", 10"], shell=True) +subprocess.run(["echo", "hello", "world", "10"], shell=True) ' | python3 assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 10"')" From 0aec67ee482790805764ee8e26f98aaaa58eb1f1 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:32:29 +0100 Subject: [PATCH 090/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 9bc0d52dc..995ec03d2 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -66,11 +66,13 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = list(args) if len(args) > 0 and type(args[0]) is list: args = args[0] - print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:], not kwargs.get('shell', False))) kwargs['env'] = inject_env(kwargs.get('env', None)) - kwargs['shell'] = False # TODO commandline override and no auto injection like node - print('subprocess.Popen([' + ','.join(args) + '], ' + str(kwargs) + ')', file=sys.stderr) + if kwargs.get('shell', False): + kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE'] = '/bin/sh -c ' + ' '.join(args) + kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) + kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' + kwargs['shell'] = False return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From 68bd3229159997aa12090b341d8124b28da626a8 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:46:09 +0100 Subject: [PATCH 091/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index a77eca412..b546ac1da 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -67,18 +67,18 @@ span="$(resolve_span '.name == "echo hello world 6"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') -# dir=$(mktemp -d) -# python3 -m venv --system-site-packages "$dir"/venv || exit 1 -# . "$dir"/venv/bin/activate -# pip3 install opentelemetry-distro opentelemetry-exporter-otlp -# opentelemetry-bootstrap --action install || exit 1 +dir=$(mktemp -d) +python3 -m venv "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip3 install opentelemetry-distro opentelemetry-exporter-otlp +opentelemetry-bootstrap --action install || exit 1 printf '%s' ' import subprocess with subprocess.Popen(["/usr/bin/echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 -# deactivate assert_equals 0 $? +deactivate span="$(resolve_span '.name == "echo hello world 7"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') From 243b64aa64bfbb641450ed66161351bb466d521d Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:58:22 +0100 Subject: [PATCH 092/162] 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 b546ac1da..86b85d2cb 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -68,7 +68,7 @@ assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') dir=$(mktemp -d) -python3 -m venv "$dir"/venv || exit 1 +python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate pip3 install opentelemetry-distro opentelemetry-exporter-otlp opentelemetry-bootstrap --action install || exit 1 From ff78109d03dea598b2d5aad1873498c5bdc5d07e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 00:07:00 +0100 Subject: [PATCH 093/162] Update agent.instrumentation.python.sh --- .../opentelemetry_shell/agent.instrumentation.python.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index f41cd7fee..88895287a 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -75,6 +75,13 @@ _otel_python_inject_args() { _otel_escape_arg "$(\cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py) $arg" local injected=cmdline + elif \[ "$arg" = -m ]; then + _otel_escape_args -c + \echo -n ' ' + local arg="$1"; shift + _otel_escape_arg "$(\cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py) +import runpy +runpy.run_module('$arg', run_name='__main__')" elif \[ -f "$arg" ]; then _otel_escape_args -c "$(\cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py) with open('$arg', 'r') as file: # SKIP_DEPENDENCY_CHECK From 0865aa1ba745f54188e3ed51ae3393043295ae03 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 00:07:21 +0100 Subject: [PATCH 094/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 88895287a..0205fc111 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -82,6 +82,7 @@ $arg" _otel_escape_arg "$(\cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py) import runpy runpy.run_module('$arg', run_name='__main__')" + local injected=module elif \[ -f "$arg" ]; then _otel_escape_args -c "$(\cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py) with open('$arg', 'r') as file: # SKIP_DEPENDENCY_CHECK From d5d98faabed34ecaf4d560a4efe02ab882a6c153 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 00:17:19 +0100 Subject: [PATCH 095/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 0205fc111..641f179c3 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -80,7 +80,7 @@ $arg" \echo -n ' ' local arg="$1"; shift _otel_escape_arg "$(\cat /usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py) -import runpy +import runpy # SKIP_DEPENDENCY_CHECK runpy.run_module('$arg', run_name='__main__')" local injected=module elif \[ -f "$arg" ]; then From 38a8efe90ee8272875dc715ebbd2a35eb978adfa Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:30:26 +0100 Subject: [PATCH 096/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 995ec03d2..82ee78620 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -41,13 +41,17 @@ def inject_arguments(file, args, is_file=True): file = file.decode() except (UnicodeDecodeError, AttributeError): pass + arg_zero = None if is_file: if not '/' in file: file = './' + file if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used + arg_zero = file; file = "_otel_inject '" + file + "'" - return [ '-c', '. otel.sh\n' + file + ' "$@"', 'python' ] + args + else + arg_zero = 'python' + return [ '-c', '. otel.sh\n' + file + ' "$@"', arg_zero ] + args original_os_execve = os.execve original_subprocess_Popen___init__ = subprocess.Popen.__init__ From a2c0be2e8c955dfc8cdb5869e484edc827efb392 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:42:17 +0100 Subject: [PATCH 097/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 82ee78620..c26548465 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -49,7 +49,7 @@ def inject_arguments(file, args, is_file=True): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used arg_zero = file; file = "_otel_inject '" + file + "'" - else + else: arg_zero = 'python' return [ '-c', '. otel.sh\n' + file + ' "$@"', arg_zero ] + args From eff63699d7e110ea6ef535c44b0be9c8611d02cd Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:38:19 +0100 Subject: [PATCH 098/162] 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 c9e814e59..d7c829f30 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -200,7 +200,7 @@ _otel_filter_commands_by_special() { } _otel_filter_by_validity() { - \grep -E '^[a-zA-Z0-9._\[][a-zA-Z0-9 ._-]*$' + \grep -aE '^[a-zA-Z0-9._\[][a-zA-Z0-9 ._-]*$' } _otel_deshebangify() { From d37e474a70b1fc9a4499edd53267f4b24f9f85f0 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:43:51 +0100 Subject: [PATCH 099/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index c26548465..e2cee6475 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -14,9 +14,10 @@ new_context = propagator.extract(carrier=carrier) attach(new_context) - def inject_env(env): + def inject_env(env, args): if not env: env = os.environ.copy() + env['OTEL_SHELL_AUTO_INSTRUMENTATION_HINT'] = ' '.join(args) carrier = {} tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) if 'traceparent' in carrier: @@ -26,9 +27,10 @@ def inject_env(env): return env; except ModuleNotFoundError: - def inject_env(env): + def inject_env(env, args): if not env: env = os.environ.copy() + env['OTEL_SHELL_AUTO_INSTRUMENTATION_HINT'] = ' '.join(args) return env import functools @@ -59,19 +61,25 @@ def inject_arguments(file, args, is_file=True): def observed_os_execv(file, args): if type(args) is tuple: args = list(args) - return original_os_execve(inject_file(file), [ args[0] ] + inject_arguments(file, args[1:]), inject_env(None)) + args = [ args[0] ] + inject_arguments(file, args[1:]) + file = inject_file(file) + env = inject_env(None, args) + return original_os_execve(file, args, env) def observed_os_execve(file, args, env): if type(args) is tuple: args = list(args) - return original_os_execve(inject_file(file), [ args[0] ] + inject_arguments(file, args[1:]), inject_env(env)) + args = [ args[0] ] + inject_arguments(file, args[1:]) + file = inject_file(file) + env = inject_env(env, args) + return original_os_execve(file, args, env) def observed_subprocess_Popen___init__(self, *args, **kwargs): args = list(args) if len(args) > 0 and type(args[0]) is list: args = args[0] args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:], not kwargs.get('shell', False))) - kwargs['env'] = inject_env(kwargs.get('env', None)) + kwargs['env'] = inject_env(kwargs.get('env', None), args) if kwargs.get('shell', False): kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE'] = '/bin/sh -c ' + ' '.join(args) kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) From 9068ac117a0ab7b12650922ec62c4e8d3e9b3df5 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 23:12:05 +0100 Subject: [PATCH 100/162] 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 d7c829f30..136b9bb90 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -447,7 +447,7 @@ command() { _otel_inject() { if _otel_string_contains "$1" /; then local path="$1" - local command="$(\readlink -f "$path" | \rev | \cut -d / -f 1 | \rev)" + local command="$(\echo "$path" | \rev | \cut -d / -f 1 | \rev)" shift set -- "$command" "$@" if ! \[ "$(\which "$command")" = "$path" ]; then From e6cf631a16ee0e0c9aa11f22801178850e5cd31d Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 23:31:37 +0100 Subject: [PATCH 101/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index e2cee6475..b75943f48 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -50,7 +50,7 @@ def inject_arguments(file, args, is_file=True): if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used arg_zero = file; - file = "_otel_inject '" + file + "'" + # file = "_otel_inject '" + file + "'" else: arg_zero = 'python' return [ '-c', '. otel.sh\n' + file + ' "$@"', arg_zero ] + args From a30fa481cce7abc6616f95ed483fb68afa82af6c Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 23:46:09 +0100 Subject: [PATCH 102/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index b75943f48..e2cee6475 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -50,7 +50,7 @@ def inject_arguments(file, args, is_file=True): if not os.path.exists(file) or not os.path.isfile(file) or not os.access(file, os.X_OK): raise FileNotFoundError(file) # python will just trial and error all possible paths if the 'p' variants of exec are used arg_zero = file; - # file = "_otel_inject '" + file + "'" + file = "_otel_inject '" + file + "'" else: arg_zero = 'python' return [ '-c', '. otel.sh\n' + file + ' "$@"', arg_zero ] + args From 52fe8c27a9f34597cc0442bbdca244c35b6b59cb Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 10 Jan 2025 23:56:24 +0100 Subject: [PATCH 103/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index e2cee6475..bac5e9234 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -85,6 +85,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False + kwargs['stderr'] = sys.stderr return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From 6dbcb512396ead88b3dc338b0258539d2b4f4103 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 00:11:57 +0100 Subject: [PATCH 104/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index bac5e9234..060f3d436 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -78,6 +78,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = list(args) if len(args) > 0 and type(args[0]) is list: args = args[0] + print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:], not kwargs.get('shell', False))) kwargs['env'] = inject_env(kwargs.get('env', None), args) if kwargs.get('shell', False): @@ -85,7 +86,8 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False - kwargs['stderr'] = sys.stderr + print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) + kwargs['stderr'] = sys.stderr return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From f9629bafbd24532ff3da65d9516a67171ef7932b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 10:47:17 +0100 Subject: [PATCH 105/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 060f3d436..6a4b0ca78 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -79,7 +79,9 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if len(args) > 0 and type(args[0]) is list: args = args[0] print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) - args = ([ inject_file(args[0]) ] + inject_arguments(args[0], args[1:], not kwargs.get('shell', False))) + args = ([ inject_file(args[0]) ] + inject_arguments(inject_file(kwargs.get('executable', args[0])), args[1:], not kwargs.get('shell', False))) + if kwargs.get('executable'): + kwargs['executable'] = inject_file(kwargs['executable']) kwargs['env'] = inject_env(kwargs.get('env', None), args) if kwargs.get('shell', False): kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE'] = '/bin/sh -c ' + ' '.join(args) From e134d418cc98f981a1a7e7169d79af474321524c Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 11:30:30 +0100 Subject: [PATCH 106/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 6a4b0ca78..9e9b96497 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -79,7 +79,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if len(args) > 0 and type(args[0]) is list: args = args[0] print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) - args = ([ inject_file(args[0]) ] + inject_arguments(inject_file(kwargs.get('executable', args[0])), args[1:], not kwargs.get('shell', False))) + args = ([ inject_file(kwargs.get('executable', args[0])) ] + inject_arguments(kwargs.get('executable', args[0]), args[1:], not kwargs.get('shell', False))) if kwargs.get('executable'): kwargs['executable'] = inject_file(kwargs['executable']) kwargs['env'] = inject_env(kwargs.get('env', None), args) From 7bc783dfedbab540cde56c8c6cdde6971c58f639 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 16:31:06 +0100 Subject: [PATCH 107/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index 136b9bb90..d283ac1d7 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -446,9 +446,8 @@ command() { _otel_inject() { if _otel_string_contains "$1" /; then - local path="$1" + local path="$1"; shift local command="$(\echo "$path" | \rev | \cut -d / -f 1 | \rev)" - shift set -- "$command" "$@" if ! \[ "$(\which "$command")" = "$path" ]; then local PATH="$(\readlink -f "$path" | \rev | \cut -d / -f 2- | \rev):$PATH" @@ -458,6 +457,15 @@ _otel_inject() { \eval "$(_otel_escape_args "$@")" } +_otel_inject() { + if _otel_string_contains "$1" /; then + local path="$1"; shift + local command_string="$(\alias "${path##*/}" 2> /dev/null)" + \eval "set -- ${command_string% *} '$path' "'"$@"' + fi + \eval "$(_otel_escape_args "$@")" +} + _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 From c0445fd72f763c01b1c834637b08352997eba06f Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 16:33:31 +0100 Subject: [PATCH 108/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index d283ac1d7..a38c75c0c 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -459,9 +459,12 @@ _otel_inject() { _otel_inject() { if _otel_string_contains "$1" /; then - local path="$1"; shift + local path="$1" local command_string="$(\alias "${path##*/}" 2> /dev/null)" - \eval "set -- ${command_string% *} '$path' "'"$@"' + if \[ -n "$command_string" ]; then + shift + \eval "set -- ${command_string% *} '$path' "'"$@"' + fi fi \eval "$(_otel_escape_args "$@")" } From 9bef25dae331b8d94babfc0641f69b1fa7bc82fd Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 16:39:46 +0100 Subject: [PATCH 109/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index a38c75c0c..c597060a5 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -460,11 +460,14 @@ _otel_inject() { _otel_inject() { if _otel_string_contains "$1" /; then local path="$1" - local command_string="$(\alias "${path##*/}" 2> /dev/null)" - if \[ -n "$command_string" ]; then - shift - \eval "set -- ${command_string% *} '$path' "'"$@"' + local instrumentation="$(\alias "${path##*/}" 2> /dev/null)" + if \[ -n "$instrumentation" ]; then + local instrumentation="${instrumentation#*=}" + local instrumentation="${instrumentation% *}" + else + local instrumentation=_otel_observe fi + \eval "set -- $instrumentation "'"$@"' fi \eval "$(_otel_escape_args "$@")" } From 86e610aa046f4a2888e9c74fd9e46393b0017b37 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 16:53:27 +0100 Subject: [PATCH 110/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index c597060a5..391bded76 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -464,6 +464,7 @@ _otel_inject() { if \[ -n "$instrumentation" ]; then local instrumentation="${instrumentation#*=}" local instrumentation="${instrumentation% *}" + local instrumentation="$(\printf '%s' "$instrumentation" | _otel_line_split | \grep -v '^OTEL_' | _otel_line_join)" else local instrumentation=_otel_observe fi From 0fb70c7e76ccad484a3935a44bfd5b6061f3a9f7 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:08:24 +0100 Subject: [PATCH 111/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index 391bded76..490accc52 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -468,7 +468,8 @@ _otel_inject() { else local instrumentation=_otel_observe fi - \eval "set -- $instrumentation "'"$@"' + # \echo "DEBUG DEBUG DEBUG set -- $instrumentation " + \eval "set -- $instrumentation $(_otel_escape_args "$@")" fi \eval "$(_otel_escape_args "$@")" } From 895ab95b2db230991e129bbbbb32f06126f1e2d7 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:21:34 +0100 Subject: [PATCH 112/162] 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 490accc52..759b9ada6 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -468,7 +468,7 @@ _otel_inject() { else local instrumentation=_otel_observe fi - # \echo "DEBUG DEBUG DEBUG set -- $instrumentation " + \echo "DEBUG DEBUG DEBUG set -- $instrumentation $(_otel_escape_args "$@")" >&2 \eval "set -- $instrumentation $(_otel_escape_args "$@")" fi \eval "$(_otel_escape_args "$@")" From 51fa793168ce4b94b53e97b17af8592210370085 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:33:32 +0100 Subject: [PATCH 113/162] 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 759b9ada6..6720f3f68 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -460,7 +460,7 @@ _otel_inject() { _otel_inject() { if _otel_string_contains "$1" /; then local path="$1" - local instrumentation="$(\alias "${path##*/}" 2> /dev/null)" + local instrumentation="$(\alias "${path##*/}" 2> /dev/null | _otel_unquote)" if \[ -n "$instrumentation" ]; then local instrumentation="${instrumentation#*=}" local instrumentation="${instrumentation% *}" From 874b5a3a23b7e9fe6326696339125fb57c79ac98 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:36:41 +0100 Subject: [PATCH 114/162] 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 6720f3f68..51e8d99e4 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -460,9 +460,8 @@ _otel_inject() { _otel_inject() { if _otel_string_contains "$1" /; then local path="$1" - local instrumentation="$(\alias "${path##*/}" 2> /dev/null | _otel_unquote)" + local instrumentation="$(_otel_resolve_alias "${path##*/}")" if \[ -n "$instrumentation" ]; then - local instrumentation="${instrumentation#*=}" local instrumentation="${instrumentation% *}" local instrumentation="$(\printf '%s' "$instrumentation" | _otel_line_split | \grep -v '^OTEL_' | _otel_line_join)" else From da213f63453baa6700d4d9c9b5791304ba180c05 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 19:58:50 +0100 Subject: [PATCH 115/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index 51e8d99e4..b2af96e7f 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -468,6 +468,7 @@ _otel_inject() { local instrumentation=_otel_observe fi \echo "DEBUG DEBUG DEBUG set -- $instrumentation $(_otel_escape_args "$@")" >&2 + \echo "DEBUG DEBUG DEBUG $(_otel_resolve_instrumentation_hint)" >&2 \eval "set -- $instrumentation $(_otel_escape_args "$@")" fi \eval "$(_otel_escape_args "$@")" From fcd8d1edfbfc5059054cf62dde43d9de5ae68396 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 20:15:11 +0100 Subject: [PATCH 116/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index b2af96e7f..7760a3da0 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -30,6 +30,7 @@ case "$-" in *) _otel_is_interactive=FALSE;; esac +set -x if \[ -n "${OTEL_SHELL_AUTO_INSTRUMENTATION_HINT:-}" ]; then _otel_shell_auto_instrumentation_hint="$OTEL_SHELL_AUTO_INSTRUMENTATION_HINT" unset OTEL_SHELL_AUTO_INSTRUMENTATION_HINT @@ -44,6 +45,7 @@ elif \[ -f "$0" ] && \[ "$(\readlink -f "$0")" != "$(\readlink -f "/proc/$$/exe" else _otel_shell_auto_instrumentation_hint="$(_otel_resolve_command_self)" fi +set +x if \[ "$_otel_shell" = "bash" ]; then _otel_source_file_resolver='${BASH_SOURCE[0]}' From 3bc70a3e3cc1930a230cfc40763f3b2134ce30e1 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 22:04:15 +0100 Subject: [PATCH 117/162] 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 7760a3da0..d2c556fb6 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -170,7 +170,7 @@ _otel_filter_commands_by_hint() { _otel_resolve_instrumentation_hint() { local hint="$1" - { \[ -f "$hint" ] && \[ "$(\readlink -f "$hint")" != "$(\readlink -f "/proc/$$/exe")" ] && \[ "$(\readlink -f "$hint")" != "/usr/share/opentelemetry_shell/opentelemetry_shell.sh" ] && \cat "$hint" || \echo "$hint"; } | \tr -s ' $=";(){}/\\!#~^'\' '\n' | _otel_filter_by_validity | \sort -u + { \[ -f "$hint" ] && \[ "$(\readlink -f "$hint")" != "$(\readlink -f "/proc/$$/exe")" ] && \[ "$(\readlink -f "$hint")" != /usr/share/opentelemetry_shell/agent.sh ] && \cat "$hint" || \echo "$hint"; } | tee /dev/stderr | \tr -s ' $=";(){}/\\!#~^'\' '\n' | tee /dev/stderr | _otel_filter_by_validity | tee /dev/stderr | \sort -u | tee /dev/stderr } _otel_filter_commands_by_instrumentation() { From 6544d25afc1382494e3c722d886fceae7bbd93c3 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 11 Jan 2025 23:00:09 +0100 Subject: [PATCH 118/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index d2c556fb6..bcb3b9d84 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -170,7 +170,7 @@ _otel_filter_commands_by_hint() { _otel_resolve_instrumentation_hint() { local hint="$1" - { \[ -f "$hint" ] && \[ "$(\readlink -f "$hint")" != "$(\readlink -f "/proc/$$/exe")" ] && \[ "$(\readlink -f "$hint")" != /usr/share/opentelemetry_shell/agent.sh ] && \cat "$hint" || \echo "$hint"; } | tee /dev/stderr | \tr -s ' $=";(){}/\\!#~^'\' '\n' | tee /dev/stderr | _otel_filter_by_validity | tee /dev/stderr | \sort -u | tee /dev/stderr + { \[ -f "$hint" ] && \[ "$(\readlink -f "$hint")" != "$(\readlink -f "/proc/$$/exe")" ] && \[ "$(\readlink -f "$hint")" != /usr/share/opentelemetry_shell/agent.sh ] && \cat "$hint" || \echo "$hint"; } | \tr -s ' $=";(){}/\\!#~^'\' '\n' | _otel_filter_by_validity | \sort -u } _otel_filter_commands_by_instrumentation() { @@ -470,7 +470,8 @@ _otel_inject() { local instrumentation=_otel_observe fi \echo "DEBUG DEBUG DEBUG set -- $instrumentation $(_otel_escape_args "$@")" >&2 - \echo "DEBUG DEBUG DEBUG $(_otel_resolve_instrumentation_hint)" >&2 + \echo "DEBUG DEBUG DEBUG $(_otel_resolve_instrumentation_hint "$_otel_shell_auto_instrumentation_hint")" >&2 + \alias \eval "set -- $instrumentation $(_otel_escape_args "$@")" fi \eval "$(_otel_escape_args "$@")" From 408dae69532861495d82b93d1507f831ff2df7d3 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:17:54 +0100 Subject: [PATCH 119/162] 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 bcb3b9d84..6ceacc7ee 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -30,7 +30,6 @@ case "$-" in *) _otel_is_interactive=FALSE;; esac -set -x if \[ -n "${OTEL_SHELL_AUTO_INSTRUMENTATION_HINT:-}" ]; then _otel_shell_auto_instrumentation_hint="$OTEL_SHELL_AUTO_INSTRUMENTATION_HINT" unset OTEL_SHELL_AUTO_INSTRUMENTATION_HINT @@ -45,7 +44,6 @@ elif \[ -f "$0" ] && \[ "$(\readlink -f "$0")" != "$(\readlink -f "/proc/$$/exe" else _otel_shell_auto_instrumentation_hint="$(_otel_resolve_command_self)" fi -set +x if \[ "$_otel_shell" = "bash" ]; then _otel_source_file_resolver='${BASH_SOURCE[0]}' From 4ba5f9e1e6d96855acf8ff3c337dc91a6c3386e7 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:22:43 +0100 Subject: [PATCH 120/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index 6ceacc7ee..86acbb91d 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -459,6 +459,11 @@ _otel_inject() { _otel_inject() { if _otel_string_contains "$1" /; then + \echo "DEBUG DEBUG DEBUG $path ${path##*/}" >&2 + \echo "DEBUG DEBUG DEBUG $(_otel_resolve_instrumentation_hint "$_otel_shell_auto_instrumentation_hint")" >&2 + \alias >&2 + \echo "DEBUG DEBUG DEBUG $(\alias "${path##*/}")" >&2 + \echo "DEBUG DEBUG DEBUG $(_otel_resolve_alias "${path##*/}")" >&2 local path="$1" local instrumentation="$(_otel_resolve_alias "${path##*/}")" if \[ -n "$instrumentation" ]; then @@ -468,8 +473,6 @@ _otel_inject() { local instrumentation=_otel_observe fi \echo "DEBUG DEBUG DEBUG set -- $instrumentation $(_otel_escape_args "$@")" >&2 - \echo "DEBUG DEBUG DEBUG $(_otel_resolve_instrumentation_hint "$_otel_shell_auto_instrumentation_hint")" >&2 - \alias \eval "set -- $instrumentation $(_otel_escape_args "$@")" fi \eval "$(_otel_escape_args "$@")" From 06488c983eac4a3bd6b9d369d665e252beaa8afa Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:28:07 +0100 Subject: [PATCH 121/162] 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 86acbb91d..b59d8f843 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -459,12 +459,12 @@ _otel_inject() { _otel_inject() { if _otel_string_contains "$1" /; then + local path="$1" \echo "DEBUG DEBUG DEBUG $path ${path##*/}" >&2 \echo "DEBUG DEBUG DEBUG $(_otel_resolve_instrumentation_hint "$_otel_shell_auto_instrumentation_hint")" >&2 \alias >&2 \echo "DEBUG DEBUG DEBUG $(\alias "${path##*/}")" >&2 \echo "DEBUG DEBUG DEBUG $(_otel_resolve_alias "${path##*/}")" >&2 - local path="$1" local instrumentation="$(_otel_resolve_alias "${path##*/}")" if \[ -n "$instrumentation" ]; then local instrumentation="${instrumentation% *}" From 268eb2808a5cb2218e728b61be2610d1d94a5ff6 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:15:23 +0100 Subject: [PATCH 122/162] Update agent.sh --- src/usr/share/opentelemetry_shell/agent.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.sh b/src/usr/share/opentelemetry_shell/agent.sh index b59d8f843..8c78f3a0a 100755 --- a/src/usr/share/opentelemetry_shell/agent.sh +++ b/src/usr/share/opentelemetry_shell/agent.sh @@ -460,11 +460,6 @@ _otel_inject() { _otel_inject() { if _otel_string_contains "$1" /; then local path="$1" - \echo "DEBUG DEBUG DEBUG $path ${path##*/}" >&2 - \echo "DEBUG DEBUG DEBUG $(_otel_resolve_instrumentation_hint "$_otel_shell_auto_instrumentation_hint")" >&2 - \alias >&2 - \echo "DEBUG DEBUG DEBUG $(\alias "${path##*/}")" >&2 - \echo "DEBUG DEBUG DEBUG $(_otel_resolve_alias "${path##*/}")" >&2 local instrumentation="$(_otel_resolve_alias "${path##*/}")" if \[ -n "$instrumentation" ]; then local instrumentation="${instrumentation% *}" @@ -472,7 +467,6 @@ _otel_inject() { else local instrumentation=_otel_observe fi - \echo "DEBUG DEBUG DEBUG set -- $instrumentation $(_otel_escape_args "$@")" >&2 \eval "set -- $instrumentation $(_otel_escape_args "$@")" fi \eval "$(_otel_escape_args "$@")" From e1f9a3a1f1e2a9f730e48a97f4a131fa2816484c Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:17:09 +0100 Subject: [PATCH 123/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 86b85d2cb..0fbbeaba6 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -8,7 +8,7 @@ import os os.execl("/bin/echo", "echo", "hello", "world", "0") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 0"')" +span="$(resolve_span '.name == "/bin/echo hello world 0"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -17,7 +17,7 @@ import os os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 1"')" +span="$(resolve_span '.name == "/bin/echo hello world 1"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -26,7 +26,7 @@ import os os.spawnl(os.P_WAIT, "/bin/echo", "echo", "hello", "world", "2") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 2"')" +span="$(resolve_span '.name == "/bin/echo hello world 2"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -35,7 +35,7 @@ import os os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 3"')" +span="$(resolve_span '.name == "/bin/echo hello world 3"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -44,7 +44,7 @@ import os os.spawnv(os.P_WAIT, "/bin/echo", ["echo", "hello", "world", "4"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 4"')" +span="$(resolve_span '.name == "/bin/echo hello world 4"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -53,17 +53,17 @@ import os os.spawnvp(os.P_WAIT, "echo", ["echo", "hello", "world", "5"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 5"')" +span="$(resolve_span '.name == "/bin/echo hello world 5"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') printf '%s' ' import subprocess -with subprocess.Popen(["/usr/bin/echo", "hello", "world", "6"], stdout=subprocess.DEVNULL) as proc: +with subprocess.Popen(["/bin/echo", "hello", "world", "6"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 6"')" +span="$(resolve_span '.name == "/bin/echo hello world 6"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -74,21 +74,21 @@ pip3 install opentelemetry-distro opentelemetry-exporter-otlp opentelemetry-bootstrap --action install || exit 1 printf '%s' ' import subprocess -with subprocess.Popen(["/usr/bin/echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: +with subprocess.Popen(["/bin/echo", "hello", "world", "7"], stdout=subprocess.DEVNULL) as proc: pass ' | python3 assert_equals 0 $? deactivate -span="$(resolve_span '.name == "echo hello world 7"')" +span="$(resolve_span '.name == "/bin/echo hello world 7"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') echo ' import subprocess -subprocess.run(["/usr/bin/echo", "hello", "world", "8"]) +subprocess.run(["/bin/echo", "hello", "world", "8"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "echo hello world 8"')" +span="$(resolve_span '.name == "/bin/echo hello world 8"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') From 3ff5b0cc3d65f8924623f2088a67fe14007ff9ec Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 18:33:44 +0100 Subject: [PATCH 124/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 0fbbeaba6..a03ee35b2 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -17,7 +17,7 @@ import os os.execv("/bin/echo", [ "echo", "hello", "world", "1" ]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/bin/echo hello world 1"')" +span="$(resolve_span '.name | endswith("/echo hello world 1")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -26,7 +26,7 @@ import os os.spawnl(os.P_WAIT, "/bin/echo", "echo", "hello", "world", "2") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/bin/echo hello world 2"')" +span="$(resolve_span '.name | endswith("/echo hello world 2")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -35,7 +35,7 @@ import os os.spawnlp(os.P_WAIT, "echo", "echo", "hello", "world", "3") ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/bin/echo hello world 3"')" +span="$(resolve_span '.name | endswith("/echo hello world 3")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -44,7 +44,7 @@ import os os.spawnv(os.P_WAIT, "/bin/echo", ["echo", "hello", "world", "4"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/bin/echo hello world 4"')" +span="$(resolve_span '.name | endswith("/echo hello world 4")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -53,7 +53,7 @@ import os os.spawnvp(os.P_WAIT, "echo", ["echo", "hello", "world", "5"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/bin/echo hello world 5"')" +span="$(resolve_span '.name | endswith("/echo hello world 5")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -63,7 +63,7 @@ with subprocess.Popen(["/bin/echo", "hello", "world", "6"], stdout=subprocess.DE pass ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/bin/echo hello world 6"')" +span="$(resolve_span '.name | endswith("/echo hello world 6")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -79,7 +79,7 @@ with subprocess.Popen(["/bin/echo", "hello", "world", "7"], stdout=subprocess.DE ' | python3 assert_equals 0 $? deactivate -span="$(resolve_span '.name == "/bin/echo hello world 7"')" +span="$(resolve_span '.name | endswith("/echo hello world 7")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') @@ -88,7 +88,7 @@ import subprocess subprocess.run(["/bin/echo", "hello", "world", "8"]) ' | python3 assert_equals 0 $? -span="$(resolve_span '.name == "/bin/echo hello world 8"')" +span="$(resolve_span '.name | endswith("/echo hello world 8")')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') From 0e43b1d81665e73c8779b3df836204b3ca9bac4b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 19:42:32 +0100 Subject: [PATCH 125/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 9e9b96497..6f8b58a6c 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -78,6 +78,8 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = list(args) if len(args) > 0 and type(args[0]) is list: args = args[0] + if len(args) > 0 and type(args[0]) is tuple: + args = list(args[0]) print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) args = ([ inject_file(kwargs.get('executable', args[0])) ] + inject_arguments(kwargs.get('executable', args[0]), args[1:], not kwargs.get('shell', False))) if kwargs.get('executable'): From aa105b18ccc234aea268368bba4158cef16a1f82 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 20:05:48 +0100 Subject: [PATCH 126/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 6f8b58a6c..81ec3b2be 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -80,7 +80,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = args[0] if len(args) > 0 and type(args[0]) is tuple: args = list(args[0]) - print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) + # print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) args = ([ inject_file(kwargs.get('executable', args[0])) ] + inject_arguments(kwargs.get('executable', args[0]), args[1:], not kwargs.get('shell', False))) if kwargs.get('executable'): kwargs['executable'] = inject_file(kwargs['executable']) @@ -90,8 +90,8 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False - print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) - kwargs['stderr'] = sys.stderr + # print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) + # kwargs['stderr'] = sys.stderr return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From 3508eaad10ce99971324a178594b307c5633fa52 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 20:56:13 +0100 Subject: [PATCH 127/162] Update agent.instrumentation.python.deep.py --- .../agent.instrumentation.python.deep.py | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 81ec3b2be..6ce137720 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -2,6 +2,12 @@ import os import subprocess +def inject_env_minimal(env, args): + env['OTEL_SHELL_AUTO_INSTRUMENTATION_HINT'] = ' '.join(args) + env['OTEL_SHELL_COMMANDLINE_OVERRIDE'] = '/bin/sh -c ' + ' '.join(args) + env['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) + return env + try: import opentelemetry from opentelemetry.context import attach @@ -15,9 +21,7 @@ attach(new_context) def inject_env(env, args): - if not env: - env = os.environ.copy() - env['OTEL_SHELL_AUTO_INSTRUMENTATION_HINT'] = ' '.join(args) + env = inject_env_minimal(env, args) carrier = {} tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) if 'traceparent' in carrier: @@ -28,16 +32,10 @@ def inject_env(env, args): except ModuleNotFoundError: def inject_env(env, args): - if not env: - env = os.environ.copy() - env['OTEL_SHELL_AUTO_INSTRUMENTATION_HINT'] = ' '.join(args) - return env + return inject_env_minimal(env, args) import functools -def inject_file(file): - return '/bin/sh' - def inject_arguments(file, args, is_file=True): try: file = file.decode() @@ -55,23 +53,26 @@ def inject_arguments(file, args, is_file=True): arg_zero = 'python' return [ '-c', '. otel.sh\n' + file + ' "$@"', arg_zero ] + args +def inject_file(file): + return '/bin/sh' + original_os_execve = os.execve original_subprocess_Popen___init__ = subprocess.Popen.__init__ def observed_os_execv(file, args): if type(args) is tuple: args = list(args) + env = inject_env(os.environ.copy(), args) args = [ args[0] ] + inject_arguments(file, args[1:]) file = inject_file(file) - env = inject_env(None, args) return original_os_execve(file, args, env) def observed_os_execve(file, args, env): if type(args) is tuple: args = list(args) + env = inject_env(env, args) args = [ args[0] ] + inject_arguments(file, args[1:]) file = inject_file(file) - env = inject_env(env, args) return original_os_execve(file, args, env) def observed_subprocess_Popen___init__(self, *args, **kwargs): @@ -80,18 +81,13 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = args[0] if len(args) > 0 and type(args[0]) is tuple: args = list(args[0]) - # print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) + kwargs['env'] = inject_env(kwargs.get('env', os.environ.copy()), args) args = ([ inject_file(kwargs.get('executable', args[0])) ] + inject_arguments(kwargs.get('executable', args[0]), args[1:], not kwargs.get('shell', False))) if kwargs.get('executable'): kwargs['executable'] = inject_file(kwargs['executable']) - kwargs['env'] = inject_env(kwargs.get('env', None), args) if kwargs.get('shell', False): - kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE'] = '/bin/sh -c ' + ' '.join(args) - kwargs['env']['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False - # print('subprocess.Popen([' + ','.join(args) + '],' + str(kwargs) + ')', file=sys.stderr) - # kwargs['stderr'] = sys.stderr return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From bfd390fad09f6f90ce9b8030e5d97ec5342260d8 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 21:26:08 +0100 Subject: [PATCH 128/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 6ce137720..56ace2244 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -4,7 +4,7 @@ def inject_env_minimal(env, args): env['OTEL_SHELL_AUTO_INSTRUMENTATION_HINT'] = ' '.join(args) - env['OTEL_SHELL_COMMANDLINE_OVERRIDE'] = '/bin/sh -c ' + ' '.join(args) + env['OTEL_SHELL_COMMANDLINE_OVERRIDE'] = ' '.join(args) env['OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE'] = str(os.getpid()) return env From 8f0230295dc89235d9362826b704e78748ff482e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sun, 12 Jan 2025 21:28:44 +0100 Subject: [PATCH 129/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 56ace2244..cf06d2f71 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -21,14 +21,13 @@ def inject_env_minimal(env, args): attach(new_context) def inject_env(env, args): - env = inject_env_minimal(env, args) carrier = {} tracecontext.TraceContextTextMapPropagator().inject(carrier, opentelemetry.trace.set_span_in_context(opentelemetry.trace.get_current_span(), None)) if 'traceparent' in carrier: env["OTEL_TRACEPARENT"] = carrier["traceparent"] if 'tracestate' in carrier: env["OTEL_TRACESTATE"] = carrier["tracestate"] - return env; + return inject_env_minimal(env, args) except ModuleNotFoundError: def inject_env(env, args): From 7afe695e3b2261019420a41978d92a1c38778a62 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:21:06 +0100 Subject: [PATCH 130/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 155 ++++++++++---------- 1 file changed, 81 insertions(+), 74 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index a03ee35b2..e1ebbd6b0 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,6 +3,87 @@ if ! which python3; then exit 0; fi . otel.sh +export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE + +echo ' +import requests +requests.get("http://example.com/foo") +' | python3 | grep -v -F '"parent_id": null,' | grep -- '/foo' || exit 1 + +python3 -c ' +import requests +requests.get("http://example.com/bar") +' | grep -v -F '"parent_id": null,' | grep -- '/bar' || exit 1 + +echo ' +import requests +requests.get("http://example.com/baz") +' > script.py +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 +. "$dir"/venv/bin/activate +pip install requests +echo ' +import requests +requests.get("http://example.com/venv") +' | python | grep -v -F '"parent_id": null,' | grep -- '/venv' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv --system-site-packages "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip3 install requests +pip3 install opentelemetry-distro opentelemetry-exporter-otlp +opentelemetry-bootstrap --action install || exit 1 +script=$(mktemp -u).py +echo ' +import requests +requests.get("http://example.com/instrumented") +' | opentelemetry-instrument python3 | grep -v -F '"parent_id": null,' | grep -- '/instrumented' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip install requests +echo ' +import requests +requests.get("http://example.com/venv_deep_stdin") +' | python | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_stdin' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip install requests +python -c ' +import requests +requests.get("http://example.com/venv_deep_c") +' | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_c' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip install requests +echo ' +import requests +requests.get("http://example.com/venv_deep_file") +' > "$dir"/script.py +python "$dir"/script.py | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_file' || exit 1 +deactivate + +exit 0 + + + + + +#### move to front + + echo ' import os os.execl("/bin/echo", "echo", "hello", "world", "0") @@ -109,77 +190,3 @@ assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 10"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') - -export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE - -echo ' -import requests -requests.get("http://example.com/foo") -' | python3 | grep -v -F '"parent_id": null,' | grep -- '/foo' || exit 1 - -python3 -c ' -import requests -requests.get("http://example.com/bar") -' | grep -v -F '"parent_id": null,' | grep -- '/bar' || exit 1 - -echo ' -import requests -requests.get("http://example.com/baz") -' > script.py -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 -. "$dir"/venv/bin/activate -pip install requests -echo ' -import requests -requests.get("http://example.com/venv") -' | python | grep -v -F '"parent_id": null,' | grep -- '/venv' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv --system-site-packages "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate -pip3 install requests -pip3 install opentelemetry-distro opentelemetry-exporter-otlp -opentelemetry-bootstrap --action install || exit 1 -script=$(mktemp -u).py -echo ' -import requests -requests.get("http://example.com/instrumented") -' | opentelemetry-instrument python3 | grep -v -F '"parent_id": null,' | grep -- '/instrumented' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate -pip install requests -echo ' -import requests -requests.get("http://example.com/venv_deep_stdin") -' | python | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_stdin' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate -pip install requests -python -c ' -import requests -requests.get("http://example.com/venv_deep_c") -' | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_c' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate -pip install requests -echo ' -import requests -requests.get("http://example.com/venv_deep_file") -' > "$dir"/script.py -python "$dir"/script.py | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_file' || exit 1 -deactivate - -exit 0 From e43bc0fb346df710a5e11b2bd0d53c8eb5db7b15 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:32:48 +0100 Subject: [PATCH 131/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 641f179c3..7fb4d6bc9 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -2,6 +2,7 @@ _otel_inject_python() { if \[ -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 +\echo "DEBUG DEBUG DEBUG injecting into $*" >&2 local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" if _otel_python_is_customize_injectable && \false; then From 52706f94b6cd457bc37a37ed850dac32bb5581a3 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:40:19 +0100 Subject: [PATCH 132/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 7fb4d6bc9..641f179c3 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -2,7 +2,6 @@ _otel_inject_python() { if \[ -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 -\echo "DEBUG DEBUG DEBUG injecting into $*" >&2 local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" if _otel_python_is_customize_injectable && \false; then From 70716ec536cf48279611a1d264ef9e11cc318ff5 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:44:08 +0100 Subject: [PATCH 133/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 147 ++++++++++---------- 1 file changed, 73 insertions(+), 74 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index e1ebbd6b0..c4f599d1b 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -3,86 +3,13 @@ if ! which python3; then exit 0; fi . otel.sh -export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE - -echo ' -import requests -requests.get("http://example.com/foo") -' | python3 | grep -v -F '"parent_id": null,' | grep -- '/foo' || exit 1 - -python3 -c ' -import requests -requests.get("http://example.com/bar") -' | grep -v -F '"parent_id": null,' | grep -- '/bar' || exit 1 - -echo ' -import requests -requests.get("http://example.com/baz") -' > script.py -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 -. "$dir"/venv/bin/activate -pip install requests -echo ' -import requests -requests.get("http://example.com/venv") -' | python | grep -v -F '"parent_id": null,' | grep -- '/venv' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv --system-site-packages "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate pip3 install requests -pip3 install opentelemetry-distro opentelemetry-exporter-otlp -opentelemetry-bootstrap --action install || exit 1 -script=$(mktemp -u).py -echo ' -import requests -requests.get("http://example.com/instrumented") -' | opentelemetry-instrument python3 | grep -v -F '"parent_id": null,' | grep -- '/instrumented' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate -pip install requests -echo ' -import requests -requests.get("http://example.com/venv_deep_stdin") -' | python | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_stdin' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv "$dir"/venv || exit 1 -. "$dir"/venv/bin/activate -pip install requests -python -c ' -import requests -requests.get("http://example.com/venv_deep_c") -' | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_c' || exit 1 -deactivate - -dir=$(mktemp -d) -python3 -m venv "$dir"/venv || exit 1 . "$dir"/venv/bin/activate -pip install requests -echo ' -import requests -requests.get("http://example.com/venv_deep_file") -' > "$dir"/script.py -python "$dir"/script.py | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_file' || exit 1 deactivate -exit 0 - - - - - -#### move to front - +exit 1 echo ' import os @@ -190,3 +117,75 @@ assert_equals 0 $? span="$(resolve_span '.name == "echo hello world 10"')" assert_equals "SpanKind.INTERNAL" $(\echo "$span" | \jq -r '.kind') assert_not_equals null $(\echo "$span" | \jq -r '.parent_id') + +export OTEL_SHELL_CONFIG_INJECT_DEEP=TRUE + +echo ' +import requests +requests.get("http://example.com/foo") +' | python3 | grep -v -F '"parent_id": null,' | grep -- '/foo' || exit 1 + +python3 -c ' +import requests +requests.get("http://example.com/bar") +' | grep -v -F '"parent_id": null,' | grep -- '/bar' || exit 1 + +echo ' +import requests +requests.get("http://example.com/baz") +' > script.py +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 +. "$dir"/venv/bin/activate +pip install requests +echo ' +import requests +requests.get("http://example.com/venv") +' | python | grep -v -F '"parent_id": null,' | grep -- '/venv' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv --system-site-packages "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip3 install requests +pip3 install opentelemetry-distro opentelemetry-exporter-otlp +opentelemetry-bootstrap --action install || exit 1 +script=$(mktemp -u).py +echo ' +import requests +requests.get("http://example.com/instrumented") +' | opentelemetry-instrument python3 | grep -v -F '"parent_id": null,' | grep -- '/instrumented' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip install requests +echo ' +import requests +requests.get("http://example.com/venv_deep_stdin") +' | python | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_stdin' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip install requests +python -c ' +import requests +requests.get("http://example.com/venv_deep_c") +' | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_c' || exit 1 +deactivate + +dir=$(mktemp -d) +python3 -m venv "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate +pip install requests +echo ' +import requests +requests.get("http://example.com/venv_deep_file") +' > "$dir"/script.py +python "$dir"/script.py | grep -v -F '"parent_id": null,' | grep -- '/venv_deep_file' || exit 1 +deactivate From eacfa4d7c11108a2860aab88509c8864766f818b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:50:32 +0100 Subject: [PATCH 134/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index c4f599d1b..4cf63712e 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -5,9 +5,9 @@ if ! which python3; then exit 0; fi dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 +set -x pip3 install requests -. "$dir"/venv/bin/activate -deactivate +set +x exit 1 From 79e6f483f60e8ffe9c2ab2dea262e954781c211e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:57:41 +0100 Subject: [PATCH 135/162] 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 4cf63712e..8c82abb86 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -5,9 +5,11 @@ if ! which python3; then exit 0; fi dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 +. "$dir"/venv/bin/activate set -x pip3 install requests set +x +deactivate exit 1 From 4364a955daa5ae75b77c2ecb6ad5a9e60bfb0f80 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 15:12:26 +0100 Subject: [PATCH 136/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 8c82abb86..5b2c24e52 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -6,6 +6,9 @@ if ! which python3; then exit 0; fi dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate +\alias pip3 +\unalias pip3 +\which pip3 set -x pip3 install requests set +x From b4cd7615fea3e11fe3e00c7369a4f227c60f67a5 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 15:37:14 +0100 Subject: [PATCH 137/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 5b2c24e52..24ea905aa 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -9,6 +9,10 @@ python3 -m venv --system-site-packages "$dir"/venv || exit 1 \alias pip3 \unalias pip3 \which pip3 +\. "$dir"/venv/bin/activate +\alias pip3 +\unalias pip3 +\which pip3 set -x pip3 install requests set +x From 153c0a80c1648f17df6efc032a5d75ba60faff9b Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:15:11 +0100 Subject: [PATCH 138/162] Update test_auto_injection_python.shell --- tests/auto/test_auto_injection_python.shell | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/auto/test_auto_injection_python.shell b/tests/auto/test_auto_injection_python.shell index 24ea905aa..da893e661 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -6,12 +6,8 @@ if ! which python3; then exit 0; fi dir=$(mktemp -d) python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate +\echo "$PATH" \alias pip3 -\unalias pip3 -\which pip3 -\. "$dir"/venv/bin/activate -\alias pip3 -\unalias pip3 \which pip3 set -x pip3 install requests From 180a3904d901f74d41d130ae1e2a90c65ed08934 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:23:15 +0100 Subject: [PATCH 139/162] 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 da893e661..2cd91ccbd 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -10,7 +10,7 @@ python3 -m venv --system-site-packages "$dir"/venv || exit 1 \alias pip3 \which pip3 set -x -pip3 install requests +\pip3 install requests set +x deactivate From 564f7ef738abdee8f1ba4a5b23cd8a70b3f315f9 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:27:58 +0100 Subject: [PATCH 140/162] 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 2cd91ccbd..29bde8e7d 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -4,7 +4,7 @@ if ! which python3; then exit 0; fi . otel.sh dir=$(mktemp -d) -python3 -m venv --system-site-packages "$dir"/venv || exit 1 +\python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate \echo "$PATH" \alias pip3 From 89d8be71e6369114e527241c73a881fcf871f2bb Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:32:45 +0100 Subject: [PATCH 141/162] 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 29bde8e7d..852d1fa26 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -10,7 +10,7 @@ dir=$(mktemp -d) \alias pip3 \which pip3 set -x -\pip3 install requests +pip3 install requests set +x deactivate From 7382bc91425cf9e4f233cf894c4af16ff626f981 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:41:54 +0100 Subject: [PATCH 142/162] 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 852d1fa26..1bff6da08 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -4,14 +4,12 @@ if ! which python3; then exit 0; fi . otel.sh dir=$(mktemp -d) -\python3 -m venv --system-site-packages "$dir"/venv || exit 1 +python3 -m venv --system-site-packages "$dir"/venv || exit 1 . "$dir"/venv/bin/activate \echo "$PATH" \alias pip3 \which pip3 -set -x pip3 install requests -set +x deactivate exit 1 From b8fc9938e560e28c44d57ad0afb9e668d9cd9608 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:44:05 +0100 Subject: [PATCH 143/162] 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 1bff6da08..081f379e8 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -9,7 +9,7 @@ python3 -m venv --system-site-packages "$dir"/venv || exit 1 \echo "$PATH" \alias pip3 \which pip3 -pip3 install requests +pip3 install requests 2>&1 | grep writable && exit 1 deactivate exit 1 From 4e69498b6b513ed324d01d94363300b672c373f9 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:48:46 +0100 Subject: [PATCH 144/162] 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 081f379e8..94e621de6 100755 --- a/tests/auto/test_auto_injection_python.shell +++ b/tests/auto/test_auto_injection_python.shell @@ -12,8 +12,6 @@ python3 -m venv --system-site-packages "$dir"/venv || exit 1 pip3 install requests 2>&1 | grep writable && exit 1 deactivate -exit 1 - echo ' import os os.execl("/bin/echo", "echo", "hello", "world", "0") From 146898f69126349a6dbf20fc16cb7c1a7e06c09e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 16:55:30 +0100 Subject: [PATCH 145/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index cf06d2f71..f02b5b3e1 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -80,6 +80,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = args[0] if len(args) > 0 and type(args[0]) is tuple: args = list(args[0]) + original_args = args kwargs['env'] = inject_env(kwargs.get('env', os.environ.copy()), args) args = ([ inject_file(kwargs.get('executable', args[0])) ] + inject_arguments(kwargs.get('executable', args[0]), args[1:], not kwargs.get('shell', False))) if kwargs.get('executable'): @@ -87,6 +88,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if kwargs.get('shell', False): kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False + print('subprocess.Popen(' + str(original_args) + ' => ' + str(args) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From 87eeadb59497a32b6318ea48d3c74ca96a525e77 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 17:02:54 +0100 Subject: [PATCH 146/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 641f179c3..3d25e0cfb 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -1,7 +1,7 @@ #!/bin/false -_otel_inject_python() { - if \[ -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 +_otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip'] => ['/bin/sh', '-c', '. otel.sh\n_otel_inject \'/tmp/tmp.TAwDcuoM1r/venv/bin/python3\' "$@"', '/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']) + if \[ -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 && ! \[ "${3:-}" = ensurepip ]; then local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" if _otel_python_is_customize_injectable && \false; then From 60a19c34b51c876dae96c1d91eacaaa3107f5679 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:08:54 +0100 Subject: [PATCH 147/162] Update agent.instrumentation.python.sh --- .../agent.instrumentation.python.sh | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 3d25e0cfb..60c3204bd 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -4,25 +4,17 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python if \[ -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 && ! \[ "${3:-}" = ensurepip ]; then local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" - if _otel_python_is_customize_injectable && \false; then - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then - local command="$1"; shift - set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" - fi - 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_python_inject_args "$@" > /dev/null + \eval "set -- $(_otel_python_inject_args "$@")" + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + local command="$1"; shift + set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" + fi + 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 "$@" else - _otel_python_inject_args "$@" > /dev/null - \eval "set -- $(_otel_python_inject_args "$@")" - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then - local command="$1"; shift - set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" - fi - 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 "$@" - 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 "$@" - fi + 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 else _otel_call "$@" From 0ab215e74df43770df23f95d831d1ae73afb8471 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:13:51 +0100 Subject: [PATCH 148/162] Update agent.instrumentation.python.sh --- .../agent.instrumentation.python.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 60c3204bd..5a84b877d 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -1,7 +1,7 @@ #!/bin/false _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip'] => ['/bin/sh', '-c', '. otel.sh\n_otel_inject \'/tmp/tmp.TAwDcuoM1r/venv/bin/python3\' "$@"', '/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']) - if \[ -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 && ! \[ "${3:-}" = ensurepip ]; then + if \[ -d "/opt/opentelemetry_shell/venv" ] && _otel_string_starts_with "$(\eval "$1 -V" | \cut -d ' ' -f 2)" "3."; then local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" _otel_python_inject_args "$@" > /dev/null @@ -10,11 +10,15 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi + local python_path="${PYTHONPATH:-}" + if ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! \[ "${3:-}" = ensurepip ]; then + local python_path=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$python_path" + fi 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="$python_path" 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="$python_path" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@" fi else _otel_call "$@" From 43fa038ed528eb299cdf94dfd22f36561890538e Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:19:40 +0100 Subject: [PATCH 149/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index f02b5b3e1..9597afb78 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -88,7 +88,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if kwargs.get('shell', False): kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False - print('subprocess.Popen(' + str(original_args) + ' => ' + str(args) + ')', file=sys.stderr) + # print('subprocess.Popen(' + str(original_args) + ' => ' + str(args) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From 1f7b10e16f976d98458a4f4cb0f8d576786d86d1 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:32:38 +0100 Subject: [PATCH 150/162] Update agent.instrumentation.python.sh --- .../opentelemetry_shell/agent.instrumentation.python.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 5a84b877d..f19075aaa 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -6,13 +6,13 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python local cmdline="${cmdline#\\}" _otel_python_inject_args "$@" > /dev/null \eval "set -- $(_otel_python_inject_args "$@")" - if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then - local command="$1"; shift - set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" - fi local python_path="${PYTHONPATH:-}" if ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! \[ "${3:-}" = ensurepip ]; then local python_path=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$python_path" + if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then + local command="$1"; shift + set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" + fi fi if \[ "${_otel_python_code_source:-}" = stdin ]; then unset _otel_python_code_source From 392ec9fd0fe212f8459e0d2c16c8c3c4734cfd94 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:38:35 +0100 Subject: [PATCH 151/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index f19075aaa..7bb668dad 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -7,7 +7,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python _otel_python_inject_args "$@" > /dev/null \eval "set -- $(_otel_python_inject_args "$@")" local python_path="${PYTHONPATH:-}" - if ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! \[ "${3:-}" = ensurepip ]; then + if ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! (\[ "${2:-}" = -m ] && \[ "${3:-}" = ensurepip ]); then local python_path=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$python_path" if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift From 91c86657afcb58ab81af15303056d4568514b2fa Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:39:00 +0100 Subject: [PATCH 152/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 9597afb78..f02b5b3e1 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -88,7 +88,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if kwargs.get('shell', False): kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False - # print('subprocess.Popen(' + str(original_args) + ' => ' + str(args) + ')', file=sys.stderr) + print('subprocess.Popen(' + str(original_args) + ' => ' + str(args) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From d7d4008f6ce36510b2157da59188875f7093c505 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:40:06 +0100 Subject: [PATCH 153/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index f02b5b3e1..5d8d254ab 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -61,6 +61,7 @@ def inject_file(file): def observed_os_execv(file, args): if type(args) is tuple: args = list(args) + print('os.execv(' + str(args) + ')', file=sys.stderr) env = inject_env(os.environ.copy(), args) args = [ args[0] ] + inject_arguments(file, args[1:]) file = inject_file(file) @@ -69,6 +70,7 @@ def observed_os_execv(file, args): def observed_os_execve(file, args, env): if type(args) is tuple: args = list(args) + print('os.execve(' + str(args) + ')', file=sys.stderr) env = inject_env(env, args) args = [ args[0] ] + inject_arguments(file, args[1:]) file = inject_file(file) @@ -80,7 +82,7 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): args = args[0] if len(args) > 0 and type(args[0]) is tuple: args = list(args[0]) - original_args = args + print('subprocess.Popen(' + str(args) + ')', file=sys.stderr) kwargs['env'] = inject_env(kwargs.get('env', os.environ.copy()), args) args = ([ inject_file(kwargs.get('executable', args[0])) ] + inject_arguments(kwargs.get('executable', args[0]), args[1:], not kwargs.get('shell', False))) if kwargs.get('executable'): @@ -88,7 +90,6 @@ def observed_subprocess_Popen___init__(self, *args, **kwargs): if kwargs.get('shell', False): kwargs['env']['OTEL_SHELL_AUTO_INJECTED'] = 'FALSE' kwargs['shell'] = False - print('subprocess.Popen(' + str(original_args) + ' => ' + str(args) + ')', file=sys.stderr) return original_subprocess_Popen___init__(self, args, **kwargs); os.execv = observed_os_execv From 53fe91a9035ff081559a4ba1e05d39c34c7f6dbe Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 19:55:28 +0100 Subject: [PATCH 154/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 7bb668dad..111655d4c 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -7,7 +7,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python _otel_python_inject_args "$@" > /dev/null \eval "set -- $(_otel_python_inject_args "$@")" local python_path="${PYTHONPATH:-}" - if ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! (\[ "${2:-}" = -m ] && \[ "${3:-}" = ensurepip ]); then + if \alse && ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! (\[ "${2:-}" = -m ] && \[ "${3:-}" = ensurepip ]); then local python_path=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$python_path" if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift From 6a1f80f95b9bb414919dff2c1d90fff9d64f2e65 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 20:03:33 +0100 Subject: [PATCH 155/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 111655d4c..f05685283 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -7,7 +7,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python _otel_python_inject_args "$@" > /dev/null \eval "set -- $(_otel_python_inject_args "$@")" local python_path="${PYTHONPATH:-}" - if \alse && ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! (\[ "${2:-}" = -m ] && \[ "${3:-}" = ensurepip ]); then + if \false && ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! (\[ "${2:-}" = -m ] && \[ "${3:-}" = ensurepip ]); then local python_path=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$python_path" if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift From 6e7418b9f5282a9607266a58b83ae2df41951386 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 20:08:26 +0100 Subject: [PATCH 156/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index f05685283..9023bcbd0 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -2,6 +2,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip'] => ['/bin/sh', '-c', '. otel.sh\n_otel_inject \'/tmp/tmp.TAwDcuoM1r/venv/bin/python3\' "$@"', '/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']) if \[ -d "/opt/opentelemetry_shell/venv" ] && _otel_string_starts_with "$(\eval "$1 -V" | \cut -d ' ' -f 2)" "3."; then +\echo "DEBUG DEBUG DEBUG $*" >&2 local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" _otel_python_inject_args "$@" > /dev/null From 2fa1c291e21d13f9d7d001990231c5ebf87b6995 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 21:09:00 +0100 Subject: [PATCH 157/162] Update agent.instrumentation.python.deep.py --- .../opentelemetry_shell/agent.instrumentation.python.deep.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py index 5d8d254ab..aae438a53 100644 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.deep.py @@ -61,7 +61,7 @@ def inject_file(file): def observed_os_execv(file, args): if type(args) is tuple: args = list(args) - print('os.execv(' + str(args) + ')', file=sys.stderr) + # print('os.execv(' + str(args) + ')', file=sys.stderr) env = inject_env(os.environ.copy(), args) args = [ args[0] ] + inject_arguments(file, args[1:]) file = inject_file(file) @@ -70,7 +70,7 @@ def observed_os_execv(file, args): def observed_os_execve(file, args, env): if type(args) is tuple: args = list(args) - print('os.execve(' + str(args) + ')', file=sys.stderr) + # print('os.execve(' + str(args) + ')', file=sys.stderr) env = inject_env(env, args) args = [ args[0] ] + inject_arguments(file, args[1:]) file = inject_file(file) From 36cce5b824d7bd7bafa9b94725347e117ce7f8db Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 21:13:07 +0100 Subject: [PATCH 158/162] Update agent.instrumentation.python.sh --- .../opentelemetry_shell/agent.instrumentation.python.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 9023bcbd0..a9ebeaf27 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -2,19 +2,20 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip'] => ['/bin/sh', '-c', '. otel.sh\n_otel_inject \'/tmp/tmp.TAwDcuoM1r/venv/bin/python3\' "$@"', '/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']) if \[ -d "/opt/opentelemetry_shell/venv" ] && _otel_string_starts_with "$(\eval "$1 -V" | \cut -d ' ' -f 2)" "3."; then -\echo "DEBUG DEBUG DEBUG $*" >&2 +\echo "DEBUG DEBUG DEBUG 0 $*" >&2 local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" _otel_python_inject_args "$@" > /dev/null \eval "set -- $(_otel_python_inject_args "$@")" local python_path="${PYTHONPATH:-}" - if \false && ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! (\[ "${2:-}" = -m ] && \[ "${3:-}" = ensurepip ]); then + if ! _otel_string_ends_with "${2:-}" /pip && ! _otel_string_ends_with "${2:-}" /pip3 && ! (\[ "${2:-}" = -m ] && \[ "${3:-}" = ensurepip ]); then local python_path=/opt/opentelemetry_shell/venv/lib/"$(\ls /opt/opentelemetry_shell/venv/lib/)"/site-packages/:"$python_path" if \[ "${OTEL_SHELL_CONFIG_INJECT_DEEP:-FALSE}" = TRUE ]; then local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi fi +\echo "DEBUG DEBUG DEBUG 1 $*" >&2 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="$python_path" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@" From 8bd0134a55cef079be91d6e23b54723944b66334 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 21:13:49 +0100 Subject: [PATCH 159/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index a9ebeaf27..80eba8385 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -2,7 +2,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip'] => ['/bin/sh', '-c', '. otel.sh\n_otel_inject \'/tmp/tmp.TAwDcuoM1r/venv/bin/python3\' "$@"', '/tmp/tmp.TAwDcuoM1r/venv/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']) if \[ -d "/opt/opentelemetry_shell/venv" ] && _otel_string_starts_with "$(\eval "$1 -V" | \cut -d ' ' -f 2)" "3."; then -\echo "DEBUG DEBUG DEBUG 0 $*" >&2 +\echo "DEBUG DEBUG DEBUG $*" >&2 local cmdline="$(_otel_dollar_star "$@")" local cmdline="${cmdline#\\}" _otel_python_inject_args "$@" > /dev/null @@ -15,7 +15,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi fi -\echo "DEBUG DEBUG DEBUG 1 $*" >&2 +\echo "DEBUG DEBUG DEBUG PYTHON_PATH=$python_path $*" >&2 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="$python_path" OTEL_BSP_MAX_EXPORT_BATCH_SIZE=1 _otel_call "$@" From f881ebb4fa720143d2cc85ef5b7a85cf41e077d9 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 22:55:48 +0100 Subject: [PATCH 160/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 80eba8385..444c91648 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -14,6 +14,8 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python local command="$1"; shift set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi + else + local python_path="$(\printf '%s' "$python_path" | \tr ':' '\n' | grep -v '^/opt/opentelemetry_shell/venv/lib/' | tr '\n' ':')" fi \echo "DEBUG DEBUG DEBUG PYTHON_PATH=$python_path $*" >&2 if \[ "${_otel_python_code_source:-}" = stdin ]; then From bac647c2fc1f4d42a4a91697540d4659b23000f3 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Fri, 24 Jan 2025 23:04:37 +0100 Subject: [PATCH 161/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index 444c91648..e43a8d731 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -15,7 +15,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi else - local python_path="$(\printf '%s' "$python_path" | \tr ':' '\n' | grep -v '^/opt/opentelemetry_shell/venv/lib/' | tr '\n' ':')" + local python_path="$(\printf '%s' "$python_path" | \tr ':' '\n' | \grep -v '^/opt/opentelemetry_shell/venv/lib/' | \tr '\n' ':')" fi \echo "DEBUG DEBUG DEBUG PYTHON_PATH=$python_path $*" >&2 if \[ "${_otel_python_code_source:-}" = stdin ]; then From c44adbc1e22959fcdd63e25f84ea113c16f38135 Mon Sep 17 00:00:00 2001 From: Philipp Lengauer <100447901+plengauer@users.noreply.github.com> Date: Sat, 25 Jan 2025 01:37:48 +0100 Subject: [PATCH 162/162] Update agent.instrumentation.python.sh --- .../share/opentelemetry_shell/agent.instrumentation.python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh index e43a8d731..c595b2cbf 100755 --- a/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh +++ b/src/usr/share/opentelemetry_shell/agent.instrumentation.python.sh @@ -15,7 +15,7 @@ _otel_inject_python() { # subprocess.Popen(['/tmp/tmp.TAwDcuoM1r/venv/bin/python set -- "$command" /opt/opentelemetry_shell/venv/bin/opentelemetry-instrument "${command#\\}" "$@" fi else - local python_path="$(\printf '%s' "$python_path" | \tr ':' '\n' | \grep -v '^/opt/opentelemetry_shell/venv/lib/' | \tr '\n' ':')" + local python_path="$(\printf '%s' "$python_path" | \tr ':' '\n' | \grep -vE '^/opt/opentelemetry_shell/venv/lib/' | \tr '\n' ':')" fi \echo "DEBUG DEBUG DEBUG PYTHON_PATH=$python_path $*" >&2 if \[ "${_otel_python_code_source:-}" = stdin ]; then