Skip to content

Commit

Permalink
Improve action test
Browse files Browse the repository at this point in the history
  • Loading branch information
plengauer authored Dec 17, 2024
1 parent 8eeb1cf commit e9f8922
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,14 @@ jobs:
OTEL_METRICS_EXPORTER: console
OTEL_LOGS_EXPORTER: console
OTEL_TRACES_EXPORTER: console
- run: echo hello world # check if simple command fails
- run: sudo apt-get update
- run: | # check if install succeeded
type otel.sh && type strace
- run: | # check if instrumentation happened
[ "$(alias | grep '_otel_observe' | wc -l)" -gt 0 ]
- run: | # check if traceparent is injected
[ -n "$TRACEPARENT" ]
- run: echo hello world # check if simple command fails
- run: sudo apt-get update # check if complex command fails
- uses: actions/download-artifact@v4 # check if node action works
with:
name: packages
Expand Down
2 changes: 1 addition & 1 deletion src/usr/share/opentelemetry_shell/api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ otel_observe() {
otel_span_activate "$span_handle"
local exit_code=0
local call_command=_otel_call
if \[ "${OTEL_SHELL_CONFIG_OBSERVE_SUBPROCESSES:-FALSE}" = TRUE ] || \[ "${OTEL_SHELL_CONFIG_OBSERVE_SIGNALS:-FALSE}" = TRUE ]; then if ! _otel_string_starts_with "$1" _otel_ && \type strace 1> /dev/null 2> /dev/null; then local call_command="_otel_call_and_record_subprocesses $span_handle $call_command"; fi; fi
if \[ "${OTEL_SHELL_CONFIG_OBSERVE_SUBPROCESSES:-FALSE}" = TRUE ] || \[ "${OTEL_SHELL_CONFIG_OBSERVE_SIGNALS:-FALSE}" = TRUE ]; then if ! _otel_string_starts_with "$1" _otel_ && \[ "$command_type" = file ] && \type strace 1> /dev/null 2> /dev/null; then local call_command="_otel_call_and_record_subprocesses $span_handle $call_command"; fi; fi
if ! \[ -t 2 ] && ! _otel_string_contains "$-" x; then local call_command="_otel_call_and_record_logs $call_command"; fi
if ! \[ -t 0 ] && ! \[ -t 1 ] && ! \[ -t 2 ] && ! _otel_string_contains "$-" x && \[ "$OTEL_SHELL_CONFIG_OBSERVE_PIPES" = TRUE ]; then local call_command="_otel_call_and_record_pipes $span_handle $command_type $call_command"; fi
$call_command "$@" || local exit_code="$?"
Expand Down
14 changes: 7 additions & 7 deletions tests/auto/test_auto_observe_subprocesses_and_signals.shell
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export OTEL_SHELL_CONFIG_OBSERVE_SUBPROCESSES=TRUE
export OTEL_SHELL_CONFIG_OBSERVE_SIGNALS=TRUE
. otel.sh

if type apt-get update; then
if \type apt-get; then
command="sudo apt-get update"
elif type dnf; then
elif \type dnf; then
command="sudo dnf -y upgrade"
elif type zypper; then
elif \type zypper; then
command="sudo zypper --non-interactive update"
else
exit 0
Expand All @@ -21,12 +21,12 @@ resolve_span '.name == "'"$command"'"'

assert_equals 0 "$(\cat "$OTEL_EXPORT_LOCATION" | \jq '. | select(.name != null) | .events[] | select(.name | startswith("SIG") | not) | .name' | \wc -l)"
assert_equals 0 "$(\cat "$OTEL_EXPORT_LOCATION" | \jq '. | select(.name != null) | select(.name | contains("execve(")) | .name' | \wc -l)"
\cat "$OTEL_EXPORT_LOCATION" | \jq -r '. | select(.name != null) | .name' | \cut -d ' ' -f 1 | while read -r command; do
assert_not_equals "" "$(\which "$command")"
\cat "$OTEL_EXPORT_LOCATION" | \jq -r '. | select(.name != null) | .name' | \cut -d ' ' -f 1 | while \read -r my_command; do
assert_not_equals "" "$(\which "$my_command")"
done

\cat "$OTEL_EXPORT_LOCATION" | \jq -r '. | select(.name != null) | .context.span_id' | while read -r span_id; do
if [ -z "$span_id" ]; then continue; fi
\cat "$OTEL_EXPORT_LOCATION" | \jq -r '. | select(.name != null) | .context.span_id' | while \read -r span_id; do
if \[ -z "$span_id" ]; then continue; fi
span="$(\cat "$OTEL_EXPORT_LOCATION" | \jq '. | select(.context.span_id == "'"$span_id"'")')"
while \[ -n "$span" ] && \[ "$(\printf '%s' "$span" | \jq -r '.name')" != "$command" ]; do
span_id="$(\printf '%s' "$span" | \jq -r '.parent_id')"
Expand Down

0 comments on commit e9f8922

Please sign in to comment.