Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Opentelemetry cli

11 Aug 2022 »

Install

https://github.com/equinix-labs/otel-cli

go install github.com/equinix-labs/otel-cli@latest

Otel-cli TRACEPARENT SPANPARENT

https://github.com/equinix-labs/otel-cli

https://github.com/equinix-labs/otel-cli/issues/112

otel-cli

export TRACEPARENT=00-9f85218a78664e1d3cba6b438e90bd67-eee5976fa7571dd3-01

st=$(date +%s.%N) # unix epoch time with nanoseconds
sleep 1
et=$(date +%s.%N)


export OTEL_EXPORTER_OTLP_ENDPOINT=10.7.0.24:4317
export OTEL_EXPORTER_OTLP_INSECURE=true
export OTEL_EXPORTER_OTLP_HEADERS="lala=k"
data1=$(uuidgen)
data2=$(uuidgen)

otel-cli span \
        -n my-script \
        -s some-interesting-program \
        --tp-required \
        --start $st \
        --end $et \
        --tp-print \
        --attrs "my.data1=$data1,my.data2=$data2"

bash: uuidgen: command not found
bash: uuidgen: command not found
# trace id: 9f85218a78664e1d3cba6b438e90bd67
#  span id: 05acf2a3a9032f82
TRACEPARENT=00-9f85218a78664e1d3cba6b438e90bd67-05acf2a3a9032f82-01

Nested otel-cli

https://github.com/equinix-labs/otel-cli/blob/main/demos/05-nested-exec.sh

carrier=$(mktemp)
export TRACEPARENT=00-d4b603f0cbf3db95de790670f61355bb-14d25236b9217696-01

# generate a new trace & span, cli will print out the 'export TRACEPARENT'
otel-cli span -s "test0" -n "traceparent demo" --tp-print --tp-carrier $carrier

# this will start a child span, and run another otel-cli as its program
otel-cli exec \
	--service    "fake-client" \
	--name       "hammer the server for sweet sweet data" \
	--kind       "client" \
	--tp-carrier $carrier \
	"otel-cli exec -n fake-server -s 'put up with the clients nonsense' -k server echo 500 NOPE"
	# ^ child span, the responding "server" that just echos NOPE

Span background layered

https://github.com/equinix-labs/otel-cli/blob/main/demos/15span-background-layered.sh

carrier=$(mktemp)    # traceparent propagation via tempfile
sockdir=$(mktemp -d) # a unix socket will be created here

export TRACEPARENT=00-4c51af78e062796de807d48779e8af30-a4a327baaa58f2f6-01


# start the span background server, set up trace propagation, and
# time out after 10 seconds (which shouldn't be reached)
otel-cli span background \
    --tp-carrier $carrier \
    --sockdir $sockdir \
    --tp-print \
    --service layer0 \
    --name "layer0 script execution" \
    --timeout 10 &

data1=$(uuidgen)

# add an event to the span running in the background, with an attribute
# set to the uuid we just generated
otel-cli span event \
    --name "did a thing" \
    --sockdir $sockdir \
    --attrs "data1=$data1"
	
# waste some time
sleep 1

# add an event that says we wasted some time
otel-cli span event --name "slept 1 second" --sockdir $sockdir

# run a shorter sleep inside a child span, also note that this is using
# --tp-required so this will fail loudly if there is no traceparent
# available
otel-cli exec \
    --service layer1 \
    --name "sleep 0.2" \
    --tp-required \
    --tp-carrier $carrier \
    --tp-print \
    sleep 0.2

# finally, tell the background server we're all done and it can exit
otel-cli span end --sockdir $sockdir