Skip to content

Commit

Permalink
Fix new docker injection failing with duplicating mount point if /tmp…
Browse files Browse the repository at this point in the history
… is mounted externally
  • Loading branch information
plengauer authored May 30, 2024
1 parent 1d98fc3 commit 9f038c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.12.5
4.12.6
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ _otel_inject_docker_args() {
\echo -n ' '; _otel_escape_args --mount type=bind,source="$_otel_remote_sdk_pipe",target=/var/opentelemetry_shell"$_otel_remote_sdk_pipe"
\echo -n ' '; _otel_escape_args --env OTEL_REMOTE_SDK_PIPE=/var/opentelemetry_shell"$_otel_remote_sdk_pipe"
local pipes_dir="$(\mktemp -u)_opentelemetry_shell_$$.docker/tmp"; \mkdir -p "$pipes_dir"
\echo -n ' '; _otel_escape_args --mount type=bind,source="$pipes_dir",target=/tmp
\echo -n ' '; _otel_escape_args --env OTEL_SHELL_RESPONSE_PIPE_MOUNT="$pipes_dir/..";
\echo -n ' '; _otel_escape_args --mount type=bind,source="$pipes_dir",target="$pipes_dir"
\echo -n ' '; _otel_escape_args --env OTEL_SHELL_RESPONSE_PIPE_MOUNT="$pipes_dir";
\echo -n ' '; _otel_escape_args --env OTEL_SHELL_AUTO_INJECTED=TRUE
\echo -n ' '; _otel_escape_args --env OTEL_SHELL_AUTO_INSTRUMENTATION_HINT="$("$executable" inspect "$image" | \jq -r '.[0].Config.Entrypoint[]?')"
\echo -n ' '; _otel_escape_args --entrypoint /bin/sh
Expand Down
21 changes: 11 additions & 10 deletions src/usr/share/opentelemetry_shell/opentelemetry_shell_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fi

# basic setup
_otel_remote_sdk_pipe="${OTEL_REMOTE_SDK_PIPE:-$(\mktemp -u)_opentelemetry_shell_$$.pipe}"
if \[ -z "$OTEL_SHELL_RESPONSE_PIPE_MOUNT" ]; then OTEL_SHELL_RESPONSE_PIPE_MOUNT=/tmp; fi
_otel_shell="$(\readlink "/proc/$$/exe" | \rev | \cut -d / -f 1 | \rev)"
if \[ "$OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE" = 0 ] || \[ "$OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE" = "$PPID" ] || \[ "$PPID" = 0 ] || \[ "$(\tr '\000-\037' ' ' < /proc/$PPID/cmdline)" = "$(\tr '\000-\037' ' ' < /proc/$OTEL_SHELL_COMMANDLINE_OVERRIDE_SIGNATURE/cmdline)" ]; then _otel_commandline_override="$OTEL_SHELL_COMMANDLINE_OVERRIDE"; fi
unset OTEL_SHELL_COMMANDLINE_OVERRIDE
Expand Down Expand Up @@ -129,19 +130,19 @@ _otel_resolve_package_version() {
}

otel_span_current() {
local response_pipe="$(\mktemp -u)_opentelemetry_shell_$$.pipe"
local response_pipe="$(\mktemp -u -p "$OTEL_SHELL_RESPONSE_PIPE_MOUNT")_opentelemetry_shell_$$.pipe"
\mkfifo $_otel_mkfifo_flags "$response_pipe"
_otel_sdk_communicate "SPAN_HANDLE" "$OTEL_SHELL_RESPONSE_PIPE_MOUNT/$response_pipe" "$OTEL_TRACEPARENT"
_otel_sdk_communicate "SPAN_HANDLE" "$response_pipe" "$OTEL_TRACEPARENT"
\cat "$response_pipe"
\rm "$response_pipe" &> /dev/null
}

otel_span_start() {
local kind="$1"
local name="$2"
local response_pipe="$(\mktemp -u)_opentelemetry_shell_$$.pipe"
local response_pipe="$(\mktemp -u -p "$OTEL_SHELL_RESPONSE_PIPE_MOUNT")_opentelemetry_shell_$$.pipe"
\mkfifo $_otel_mkfifo_flags "$response_pipe"
_otel_sdk_communicate "SPAN_START" "$OTEL_SHELL_RESPONSE_PIPE_MOUNT/$response_pipe" "$OTEL_TRACEPARENT" "$kind" "$name"
_otel_sdk_communicate "SPAN_START" "$response_pipe" "$OTEL_TRACEPARENT" "$kind" "$name"
\cat "$response_pipe"
\rm "$response_pipe" &> /dev/null
}
Expand Down Expand Up @@ -171,9 +172,9 @@ otel_span_attribute_typed() {

otel_span_traceparent() {
local span_handle="$1"
local response_pipe="$(\mktemp -u)_opentelemetry_shell_$$.pipe"
local response_pipe="$(\mktemp -u -p "$OTEL_SHELL_RESPONSE_PIPE_MOUNT")_opentelemetry_shell_$$.pipe"
\mkfifo $_otel_mkfifo_flags "$response_pipe"
_otel_sdk_communicate "SPAN_TRACEPARENT" "$OTEL_SHELL_RESPONSE_PIPE_MOUNT/$response_pipe" "$span_handle"
_otel_sdk_communicate "SPAN_TRACEPARENT" "$response_pipe" "$span_handle"
\cat "$response_pipe"
\rm "$response_pipe" &> /dev/null
}
Expand All @@ -196,9 +197,9 @@ otel_span_deactivate() {

otel_event_create() {
local event_name="$1"
local response_pipe="$(\mktemp -u)_opentelemetry_shell_$$.pipe"
local response_pipe="$(\mktemp -u -p "$OTEL_SHELL_RESPONSE_PIPE_MOUNT")_opentelemetry_shell_$$.pipe"
\mkfifo $_otel_mkfifo_flags "$response_pipe"
_otel_sdk_communicate "EVENT_CREATE" "$OTEL_SHELL_RESPONSE_PIPE_MOUNT/$response_pipe" "$event_name"
_otel_sdk_communicate "EVENT_CREATE" "$response_pipe" "$event_name"
\cat "$response_pipe"
\rm "$response_pipe" &> /dev/null
}
Expand All @@ -224,9 +225,9 @@ otel_event_add() {

otel_metric_create() {
local metric_name="$1"
local response_pipe="$(\mktemp -u)_opentelemetry_shell_$$.pipe"
local response_pipe="$(\mktemp -u -p "$OTEL_SHELL_RESPONSE_PIPE_MOUNT")_opentelemetry_shell_$$.pipe"
\mkfifo $_otel_mkfifo_flags "$response_pipe"
_otel_sdk_communicate "METRIC_CREATE" "$OTEL_SHELL_RESPONSE_PIPE_MOUNT/$response_pipe" "$metric_name"
_otel_sdk_communicate "METRIC_CREATE" "$response_pipe" "$metric_name"
\cat "$response_pipe"
\rm "$response_pipe" &> /dev/null
}
Expand Down
8 changes: 6 additions & 2 deletions tests/auto/test_auto_injection_docker.shell
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ assert_equals "hello world 4" "$(sudo docker run --entrypoint echo debian:latest
span="$(resolve_span '.name == "echo hello world 4"')"
assert_equals "SpanKind.INTERNAL" "$(\echo "$span" | \jq -r '.kind')"

assert_equals "hello world 5" "$(sudo docker run --volume /tmp:/tmp debian:latest echo hello world 5)"
span="$(resolve_span '.name == "echo hello world 5"')"
assert_equals "SpanKind.INTERNAL" "$(\echo "$span" | \jq -r '.kind')"

sudo docker image ls
assert_equals 0 "$?"

Expand All @@ -38,8 +42,8 @@ assert_equals 0 "$?"
# from https://github.com/actions/first-interaction/blob/main/Dockerfile (added because it was hanging forever)
dockerfile="$(mktemp)"
echo 'FROM node:20.10-buster-slim' >> "$dockerfile"
echo 'ENTRYPOINT ["node", "-e", "console.log(\"hello world 4\")"]' >> "$dockerfile"
echo 'ENTRYPOINT ["node", "-e", "console.log(\"hello world 6\")"]' >> "$dockerfile"
sudo docker build -t docker_test_0 -f "$dockerfile" .
assert_equals 0 "$?"
assert_equals "hello world 4" "$(sudo docker run --rm=true docker_test_0)"
assert_equals "hello world 6" "$(sudo docker run --rm=true docker_test_0)"
assert_equals 0 "$?"

0 comments on commit 9f038c7

Please sign in to comment.