From f165e5750fff603b11c8f221b7c36a9db4e8e86e Mon Sep 17 00:00:00 2001 From: Roni Riska Date: Wed, 14 Aug 2019 10:53:40 +0300 Subject: [PATCH] First version of the tracing library Supports only noop tracer. Change-Id: I8ccd9ecbeb420b98cefc9950d2ed3f3f59482495 Signed-off-by: Roni Riska --- CMakeLists.txt | 106 ++++++++++++++++++++++++++++++++++++ LICENSES.txt | 47 ++++++++++++++++ README.md | 43 +++++++++++++++ cmake/cxx1.cmake | 19 +++++++ include/tracelibcpp/tracelibcpp.hpp | 32 +++++++++++ src/tracelib.cpp | 28 ++++++++++ tst/testcreate.cpp | 29 ++++++++++ 7 files changed, 304 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSES.txt create mode 100644 README.md create mode 100644 cmake/cxx1.cmake create mode 100644 include/tracelibcpp/tracelibcpp.hpp create mode 100644 src/tracelib.cpp create mode 100644 tst/testcreate.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1c5ad29 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,106 @@ +# +# Copyright (c) 2019 AT&T Intellectual Property. +# Copyright (c) 2018-2019 Nokia. +# +# 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. +# + +cmake_minimum_required (VERSION 3.5) + +file( + DOWNLOAD https://raw.githubusercontent.com/hunter-packages/gate/master/cmake/HunterGate.cmake + ${CMAKE_BINARY_DIR}/HunterGate.cmake) + +include("${CMAKE_BINARY_DIR}/HunterGate.cmake") + +HunterGate( + URL "https://github.com/ruslo/hunter/archive/v0.23.5.tar.gz" + SHA1 "2c5c6fc1cf609d0856695d60f147594daf4e6b3e" +) + +project(tracelibcpp LANGUAGES CXX C) +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/cxx1.cmake) + +set (tracelibcpp_VERSION_MAJOR "0") +set (tracelibcpp_VERSION_MINOR "0") +set (tracelibcpp_VERSION_MICRO "1") +set (tracelibcpp_VERSION_STRING + "${tracelibcpp_VERSION_MAJOR}.${tracelibcpp_VERSION_MINOR}.${tracelibcpp_VERSION_MICRO}") + +# Add jaeger +hunter_add_package(jaegertracing) +find_package(jaegertracing CONFIG REQUIRED) + +# Unit testing support of off by default +# Enable it with cmake -DWITH_TESTING=ON +option(WITH_TESTING "Include using testing support" OFF) + +include_directories ("${PROJECT_SOURCE_DIR}/include/tracelibcpp") + +add_library(tracelibcpp SHARED + src/tracelib.cpp +) + +option(WITH_VERSION "Support for library versioning" ON) + +if (WITH_VERSION) + set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING} + SOVERSION ${tracelibcpp_VERSION_MAJOR}) +endif (WITH_VERSION) + +# Library versions are on by default +# i.e. so versions +option(WITH_VERSION "Support for library versioning" ON) + +if (WITH_VERSION) +set_target_properties(tracelibcpp PROPERTIES VERSION ${tracelibcpp_VERSION_STRING} + SOVERSION ${tracelibcpp_VERSION_MAJOR}) +endif (WITH_VERSION) + +target_link_libraries(tracelibcpp PUBLIC jaegertracing::jaegertracing-static) + +include(GNUInstallDirs) +if (NOT DEFINED LIB_INSTALL_DIR) + set(LIB_INSTALL_DIR lib) +endif() + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/tracelibcpp + DESTINATION include + COMPONENT DEVEL) + +install(TARGETS tracelibcpp + COMPONENT DIST + LIBRARY DESTINATION ${LIB_INSTALL_DIR} + NAMELINK_SKIP + ) + +install(TARGETS tracelibcpp + COMPONENT DEVEL + LIBRARY DESTINATION ${LIB_INSTALL_DIR} + NAMELINK_ONLY + ) + +# Add google test +if (WITH_TESTING) + hunter_add_package(GTest) + find_package(GTest CONFIG REQUIRED) + add_executable(testrunner + tst/testcreate.cpp + ) + target_link_libraries(testrunner GTest::main) # GTest::gtest will be linked automatically + target_link_libraries(testrunner GTest::gtest) + target_link_libraries(testrunner tracelibcpp) + add_test(UnitTest testrunner) + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS testrunner) + ENABLE_TESTING() +endif (WITH_TESTING) diff --git a/LICENSES.txt b/LICENSES.txt new file mode 100644 index 0000000..fc2ed8e --- /dev/null +++ b/LICENSES.txt @@ -0,0 +1,47 @@ +Copyright (c) 2019 AT&T Intellectual Property. +Copyright (c) 2019 Nokia. + + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the "License"); +you may not use this software 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. + + + +Unless otherwise specified, all documentation contained herein is licensed +under the Creative Commons License, Attribution 4.0 Intl. (the "License"); +you may not use this documentation except in compliance with the License. +You may obtain a copy of the License at + +https://creativecommons.org/licenses/by/4.0/ + +Unless required by applicable law or agreed to in writing, documentation +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. + + + + +Unless otherwise specified, all data contained herein is licensed +under the CDLA-Permissive 1.0 License (the "License"); +you may not use this data except in compliance with the License. +You may obtain a copy of the License at + +https://cdla.io/permissive-1-0/ + +Unless required by applicable law or agreed to in writing, data +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6038328 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# RIC tracing helper library + +The library includes a function for creating a tracer instance. + +ToDo: tracer configuration options + +## Usage + +Create a global tracer + +```c + #include + #include + + opentracing::Tracer::InitGlobal(tracelibcpp::createTracer("my-service-name")); +``` +Span context propagation between different software components in RIC is using a +TextMap carrier and JSON format serialization. +The [opentracing C++](https://github.com/opentracing/opentracing-cpp) Readme gives examples +how span context **inject** and **extract** with textmap can be done. +Serialization to JSON can be done with any JSON library. + +## Requires + +cmake +gcc/c++ + +## Build +mkdir build +cd build +cmake .. +make + +## Unit testing +To run unit tests the project needs to be configured with testing option +cmake -DWITH_TESTING=ON .. +make check +Or with output +CTEST_OUTPUT_ON_FAILURE=1 make check + +## License + +See [LICENSES.txt](LICENSES.txt) file. diff --git a/cmake/cxx1.cmake b/cmake/cxx1.cmake new file mode 100644 index 0000000..2cc7f42 --- /dev/null +++ b/cmake/cxx1.cmake @@ -0,0 +1,19 @@ +# +# Copyright (c) 2019 AT&T Intellectual Property. +# Copyright (c) 2018-2019 Nokia. +# +# 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. +# +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED YES) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) diff --git a/include/tracelibcpp/tracelibcpp.hpp b/include/tracelibcpp/tracelibcpp.hpp new file mode 100644 index 0000000..47b1637 --- /dev/null +++ b/include/tracelibcpp/tracelibcpp.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 AT&T Intellectual Property. + * Copyright (c) 2018-2019 Nokia. + * + * 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 _TRACELIBCPP_H_ +#define _TRACELIBCPP_H_ + +#include + +namespace tracelibcpp +{ + /** Create a new trace instance + * @param[in] serviceName name of the trace + */ + std::shared_ptr createTracer(std::string serviceName); + +} + +#endif \ No newline at end of file diff --git a/src/tracelib.cpp b/src/tracelib.cpp new file mode 100644 index 0000000..6ec898c --- /dev/null +++ b/src/tracelib.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2019 AT&T Intellectual Property. + * Copyright (c) 2018-2019 Nokia. + * + * 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 "tracelibcpp.hpp" + +#include + +std::shared_ptr tracelibcpp::createTracer(std::string serviceName) +{ + auto config = jaegertracing::Config(false, + jaegertracing::samplers::Config("const", 1)); + return jaegertracing::Tracer::make(serviceName, config, jaegertracing::logging::consoleLogger()); +} + diff --git a/tst/testcreate.cpp b/tst/testcreate.cpp new file mode 100644 index 0000000..6529c18 --- /dev/null +++ b/tst/testcreate.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 AT&T Intellectual Property. + * Copyright (c) 2018-2019 Nokia. + * + * 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 +#include + +#include "tracelibcpp.hpp" + +using namespace testing; +using namespace tracelibcpp; + +TEST(CreateTest, TestThatTraceCreateReturnsANewInstance) { + auto tracer = createTracer("foo"); + EXPECT_THAT(tracer, NotNull()); +} -- 2.16.6