Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Upgrade to OpenTracing 1.5.0; Support build on Windows (#115)
Browse files Browse the repository at this point in the history
* Fix Build Under Windows ( #112)

* Move to OpenTracing 1.5.0 that builds under Windows
* Change link of OpenTracing to dynamic. With Static linking of OpenTracing, we end up with multi definition of OT Symbols. This is not acceptable especially for the OT Global Tracer
* Fix OS specificities
** Networking API
** Windows headers
* Fix some tests with random behavior that failed on Windows
* Fix some MSVC specific compilation
* Add appveyor build file.
* Update Hunter version.

Signed-off-by: FR-MUREX-COM\mchaikhadouaihy <[email protected]>

* Enable compilation against Windows 8.1 SDK

The definition of `inet_ntop` for older Windows SDK versions, such as
8.1, does not declare the `pAddr` argument as `const`. Because of this
we need to cast away the constness first.

Despite the argument not being declared as const the function should not
be touching it, hence this should be safe.

Signed-off-by: Fredrik Appelros <[email protected]>

* Fix nlohmann_json dependency

The `package_deps` list is used to iterate over all dependencies in the
package config file and run `find_package` on each of them. This should
be using the package name (`nlohmann_json`) and not the target name
(`nlohmann_json::nlohmann_json`).

Signed-off-by: Fredrik Appelros <[email protected]>

* Avoid redefinition of NOMINMAX

Only define `NOMINMAX` if it has not already been defined to avoid
redefinition warnings.

Signed-off-by: Fredrik Appelros <[email protected]>

* Add Appveyor badge and debug builds.

Signed-off-by: FR-MUREX-COM\mchaikhadouaihy <[email protected]>

* Add TODO with the related issues for Tracer.testTracer test.

Signed-off-by: FR-MUREX-COM\mchaikhadouaihy <[email protected]>
  • Loading branch information
mdouaihy authored and yurishkuro committed Sep 4, 2019
1 parent a472fba commit fec4327
Show file tree
Hide file tree
Showing 63 changed files with 799 additions and 114 deletions.
25 changes: 25 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '{build}'

image: Visual Studio 2017

init:
- cmd: git config --global core.autocrlf true

platform:
- x64

configuration:
- Debug

before_build:
- cmake -H. -Bbuild -A%PLATFORM% -DBUILD_TESTING=ON

build:
project: build\jaegertracing.sln
parallel: true
verbosity: normal

test_script:
- ps: |
cd build
ctest -V -C $env:configuration --timeout 600 --output-on-failure
71 changes: 62 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ set(HUNTER_CONFIGURATION_TYPES "Release;Debug" CACHE STRING

include(CMakeDependentOption)
include(HunterGate)

option(HUNTER_BUILD_SHARED_LIBS "Build Shared Library" ON)

HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.23.5.tar.gz"
SHA1 "2c5c6fc1cf609d0856695d60f147594daf4e6b3e"
URL "https://github.com/ruslo/hunter/archive/v0.23.201.tar.gz"
SHA1 "29f10683f10c7b35e1f599d71542af0c2daa6a01"
)

project(jaegertracing VERSION 0.5.0)
Expand All @@ -32,6 +35,14 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND cxx_flags -Wno-unused-private-field)
endif()

if(MSVC)
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)

# https://studiofreya.com/2018/01/06/visual-studio-2017-with-cpp17-and-boost/
add_definitions(-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(HUNTER_ENABLED)
Expand All @@ -56,16 +67,24 @@ else()
endif()
list(APPEND package_deps thrift)


hunter_add_package(opentracing-cpp)
# Not `${hunter_config}` because OpenTracing provides its own
# OpenTracingConfig.cmake file
find_package(OpenTracing CONFIG REQUIRED)
list(APPEND LIBS OpenTracing::opentracing-static)
# Under Windows, link dynamically with OpenTracing
if (WIN32)
list(APPEND LIBS OpenTracing::opentracing)
set(OPENTRACING_LIB OpenTracing::opentracing)
else()
list(APPEND LIBS OpenTracing::opentracing-static)
set(OPENTRACING_LIB OpenTracing::opentracing-static)
endif()
list(APPEND package_deps OpenTracing)

hunter_add_package(nlohmann_json)
find_package(nlohmann_json CONFIG REQUIRED)
list(APPEND LIBS nlohmann_json)
list(APPEND LIBS nlohmann_json::nlohmann_json)
list(APPEND package_deps nlohmann_json)

option(JAEGERTRACING_BUILD_EXAMPLES "Build examples" ON)
Expand Down Expand Up @@ -193,7 +212,8 @@ set(SRC
src/jaegertracing/utils/HexParsing.cpp
src/jaegertracing/utils/RateLimiter.cpp
src/jaegertracing/utils/UDPClient.cpp
src/jaegertracing/utils/YAML.cpp)
src/jaegertracing/utils/YAML.cpp
src/jaegertracing/ThriftMethods.cpp)

