Skip to content

Commit 36d1b60

Browse files
authored
W3C-style trace context propagation (#13)
1 parent 0409ba1 commit 36d1b60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3642
-2071
lines changed

.circleci/config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ jobs:
1010
- checkout
1111
- run: bin/check-format
1212

13+
shellcheck:
14+
docker:
15+
- image: "datadog/docker-library:dd-trace-cpp-ci"
16+
resource_class: small
17+
steps:
18+
- checkout
19+
- run: find bin/ -executable -type f | xargs shellcheck
20+
1321
build-bazel:
1422
parameters:
1523
toolchain:
@@ -59,6 +67,7 @@ workflows:
5967
pull-request:
6068
jobs:
6169
- format
70+
- shellcheck
6271
- test-cmake:
6372
matrix:
6473
parameters:

BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ cc_library(
1616
"src/datadog/error.cpp",
1717
"src/datadog/event_scheduler.cpp",
1818
"src/datadog/expected.cpp",
19+
"src/datadog/extracted_data.cpp",
1920
"src/datadog/glob.cpp",
21+
"src/datadog/hex.cpp",
2022
"src/datadog/http_client.cpp",
2123
"src/datadog/id_generator.cpp",
2224
"src/datadog/limiter.cpp",
@@ -49,6 +51,7 @@ cc_library(
4951
"src/datadog/trace_sampler.cpp",
5052
"src/datadog/trace_segment.cpp",
5153
"src/datadog/version.cpp",
54+
"src/datadog/w3c_propagation.cpp",
5255
],
5356
hdrs = [
5457
"src/datadog/cerr_logger.h",
@@ -65,7 +68,9 @@ cc_library(
6568
"src/datadog/error.h",
6669
"src/datadog/event_scheduler.h",
6770
"src/datadog/expected.h",
71+
"src/datadog/extracted_data.h",
6872
"src/datadog/glob.h",
73+
"src/datadog/hex.h",
6974
"src/datadog/http_client.h",
7075
"src/datadog/id_generator.h",
7176
"src/datadog/json.hpp",
@@ -100,6 +105,7 @@ cc_library(
100105
"src/datadog/trace_sampler.h",
101106
"src/datadog/trace_segment.h",
102107
"src/datadog/version.h",
108+
"src/datadog/w3c_propagation.h",
103109
],
104110
copts = [
105111
"-Wall",

CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ option(BUILD_COVERAGE "Build code with code coverage profiling instrumentation"
88
option(BUILD_EXAMPLE "Build the example program (example/)" OFF)
99
option(BUILD_TESTING "Build the unit tests (test/)" OFF)
1010
option(SANITIZE "Build with address sanitizer and undefined behavior sanitizer" OFF)
11+
option(FUZZ_W3C_PROPAGATION "Build a fuzzer for W3C propagation" OFF)
1112

1213
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
1314
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -20,12 +21,26 @@ include(ProcessorCount)
2021
ProcessorCount(NUM_PROCESSORS)
2122
set(MAKE_JOB_COUNT ${NUM_PROCESSORS} CACHE STRING "Number of jobs to use when building libcurl")
2223

23-
if (SANITIZE)
24+
function(add_sanitizers)
2425
add_compile_options(-fsanitize=address)
2526
add_link_options(-fsanitize=address)
2627
add_compile_options(-fsanitize=undefined)
2728
add_link_options(-fsanitize=undefined)
28-
# Thread sanitizer fails with "unexpected memory mapping".
29+
endfunction()
30+
31+
if(FUZZ_W3C_PROPAGATION)
32+
add_compile_options(-fsanitize=fuzzer)
33+
add_link_options(-fsanitize=fuzzer)
34+
add_sanitizers()
35+
add_subdirectory(fuzz/w3c-propagation)
36+
endif()
37+
38+
if (SANITIZE)
39+
add_sanitizers()
40+
endif()
41+
42+
if (BUILD_TESTING)
43+
set(CMAKE_BUILD_TYPE "Debug")
2944
endif()
3045

3146
include (ExternalProject)
@@ -70,7 +85,9 @@ target_sources(dd_trace_cpp PRIVATE
7085
src/datadog/error.cpp
7186
src/datadog/event_scheduler.cpp
7287
src/datadog/expected.cpp
88+
src/datadog/extracted_data.cpp
7389
src/datadog/glob.cpp
90+
src/datadog/hex.cpp
7491
src/datadog/http_client.cpp
7592
src/datadog/id_generator.cpp
7693
src/datadog/limiter.cpp
@@ -103,6 +120,7 @@ target_sources(dd_trace_cpp PRIVATE
103120
src/datadog/trace_sampler.cpp
104121
src/datadog/trace_segment.cpp
105122
src/datadog/version.cpp
123+
src/datadog/w3c_propagation.cpp
106124
)
107125

108126
# This library's public headers are just its source headers.
@@ -125,7 +143,9 @@ target_sources(dd_trace_cpp PUBLIC
125143
src/datadog/error.h
126144
src/datadog/event_scheduler.h
127145
src/datadog/expected.h
146+
src/datadog/extracted_data.h
128147
src/datadog/glob.h
148+
src/datadog/hex.h
129149
src/datadog/http_client.h
130150
src/datadog/id_generator.h
131151
src/datadog/json_fwd.hpp
@@ -160,6 +180,7 @@ target_sources(dd_trace_cpp PUBLIC
160180
src/datadog/trace_sampler.h
161181
src/datadog/trace_segment.h
162182
src/datadog/version.h
183+
src/datadog/w3c_propagation.h
163184
)
164185

165186
add_dependencies(dd_trace_cpp curl)

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env DEBIAN_FRONTEND=noninteractive
1414
run apt-get update && apt-get install --yes software-properties-common && \
1515
add-apt-repository ppa:git-core/ppa --yes && \
1616
apt-get update && apt-get upgrade --yes && \
17-
apt-get install --yes wget build-essential clang sed gdb clang-format git ssh
17+
apt-get install --yes wget build-essential clang sed gdb clang-format git ssh shellcheck
1818

1919
# bazelisk, a launcher for bazel. `bazelisk --help` will cause the latest
2020
# version to be downloaded.

bin/bazel-build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -e
44

5-
cd $(dirname "$0")/..
5+
cd "$(dirname "$0")"/..
66

77
bazelisk build dd_trace_cpp

bin/check

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
# Run some of the checks that are performed by CircleCI.
4+
# This is convenient to run before committing.
5+
6+
set -e
7+
8+
# Go to the repository root directory.
9+
cd "$(dirname "$0")"/..
10+
11+
bin/format --dry-run -Werror
12+
bin/test
13+
bin/bazel-build

bin/cmake-build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
set -e
44

5-
cd $(dirname "$0")/..
5+
cd "$(dirname "$0")"/..
66

77
mkdir -p .build
88
cd .build
99
cmake ..
10-
make -j $(nproc)
10+
make -j "$(nproc)"

bin/example

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ cd "$(dirname "$0")"/..
1919

2020
mkdir -p .build
2121
cd .build
22-
cmake .. $coverage_flags -DBUILD_EXAMPLE=1
23-
make -j $(nproc) $verbosity_flags
22+
cmake .. -DBUILD_EXAMPLE=1
23+
# shellcheck disable=SC2086
24+
make -j "$(nproc)" $verbosity_flags
2425

2526
if [ "$build_only" -eq 1 ]; then
2627
exit
@@ -35,6 +36,6 @@ if [ "$DD_API_KEY" = '' ]; then
3536
fi
3637
docker compose --project-directory ../example up --detach --remove-orphans
3738
# docker compose --project-directory ../example logs --follow &
38-
./example/example"$@"
39+
./example/example "$@"
3940
docker compose --project-directory ../example down
4041
# wait

bin/format

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
set -e
4+
35
# Go to the repository root directory.
46
cd "$(dirname "$0")"/..
57

@@ -9,14 +11,15 @@ cd "$(dirname "$0")"/..
911
# occasionally bumps the required version, reformatting everything.
1012
version=14
1113
formatter=clang-format-$version
12-
formatter_options='--style=file -i'
14+
formatter_options="--style=file -i"
1315

1416
find_sources() {
15-
find src/ example/ test/ -type f \( -name '*.h' -o -name '*.cpp' \) "$@"
17+
find src/ example/ test/ fuzz/ -type f \( -name '*.h' -o -name '*.cpp' \) "$@"
1618
}
1719

1820
# If the correct version of clang-format is installed, then use it and quit.
1921
if >/dev/null command -v "$formatter"; then
22+
# shellcheck disable=SC2086
2023
find_sources -print0 | xargs -0 "$formatter" $formatter_options
2124
exit
2225
fi
@@ -31,11 +34,11 @@ fi
3134
image=silkeh/clang:$version
3235
if [ "$(docker image ls --quiet $image | wc -l)" -eq 0 ]; then
3336
printf '%s is not installed. Download docker image %s instead? [Y/n] ' "$formatter" "$image"
34-
read response
37+
read -r response
3538
case "$response" in
3639
y|Y|yes|Yes|YES|'') ;;
3740
*) exit ;;
38-
esac
41+
esac
3942
fi
4043

4144
mount_path=/mnt/host
@@ -52,6 +55,7 @@ process_arg() {
5255
}
5356

5457
docker_clang_format() {
58+
# shellcheck disable=SC2086
5559
find_sources | while IFS= read -r arg; do
5660
process_arg "$arg"
5761
done | xargs -0 \

bin/install-cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
set -e
4+
35
# Install a recent binary release of cmake.
46
# Kitware produces a self-installing tarball.
57

0 commit comments

Comments
 (0)