Last active
August 18, 2022 11:58
-
-
Save tobert/ceb2cd9b18ab7ab09e1ea7e3bf150d9d to your computer and use it in GitHub Desktop.
span & event ideas for otel-cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# otel-cli-ideas.sh - some ideas I'm playing with for otel-cli to cover some | |
# use cases where manual spans or exec don't quite do the trick | |
# | |
# another cool outcome is you could run this without the collector in some | |
# cases without spamming your OTLP endpoint... | |
# | |
# I hope to OSS otel-cli under Apache 2 in early April 2021. | |
# maybe it could background itself and wait for events on a unix socket? | |
cf=$(mktemp) # carrier file, will be read/written | |
sfd=$(mktemp -d) # socket file is a unix domain socket in this dir | |
# start a span in the background, listening on a unix socket | |
# it will hold the span open until it's ended or timeout | |
otel-cli span background \ | |
--service-name $0 \ | |
--span-name "start a background span" \ | |
--tp-carrier $cf \ | |
--bg-socket-dir $sfd \ | |
--timeout 60 & # run as a background job | |
# seems like most of the time you *don't* want to nohup this, but I | |
# don't see why you couldn't, like in one use case I'm working on we | |
# might start a span in initramfs and end it just before reboot... | |
# later... add an event to that span | |
# if a socket is provided, no need for the carrier, we can get that from | |
# the socket | |
otel-cli span event \ | |
--bg-socket-dir $sfd \ | |
--event-name "this is a span event" \ | |
--attrs "foo=bar,kernel=2.5.34-hahaharememberthat" | |
# add a child span to the background span, but do not update carrier | |
otel-cli span \ | |
--bg-socket-dir $sfd \ | |
--span-name "this is a child span on the background span" | |
# add another child to the bg span, also background it | |
inner_sfd=$(mktemp -d) | |
otel-cli span background \ | |
--bg-socket-dir $inner_sfd \ | |
--span-name "child to the background" \ | |
--timeout 30 & | |
# now we can add another span that's child to the child | |
otel-cli span \ | |
--bg-socket-dir $inner_sfd \ | |
--span-name "3rd level child, inside two open spans" | |
# now close up the background spans | |
otel-cli span end --bg-socket-dir $inner_sfd | |
otel-cli span end --bg-socket-dir $sfd | |
# and/or | |
kill $1 | |
kill $(otel-cli span background pid --bg-socket-dir $sfd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment