Skip to content

Commit

Permalink
feat(w3c): partially implement w3c tracecontext (#110)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

Sub-steps within a run command cannot use TRACEPARENT env var because
our current traceid and spanid are not w3c conformant.

## Short description of the changes

* Omits dashes from trace UUID
* Shortens span id's with the exception of the root watch span, to 16
hex chars to comply with w3c

## How to verify that this has the expected result

Test in dogfood buildevents. (also bees look in OSS CI env!)
  • Loading branch information
lizthegrey authored Oct 16, 2024
1 parent 1fd59fa commit 1f6b162
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/berun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ steps:
- run:
name: << parameters.bename >>
command: |
~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents cmd $CIRCLE_WORKFLOW_ID \
~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents cmd $(echo $CIRCLE_WORKFLOW_ID | sed 's/-//g') \
$(cat "/tmp/buildevents/${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}/span_id") \
"<< parameters.bename >>" -- << parameters.becommand >>
2 changes: 1 addition & 1 deletion src/commands/finish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ steps:
name: Finish the build by sending the root span
command: |
~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents \
build $CIRCLE_WORKFLOW_ID $(cat /tmp/buildevents/build_start) << parameters.result >>
build $(echo $CIRCLE_WORKFLOW_ID | sed 's/-//g') $(cat /tmp/buildevents/build_start) << parameters.result >>
2 changes: 1 addition & 1 deletion src/commands/start_trace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ steps:
- ~/project/bin
- run:
name: report_step
command: ~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents step $CIRCLE_WORKFLOW_ID setup $(cat /tmp/buildevents/build_start) start_trace
command: ~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents step $(echo $CIRCLE_WORKFLOW_ID | sed 's/-//g') setup $(cat /tmp/buildevents/build_start) start_trace
2 changes: 1 addition & 1 deletion src/commands/watch_build_and_finish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ steps:
command: |
# set the timeout
export BUILDEVENT_TIMEOUT=<< parameters.timeout >>
~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents watch $CIRCLE_WORKFLOW_ID
~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents watch $(echo $CIRCLE_WORKFLOW_ID | sed 's/-//g')
4 changes: 2 additions & 2 deletions src/commands/with_job_span.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ steps:
command: |
mkdir -p "/tmp/buildevents/${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}"
date +%s > "/tmp/buildevents/${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}/start"
BUILDEVENTS_SPAN_ID=$(echo "${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}" | sha256sum | awk '{print $1}')
BUILDEVENTS_SPAN_ID=$(echo "${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}" | sha256sum | awk '{print substr($1, 1, 16)}')
echo $BUILDEVENTS_SPAN_ID > "/tmp/buildevents/${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}/span_id"
# in case this is a bash env, be kind and export the buildevents path and span ID
Expand Down Expand Up @@ -46,7 +46,7 @@ steps:
# go ahead and report the span
# choose the right buildevents binary
~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents step $CIRCLE_WORKFLOW_ID \
~/project/bin/be-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/buildevents step $(echo $CIRCLE_WORKFLOW_ID | sed 's/-//g') \
$(cat "/tmp/buildevents/${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}/span_id") \
$(cat "/tmp/buildevents/${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}/start") \
"${CIRCLE_JOB}"
Expand Down
2 changes: 1 addition & 1 deletion src/examples/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ usage:
- run: yarn --immutable
- run: >
# buildevents can be used directly for even more spans
buildevents cmd $CIRCLE_WORKFLOW_ID $BUILDEVENTS_SPAN_ID yarn-test -- yarn test
buildevents cmd $(echo $CIRCLE_WORKFLOW_ID | sed 's/-//g') $BUILDEVENTS_SPAN_ID yarn-test -- yarn test

0 comments on commit 1f6b162

Please sign in to comment.