Skip to content

Commit

Permalink
override span kind
Browse files Browse the repository at this point in the history
  • Loading branch information
plengauer committed Sep 20, 2023
1 parent 42c1901 commit a9ad089
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: opentelemetry-bash
Version: 0.8.0
Version: 0.9.0
Architecture: all
Depends: bash, awk, apt, python3, python3-pip, python3-venv
Priority: extra
Expand Down
19 changes: 15 additions & 4 deletions package/usr/bin/opentelemetry_bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function otel_instrumented_curl {
local target=$(\echo ${url#*//*/}/)
local host=$(\echo ${url} | \awk -F/ '{print $3}')
local method=$(\echo $@ | \awk '{for(i=1;i<=NF;i++) if ($i == "-X") print $(i+1)}')
if [ -z "$method" ]; then
local method=GET
fi
name="curl $*" kind=CLIENT \
attributes="http.url=$url,http.host=$host,http.target=$target,http.method=$method" \
command="curl $*" \
Expand All @@ -39,18 +42,26 @@ function otel_instrumented_curl {
alias curl=otel_instrumented_curl

function otel_instrumented_bash {
OTEL_BASH_ROOT_SPAN_NAME_OVERRIDE="bash $@" \bash -c "source /usr/bin/opentelemetry_bash.sh; source $*"
OTEL_BASH_COMMAND_OVERRIDE="bash $@" OTEL_BASH_ROOT_SPAN_KIND_OVERRIDE=INTERNAL \bash -c "source /usr/bin/opentelemetry_bash.sh; source $*"
}
alias bash=otel_instrumented_bash

function otel_on_script_start {
otel_init
local kind=SERVER
if [ -n "$OTEL_BASH_ROOT_SPAN_KIND_OVERRIDE" ]; then
kind=$OTEL_BASH_ROOT_SPAN_KIND_OVERRIDE
unexport OTEL_BASH_ROOT_SPAN_KIND_OVERRIDE
fi
otel_span_start $kind $(otel_command_self)
}
function otel_on_script_end {
exit_code=$?
local exit_code=$?
if [ "$exit_code" -ne "0" ]; then
otel_span_error
fi
otel_span_end
otel_shutdown
}
trap otel_on_script_end EXIT
otel_init
otel_span_start SERVER $(otel_command_self)
otel_on_script_start
4 changes: 2 additions & 2 deletions package/usr/bin/opentelemetry_bash_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
otel_remote_sdk_pipe=/tmp/opentelemetry_bash_$$_$(echo $RANDOM | md5sum | cut -c 1-32).pipe

function otel_command_self {
if [ -n "$OTEL_BASH_ROOT_SPAN_NAME_OVERRIDE" ]; then
\echo $OTEL_BASH_ROOT_SPAN_NAME_OVERRIDE
if [ -n "$OTEL_BASH_COMMAND_OVERRIDE" ]; then
\echo $OTEL_BASH_COMMAND_OVERRIDE
else
\echo $(ps -p $$ -o args | grep -v COMMAND)
fi
Expand Down

0 comments on commit a9ad089

Please sign in to comment.