if(JAEGERTRACING_BUILD_CROSSDOCK)
list(APPEND SRC
Expand All @@ -210,12 +230,31 @@ function(add_lib_deps lib)
target_compile_options(${lib} PUBLIC ${cxx_flags})
endfunction()

function(update_path_for_test atest)
if(WIN32)
# If dependent library is a DLL we have to add location of DLL to PATH
set(new_path "")

foreach(LIB OpenTracing::opentracing yaml-cpp::yaml-cpp GTest::main)
list(APPEND new_path $<TARGET_FILE_DIR:${LIB}>)
endforeach()
list(APPEND new_path $ENV{PATH})
string(REPLACE ";" "\\;" new_path "${new_path}")

set_tests_properties(${atest} PROPERTIES ENVIRONMENT "PATH=${new_path}")
endif()
endfunction()

option(JAEGERTRACING_PLUGIN "Build dynamic plugin" OFF)
cmake_dependent_option(BUILD_SHARED_LIBS "Build shared libraries" ON
"NOT JAEGERTRACING_PLUGIN" OFF)

if(BUILD_SHARED_LIBS)
add_library(jaegertracing SHARED ${SRC})
if (WIN32)
target_compile_definitions(jaegertracing PUBLIC YAML_CPP_DLL)
target_link_libraries(jaegertracing PUBLIC Iphlpapi Ws2_32)
endif()
add_lib_deps(jaegertracing)
set_target_properties(jaegertracing PROPERTIES
VERSION ${PROJECT_VERSION}
Expand All @@ -224,6 +263,7 @@ if(BUILD_SHARED_LIBS)
list(APPEND JAEGERTRACING_LIBS jaegertracing)
endif()


if(JAEGERTRACING_PLUGIN)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/export.map
"{ global: OpenTracingMakeTracerFactory; local: *; };")
Expand All @@ -236,9 +276,16 @@ if(JAEGERTRACING_PLUGIN)
endif()

add_library(jaegertracing-static STATIC ${SRC})
set_target_properties(jaegertracing-static PROPERTIES
OUTPUT_NAME jaegertracing)
if (NOT WIN32)
#on windows, the shared library generate also a .lib file
set_target_properties(jaegertracing-static PROPERTIES OUTPUT_NAME jaegertracing)
endif()

add_lib_deps(jaegertracing-static)
if (WIN32)
target_link_libraries(jaegertracing-static PUBLIC Iphlpapi Ws2_32)
endif()

if(NOT JAEGERTRACING_LIB)
set(JAEGERTRACING_LIB jaegertracing-static)
endif()
Expand Down Expand Up @@ -290,19 +337,23 @@ if(BUILD_TESTING)
src/jaegertracing/utils/RateLimiterTest.cpp
src/jaegertracing/utils/UDPClientTest.cpp)
target_link_libraries(
UnitTest PRIVATE testutils GTest::main)
UnitTest PRIVATE testutils GTest::main ${JAEGERTRACING_LIB})
add_test(NAME UnitTest COMMAND UnitTest)

update_path_for_test(UnitTest)

if(TARGET jaegertracing)
add_executable(DynamicallyLoadTracerTest
src/jaegertracing/DynamicallyLoadTracerTest.cpp)

target_include_directories(DynamicallyLoadTracerTest PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>)
target_link_libraries(
DynamicallyLoadTracerTest OpenTracing::opentracing-static GTest::main)
DynamicallyLoadTracerTest ${OPENTRACING_LIB} GTest::main)
add_test(NAME DynamicallyLoadTracerTest
COMMAND DynamicallyLoadTracerTest $<TARGET_FILE:jaegertracing>)
update_path_for_test(DynamicallyLoadTracerTest)
if(JAEGERTRACING_COVERAGE)
setup_target_for_coverage(NAME UnitTestCoverage
EXECUTABLE UnitTest
Expand All @@ -311,6 +362,8 @@ if(BUILD_TESTING)
endif()
endif()



if(JAEGERTRACING_BUILD_CROSSDOCK)
set(CROSSDOCK_SRC crossdock/Server.cpp)
add_executable(crossdock ${CROSSDOCK_SRC})
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![OpenTracing 1.0 Enabled][ot-img]][ot-url]
[![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Appveyor Build][appveyor]][appveyor] [![OpenTracing 1.0 Enabled][ot-img]][ot-url]

