Skip to content

Instantly share code, notes, and snippets.

@snbeynon
Created September 23, 2025 18:36
Show Gist options
  • Select an option

  • Save snbeynon/750796ae67b76ac144cf13a560a45129 to your computer and use it in GitHub Desktop.

Select an option

Save snbeynon/750796ae67b76ac144cf13a560a45129 to your computer and use it in GitHub Desktop.
generate w3c traceparent header - tested on mac
#!/usr/bin/env bash
# set -eox
# spec: https://www.w3.org/TR/trace-context
# format = version "-" trace-id "-" parent-id "-" trace-flags
# version = 00 ; always
# trace-id = 32 hex ; 16 bytes array identifier. All zeroes forbidden
# parent-id = 16 hex ; 8 bytes array identifier. All zeroes forbidden
# trace-flags = 01 ; sampled
VERSION="00"
TRACE_ID="$(hexdump -vn "16" -e ' /1 "%02x"' /dev/urandom)"
PARENT_ID="$(hexdump -vn "8" -e ' /1 "%02x"' /dev/urandom)"
TRACE_FLAG="01"
TRACE_PARENT="$VERSION-$TRACE_ID-$PARENT_ID-$TRACE_FLAG"
echo "traceparent: $TRACE_PARENT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment