8000 Apply changes from #221 as one signed patch. (#224) · DataDog/dd-opentracing-cpp@80979a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80979a8

Browse files
authored
Apply changes from #221 as one signed patch. (#224)
1 parent 662f433 commit 80979a8

File tree

9 files changed

+80
-62
lines changed
Filter options

9 files changed

+80
-62
lines changed

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ include(GNUInstallDirs)
1212

1313
option(BUILD_SHARED "Builds shared library" ON)
1414
option(BUILD_STATIC "Builds static library" OFF)
15+
option(BUILD_OBJECT "Builds objects for use in another project" OFF)
1516
option(BUILD_PLUGIN "Builds plugin (requires gcc and not macos)" OFF)
1617
option(BUILD_TESTING "Builds tests, also enables BUILD_SHARED" OFF)
1718
option(BUILD_COVERAGE "Builds code with code coverage profiling instrumentation" OFF)
@@ -27,7 +28,6 @@ endif()
2728
set(CMAKE_CXX_STANDARD 14)
2829

2930
# Includes
30-
set(CMAKE_INCLUDE_PATH 3rd_party/include deps/include)
3131
include_directories(SYSTEM 3rd_party/include deps/include)
3232
include_directories(include)
3333

@@ -37,7 +37,6 @@ set(CMAKE_LIBRARY_PATH deps/lib)
3737
# Dependencies
3838
find_path(OPENTRACING_INCLUDE_DIR NAMES opentracing/tracer.h)
3939
find_library(OPENTRACING_LIB opentracing)
40-
find_package(ZLIB REQUIRED)
4140
find_library(MSGPACK_LIB msgpack)
4241
find_package(CURL)
4342
find_package(Threads REQUIRED)
@@ -65,7 +64,7 @@ endif()
6564
if(BUILD_COVERAGE)
6665
set(COVERAGE_LIBRARIES gcov)
6766
endif()
68-
set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} ${ZLIB_LIBRARIES} Threads::Threads ${COVERAGE_LIBRARIES})
67+
set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} Threads::Threads ${COVERAGE_LIBRARIES})
6968

7069
## Shared lib
7170
if(BUILD_SHARED)
@@ -94,6 +93,15 @@ if(BUILD_STATIC)
9493
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
9594
endif()
9695

96+
## Object lib
97+
if(BUILD_OBJECT)
98+
add_library(dd_opentracing-object OBJECT ${DD_OPENTRACING_SOURCES})
99+
add_sanitizers(dd_opentracing-object)
100+
target_link_libraries(dd_opentracing-object ${CURL_LIBRARIES} Threads::Threads)
101+
set_property(TARGET dd_opentracing-object PROPERTY POSITION_INDEPENDENT_CODE ON)
102+
target_compile_definitions(dd_opentracing-object PUBLIC DD_OPENTRACING_OBJECT)
103+
endif()
104+
97105
## Plugin
98106
if(BUILD_PLUGIN)
99107
if(CMAKE_SYSTEM_NAME MATCHES "Darwin" OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

include/datadog/opentracing.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ DD_OPENTRACING_API std::shared_ptr<ot::Tracer> makeTracer(const TracerOptions& o
179179
std::tuple<std::shared_ptr<ot::Tracer>, std::shared_ptr<TraceEncoder>> makeTracerAndEncoder(
180180
const TracerOptions& options);
181181

182+
// Return a JSON representation of the specified `options`. If the specified
183+
// `with_timestamp` is `true`, then include a "date" field whose value is the
184+
// current date and time.
185+
// This function is defined in `tracer_options.cpp`.
186+
std::string toJSON(const TracerOptions& options, bool with_timestamp);
187+
188+
// Return a reference to the options used to configure the specified `tracer`.
189+
// The behavior is undefined unless `tracer` is a Datadog tracer.
190+
// This function is defined in `tracer.cpp`.
191+
const TracerOptions& getOptions(const ot::Tracer& tracer);
192+
182193
} // namespace opentracing
183194
} // namespace datadog
184195

scripts/install_dependencies.sh

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ fi
99
OPENTRACING_VERSION=${OPENTRACING_VERSION:-1.6.0}
1010
CURL_VERSION=${CURL_VERSION:-7.70.0}
< AE7F code>1111
MSGPACK_VERSION=${MSGPACK_VERSION:-3.2.1}
12-
ZLIB_VERSION=${ZLIB_VERSION:-1.2.12}
1312

1413
MAKE_JOB_COUNT=${MAKE_JOB_COUNT:-$(nproc)}
1514

@@ -18,7 +17,6 @@ if [[ "$1" == "versions" ]]; then
1817
echo "opentracing:$OPENTRACING_VERSION"
1918
echo "curl:$CURL_VERSION"
2019
echo "msgpack:$MSGPACK_VERSION"
21-
echo "zlib:$ZLIB_VERSION"
2220
exit 0
2321
fi
2422

@@ -28,7 +26,6 @@ fi
2826
BUILD_OPENTRACING=1
2927
BUILD_CURL=1
3028
BUILD_MSGPACK=1
31-
BUILD_ZLIB=1
3229

3330
while test $# -gt 0
3431
do
@@ -39,8 +36,6 @@ do
3936
;;
4037
not-curl) BUILD_CURL=0
4138
;;
42-
not-zlib) BUILD_ZLIB=0
43-
;;
4439
*) echo "unknown dependency: $1" && exit 1
4540
;;
4641
esac
@@ -67,26 +62,13 @@ if [ "$BUILD_OPENTRACING" -eq "1" ]; then
6762
rm opentracing-cpp.tar.gz
6863
fi
6964

70-
# Zlib
71-
if [ "$BUILD_ZLIB" -eq "1" ]; then
72-
wget "https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz"
73-
tar zxf "zlib-${ZLIB_VERSION}.tar.gz"
74-
mkdir -p "zlib-${ZLIB_VERSION}"
75-
cd "zlib-${ZLIB_VERSION}"
76-
CFLAGS="$CFLAGS -fPIC" ./configure --prefix="$install_dir" --static
77-
make --jobs="$MAKE_JOB_COUNT" && make install
78-
cd ..
79-
rm -r "zlib-${ZLIB_VERSION}"
80-
rm "zlib-${ZLIB_VERSION}.tar.gz"
81-
fi
82-
8365
# Msgpack
8466
if [ "$BUILD_MSGPACK" -eq "1" ]; then
8567
wget "https://github.com/msgpack/msgpack-c/releases/download/cpp-${MSGPACK_VERSION}/msgpack-${MSGPACK_VERSION}.tar.gz" -O msgpack.tar.gz
8668
tar zxf msgpack.tar.gz
8769
mkdir -p "msgpack-${MSGPACK_VERSION}/.build"
8870
cd "msgpack-${MSGPACK_VERSION}/.build"
89-
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -DBUILD_SHARED_LIBS=OFF ..
71+
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -DBUILD_SHARED_LIBS=OFF -DMSGPACK_CXX11=ON ..
9072
make --jobs="$MAKE_JOB_COUNT"
9173
make install
9274
cd ../..
@@ -112,11 +94,12 @@ if [ "$BUILD_CURL" -eq "1" ]; then
11294
--without-ssl \
11395
--disable-crypto-auth \
11496
--without-axtls \
115-
--with-zlib \
97+
--without-zlib \
11698
--disable-rtsp \
11799
--enable-shared=no \
118100
--enable-static=yes \
119-
--with-pic
101+
--with-pic \
102+
--without-brotli
120103
make --jobs="$MAKE_JOB_COUNT" && make install
121104
cd ..
122105
rm -r "curl-${CURL_VERSION}/"

src/tracer.cpp

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -105,44 +105,10 @@ void startupLog(TracerOptions &options) {
105105
return;
106106< 5D41 /td>
}
107107

108-
json j;
109-
std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
110-
std::stringstream ss;
111-
ss << std::put_time(std::localtime(&t), "%FT%T%z");
112-
j["date"] = ss.str();
113-
j["version"] = datadog::version::tracer_version;
114-
j["lang"] = "cpp";
115-
j["lang_version"] = datadog::version::cpp_version;
116-
j["env"] = options.environment;
117-
j["enabled"] = true;
118-
j["service"] = options.service;
119-
if (!options.agent_url.empty()) {
120-
j["agent_url"] = options.agent_url;
121-
} else {
122-
j["agent_url"] =
123-
std::string("http://") + options.agent_host + ":" + std::to_string(options.agent_port);
124-
}
125-
j["analytics_enabled"] = options.analytics_enabled;
126-
j["analytics_sample_rate"] = options.analytics_rate;
127-
if (!std::isnan(options.sample_rate)) {
128-
j["sample_rate"] = options.sample_rate;
129-
}
130-
j["sampling_rules"] = options.sampling_rules;
131-
j["sampling_limit_per_second"] = options.sampling_limit_per_second;
132-
if (!options.tags.empty()) {
133-
j["tags"] = options.tags;
134-
}
135-
if (!options.version.empty()) {
136-
j["dd_version"] = options.version;
137-
}
138-
j["report_hostname"] = options.report_hostname;
139-
if (!options.operation_name_override.empty()) {
140-
j["operation_name_override"] = options.operation_name_override;
141-
}
142-
143108
std::string message;
144109
message += "DATADOG TRACER CONFIGURATION - ";
145-
message += j.dump();
110+
const bool with_timestamp = true;
111+
message += toJSON(options, with_timestamp);
146112
options.log_func(LogLevel::info, message);
147113
}
148114

@@ -370,5 +336,12 @@ ot::expec 5D41 ted<std::unique_ptr<ot::SpanContext>> Tracer::Extract(
370336

371337
void Tracer::Close() noexcept { buffer_->flush(std::chrono::seconds(5)); }
372338

339+
const TracerOptions &Tracer::options() const noexcept { return opts_; }
340+
341+
const TracerOptions &getOptions(const ot::Tracer &tracer) {
342+
auto &dd_tracer = static_cast<const Tracer &>(tracer);
343+
return dd_tracer.options();
344+
}
345+
373346
} // namespace opentracing
374347
} // namespace datadog

src/tracer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class Tracer : public ot::Tracer, public std::enable_shared_from_this<Tracer> {
7272

7373
void Close() noexcept override;
7474

75+
const TracerOptions &options() const noexcept;
76+
7577
private:
7678
void configureRulesSampler(std::shared_ptr<RulesSampler> sampler) noexcept;
7779

src/tracer_factory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
using json = nlohmann::json;
77

8+
extern "C" char **environ;
9+
810
namespace datadog {
911
namespace opentracing {
1012

src/tracer_options.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "tracer_options.h"
22

33
#include <datadog/tags.h>
4+
#include <datadog/version.h>
45
#include <opentracing/ext/tags.h>
56

7+
#include <iomanip>
68
#include <limits>
9+
#include <nlohmann/json.hpp>
710
#include <regex>
811
#include <sstream>
912

@@ -273,5 +276,42 @@ ot::expected<TracerOptions, std::string> applyTracerOptionsFromEnvironment(
273276
return opts;
274277
}
275278

279+
std::string toJSON(const TracerOptions &options, bool with_timestamp) {
280+
nlohmann::json j;
281+
if (with_timestamp) {
282+
std::time_t t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
283+
std::stringstream ss;
284+
ss << std::put_time(std::localtime(&t), "%FT%T%z");
285+
j["date"] = ss.str();
286+
}
287+
j["version"] = datadog::version::tracer_version;
288+
j["lang"] = "cpp";
289+
j["lang_version"] = datadog::version::cpp_version;
290+
j["env"] = options.environment;
291+
j["enabled"] = true;
292+
j["service"] = options.service;
293+
if (!options.agent_url.empty()) {
294+
j["agent_url"] = options.agent_url;
295+
} else {
296+
j["agent_url"] =
297+
std::string("http://") + options.agent_host + ":" + std::to_string(options.agent_port);
298+
}
299+
j["analytics_enabled"] = options.analytics_enabled;
300+
j["analytics_sample_rate"] = options.analytics_rate;
301+
j["sampling_rules"] = options.sampling_rules;
302+
if (!options.tags.empty()) {
303+
j["tags"] = options.tags;
304+
}
305+
if (!options.version.empty()) {
306+
j["dd_version"] = options.version;
307+
}
308+
j["report_hostname"] = options.report_hostname;
309+
if (!options.operation_name_override.empty()) {
310+
j["operation_name_override"] = options.operation_name_override;
311+
}
312+
313+
return j.dump();
314+
}
315+
276316
} // namespace opentracing
277317
} // namespace datadog

test/integration/nginx/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ENV LDFLAGS="-fPIC"
4646

4747

4848
RUN apt-get update && \
49-
apt-get install -y git build-essential wget curl tar cmake libpcre3-dev zlib1g-dev
49+
apt-get install -y git build-essential wget curl tar cmake libpcre3-dev
5050

5151
WORKDIR /root
5252

vcpkg.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"homepage": "https://github.com/DataDog/dd-opentracing-cpp",
66
"description": "Datadog OpenTracing C++ Client",
77
"dependencies": [
8-
"zlib",
98
"msgpack",
109
"curl",
1110
"opentracing"

0 commit comments

Comments
 (0)
0