# jaeger-client-cpp
C++ OpenTracing binding for [Jaeger](https://www.jaegertracing.io/)
Expand Down Expand Up @@ -81,6 +81,7 @@ sampler:

[ci-img]: https://travis-ci.org/jaegertracing/jaeger-client-cpp.svg?branch=master
[ci]: https://travis-ci.org/jaegertracing/jaeger-client-cpp
[appveyor]: https://ci.appveyor.com/api/projects/status/bu992qd3y9bpwe7u?svg=true
[cov-img]: https://codecov.io/gh/jaegertracing/jaeger-client-cpp/branch/master/graph/badge.svg
[cov]: https://codecov.io/gh/jaegertracing/jaeger-client-cpp
[ot-img]: https://img.shields.io/badge/OpenTracing--1.0-enabled-blue.svg
Expand Down
1 change: 1 addition & 0 deletions cmake/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
34 changes: 34 additions & 0 deletions src/jaegertracing/Compilers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2019 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef JAEGERTRACING_COMPILERS_H
#define JAEGERTRACING_COMPILERS_H

#ifdef _MSC_VER

#pragma warning(push)
#pragma warning(disable : 4251)
#pragma warning(disable : 4275)

// Define NOMINMAX to inhibit definition of Macros min(a,b) and max(a,b) in
// windows.h
#ifndef NOMINMAX
#define NOMINMAX
#endif

#endif // _MSC_VER

#endif // JAEGERTRACING_COMPILERS_H
1 change: 1 addition & 0 deletions src/jaegertracing/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef JAEGERTRACING_CONFIG_H
#define JAEGERTRACING_CONFIG_H

#include "jaegertracing/Compilers.h"
#include "jaegertracing/Constants.h"
#include "jaegertracing/baggage/RestrictionsConfig.h"
#include "jaegertracing/propagation/HeadersConfig.h"
Expand Down
2 changes: 1 addition & 1 deletion src/jaegertracing/DynamicLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ static int makeTracerFactory(const char* opentracingVersion,
return 0;
}

OPENTRACING_DECLARE_IMPL_FACTORY(makeTracerFactory)
OPENTRACING_DECLARE_IMPL_FACTORY(makeTracerFactory)
1 change: 1 addition & 0 deletions src/jaegertracing/LogRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef JAEGERTRACING_LOGRECORD_H
#define JAEGERTRACING_LOGRECORD_H

#include "jaegertracing/Compilers.h"
#include "jaegertracing/Tag.h"
#include "jaegertracing/thrift-gen/jaeger_types.h"
#include <algorithm>
Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <memory>
#include <string>

#include "jaegertracing/Compilers.h"

namespace jaegertracing {
namespace logging {

Expand Down
1 change: 1 addition & 0 deletions src/jaegertracing/Reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <opentracing/propagation.h>

#include "jaegertracing/Compilers.h"
#include "jaegertracing/SpanContext.h"
#include "jaegertracing/thrift-gen/jaeger_types.h"

Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/SpanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <opentracing/span.h>

#include "jaegertracing/Compilers.h"

#include "jaegertracing/TraceID.h"

namespace jaegertracing {
Expand Down
2 changes: 2 additions & 0 deletions src/jaegertracing/Tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef JAEGERTRACING_TAG_H
#define JAEGERTRACING_TAG_H

#include "jaegertracing/Compilers.h"

#include "jaegertracing/thrift-gen/jaeger_types.h"
#include <algorithm>
#include <cstdint>
Expand Down
71 changes: 71 additions & 0 deletions src/jaegertracing/ThriftMethods.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2019 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "jaegertracing/thrift-gen/BaggageRestrictionManager.h"
#include "jaegertracing/thrift-gen/sampling_types.h"

namespace jaegertracing {

// trivial constructors of BaggageRestrictionManager thrift generated code are not generated by MSVC
#ifdef _MSC_VER

namespace thrift {

BaggageRestrictionManager_getBaggageRestrictions_args::
BaggageRestrictionManager_getBaggageRestrictions_args(
const BaggageRestrictionManager_getBaggageRestrictions_args& that)
: serviceName(that.serviceName)
{
}

BaggageRestrictionManager_getBaggageRestrictions_args&
BaggageRestrictionManager_getBaggageRestrictions_args::
operator=(const BaggageRestrictionManager_getBaggageRestrictions_args& that)
{
this->serviceName = that.serviceName;
return *this;
}

BaggageRestrictionManager_getBaggageRestrictions_result::
BaggageRestrictionManager_getBaggageRestrictions_result(
const BaggageRestrictionManager_getBaggageRestrictions_result& that)
: success(that.success)
, __isset(that.__isset)
{
}
BaggageRestrictionManager_getBaggageRestrictions_result&
BaggageRestrictionManager_getBaggageRestrictions_result::
operator=(const BaggageRestrictionManager_getBaggageRestrictions_result& that)
{
this->success = that.success;
return *this;
}

} // namespace thrift

#endif // MSVC

namespace sampling_manager {
namespace thrift {

const std::map<int, const char*>& samplingStrategyType_VALUES_TO_NAMES()
{
return _SamplingStrategyType_VALUES_TO_NAMES;
}

} // namespace thrift
} // namespace sampling_manager
} // namespace jaegertracing
Loading

0 comments on commit fec4327

Please sign in to comment.