equinix-labs / equinix-labs/otel-cli
Another example of usage with some different properties
- Dominant language
- Go
- Stars
- 716
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
While playing around with this - which is super helpful, thanks! - I came up with another approach than the current demos to meet my needs.
The benefits of this is that:
* No `otel-cli exec`, so we can use bash functions
* No `background`, so we don't need to deal with the [race](https://github.com/equinix-labs/otel-cli/blob/159cd1ec2e3f992e5f963dc70269b068c1038738/demos/20span-background-race-workarounds.sh) issues
* No `tp-carrier` needed either, which is not a big deal but avoids a lot of temporary files
Just wanted to share and didn't have a good way to do so, so I thought I would open an issue:
```shell
#!/bin/bash
export OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317
function gen-uid() {
tr -dc 'a-f0-9' < /dev/urandom | head -c$1
}
# Usage: trace [command ...]
function trace() {
# Throughout, "local" usage is critical to avoid nested calls overwriting things
local start="$(date -u +%s.%N)"
# First, get a trace and span ID. We need to get one now so we can propogate it to the child
# Get trace ID from TRACEPARENT, if present
local tid="$(<<<${TRACEPARENT:-} cut -d- -f2)"
tid="${tid:-"$(gen-uid 32)"}"
# Always generate a new span ID
local sid="$(gen-uid 16)"
# Execute the command they wanted with the propogation through TRACEPARENT
TRACEPARENT="00-${tid}-${sid}-01" "${@:2}"
local end="$(date -u +%s.%N)"
# Now report this span. We override the IDs to the ones we set before.
# TODO: support attributes
otel-cli span \
--service "test2" \
--name "$1" \
--start "$start" \
--end "$end" \
--force-trace-id "$tid" \
--force-span-id "$sid"
}
function nested() {
trace "child1" sleep .1
trace "child2" sleep .2
trace "deep" deep
}
function deep() {
trace "in-deep" sleep .1
}
trace "parent" nested
```
I am happy to close this immediately as an "FYI", send it to demos/, etc, whatever.
Contributor guide
Research direction
Review the existing demos/ scripts and compare them with the bash functions and nested tracing example in the issue. Check the referenced demos/20span-background-race-workarounds.sh for the current approach. Done is not defined: clarify whether this should become a demo, documentation example, or remain informational.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- cli, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100