Skip to content

Commit

Permalink
Merge branch 'main' into baggage-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgolov authored Jun 18, 2021
2 parents f5b3def + a779c3b commit 4e24e5e
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 25 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ jobs:
sudo ./ci/setup_thrift.sh
./ci/do_ci.sh cmake.test
cmake_absel_stl_test:
name: CMake test (with abseil)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: setup
run: |
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
- name: run cmake tests (enable abseil-cpp)
run: |
sudo ./ci/install_abseil.sh
./ci/do_ci.sh cmake.abseil.test
cmake_gcc_48_test:
name: CMake gcc 4.8
runs-on: ubuntu-18.04
Expand Down Expand Up @@ -56,6 +72,8 @@ jobs:
sudo ./ci/setup_cmake.sh
- name: run tests
run: ./ci/do_ci.sh cmake.c++20.test
- name: run tests (enable stl)
run: ./ci/do_ci.sh cmake.c++20.stl.test

cmake_otprotocol_test:
name: CMake test (with otlp-exporter)
Expand Down
27 changes: 21 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if(WITH_STL)
add_definitions(-DHAVE_CPP_STDLIB)
add_definitions(-DHAVE_GSL)
# Require at least C++17. C++20 is needed to avoid gsl::span
if(CMAKE_VERSION VERSION_GREATER 3.18.0)
if(CMAKE_VERSION VERSION_GREATER 3.11.999)
# Ask for 20, may get anything below
set(CMAKE_CXX_STANDARD 20)
else()
Expand Down Expand Up @@ -228,6 +228,24 @@ endif()
# GNUInstallDirs.
include(GNUInstallDirs)

find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
message("Using local nlohmann::json from submodule")
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
set(JSON_Install
OFF
CACHE INTERNAL "")
# This option allows to link nlohmann_json::nlohmann_json target
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/nlohmann-json)
# This option allows to add header to include directories
include_directories(
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
else()
message("Using external nlohmann::json")
endif()

if(WITH_OTLP)
set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf)
Expand Down Expand Up @@ -268,13 +286,13 @@ if(WITH_OTLP)
include(cmake/opentelemetry-proto.cmake)
include(CMakeDependentOption)
find_package(CURL)
find_package(nlohmann_json)

cmake_dependent_option(
WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK" ON
"gRPC_FOUND" OFF)
cmake_dependent_option(
WITH_OTLP_HTTP "Whether to include the OTLP http exporter in the SDK" ON
"CURL_FOUND;nlohmann_json_FOUND" OFF)
"CURL_FOUND" OFF)
endif()

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
Expand Down Expand Up @@ -329,9 +347,6 @@ if(NOT WITH_API_ONLY)
endif()
endif()

# Add nlohmann/json submodule to include directories
include_directories(third_party/nlohmann-json/single_include)

# Export cmake config and support find_packages(opentelemetry-cpp CONFIG) Write
# config file for find_packages(opentelemetry-cpp CONFIG)
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
Expand Down
1 change: 1 addition & 0 deletions api/include/opentelemetry/std/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ constexpr auto visit(_Callable &&_Obj, _Variants &&... _Args)
};

#else
using std::bad_variant_access;

template <std::size_t I, class... Types>
constexpr std::variant_alternative_t<I, std::variant<Types...>> &get(std::variant<Types...> &v)
Expand Down
2 changes: 1 addition & 1 deletion api/test/nostd/string_view_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "opentelemetry/nostd/string_view.h"

#include <gtest/gtest.h>

#include <cstring>
#include <map>

using opentelemetry::nostd::string_view;
Expand Down
24 changes: 24 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ if [[ "$1" == "cmake.test" ]]; then
make
make test
exit 0
elif [[ "$1" == "cmake.abseil.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_METRICS_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DWITH_ABSEIL=ON \
"${SRC_DIR}"
make
make test
exit 0
elif [[ "$1" == "cmake.c++20.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
Expand All @@ -55,6 +67,18 @@ elif [[ "$1" == "cmake.c++20.test" ]]; then
make
make test
exit 0
elif [[ "$1" == "cmake.c++20.stl.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_METRICS_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
-DWITH_STL=ON \
"${SRC_DIR}"
make
make test
exit 0
elif [[ "$1" == "cmake.legacy.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
Expand Down
23 changes: 23 additions & 0 deletions ci/install_abseil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

set -e
export DEBIAN_FRONTEND=noninteractive

BUILD_DIR=/tmp/
INSTALL_DIR=/usr/local/
TAG=20210324.0
pushd $BUILD_DIR
git clone --depth=1 -b ${TAG} https://github.com/abseil/abseil-cpp.git
cd abseil-cpp
mkdir build && pushd build
cmake -DBUILD_TESTING=OFF -DCMAKE_CXX_STANDARD=11 \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
..
make -j $(nproc)
make install
popd
popd
export PATH=${INSTALL_DIR}/bin:$PATH # ensure to use the installed abseil
2 changes: 0 additions & 2 deletions exporters/etw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
find_package(nlohmann_json REQUIRED)

add_library(opentelemetry_exporter_etw INTERFACE)

target_include_directories(
Expand Down
5 changes: 4 additions & 1 deletion exporters/jaeger/src/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ void Recordable::AddEvent(nostd::string_view name,
void Recordable::SetInstrumentationLibrary(
const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&instrumentation_library) noexcept
{}
{
AddTag("otel.library.name", instrumentation_library.GetName());
AddTag("otel.library.version", instrumentation_library.GetVersion());
}

void Recordable::AddLink(const trace::SpanContext &span_context,
const common::KeyValueIterable &attributes) noexcept
Expand Down
24 changes: 24 additions & 0 deletions exporters/jaeger/test/jaeger_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/exporters/jaeger/recordable.h"
#include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/span_data.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
Expand All @@ -15,6 +16,7 @@ namespace sdktrace = opentelemetry::sdk::trace;

using namespace jaegertracing;
using namespace opentelemetry::exporter::jaeger;
using namespace opentelemetry::sdk::instrumentationlibrary;

TEST(JaegerSpanRecordable, SetIdentity)
{
Expand Down Expand Up @@ -120,3 +122,25 @@ TEST(JaegerSpanRecordable, SetStatus)
EXPECT_EQ(tags[2].vType, thrift::TagType::STRING);
EXPECT_EQ(tags[2].vStr, error_description);
}

TEST(JaegerSpanRecordable, SetInstrumentationLibrary)
{
opentelemetry::exporter::jaeger::Recordable rec;

std::string library_name = "opentelemetry-cpp";
std::string library_version = "0.1.0";
auto instrumentation_library = InstrumentationLibrary::create(library_name, library_version);

rec.SetInstrumentationLibrary(*instrumentation_library);

auto tags = rec.Tags();
EXPECT_EQ(tags.size(), 2);

EXPECT_EQ(tags[0].key, "otel.library.name");
EXPECT_EQ(tags[0].vType, thrift::TagType::STRING);
EXPECT_EQ(tags[0].vStr, library_name);

EXPECT_EQ(tags[1].key, "otel.library.version");
EXPECT_EQ(tags[1].vType, thrift::TagType::STRING);
EXPECT_EQ(tags[1].vStr, library_version);
}
7 changes: 2 additions & 5 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ endif()

if(WITH_OTLP_HTTP)
find_package(CURL REQUIRED)
find_package(nlohmann_json REQUIRED)
add_library(opentelemetry_exporter_otlp_http src/otlp_http_exporter.cc)

set_target_properties(opentelemetry_exporter_otlp_http
PROPERTIES EXPORT_NAME otlp_http_exporter)

target_link_libraries(
opentelemetry_exporter_otlp_http
PUBLIC opentelemetry_otlp_recordable http_client_curl
nlohmann_json::nlohmann_json)
target_link_libraries(opentelemetry_exporter_otlp_http
PUBLIC opentelemetry_otlp_recordable http_client_curl)

list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http)
endif()
Expand Down
11 changes: 1 addition & 10 deletions ext/test/w3c_tracecontext_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ find_package(CURL)
if(NOT CURL_FOUND)
message(WARNING "Skipping example_w3c_tracecontext_test: CURL not found")
else()
find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
# Add library from git submodule to include path
include_directories(
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
else()
# Add header-only library found by CMake
set(NLOHMANN_JSON_LIB nlohmann_json::nlohmann_json)
endif()
add_executable(w3c_tracecontext_test main.cc)
target_link_libraries(
w3c_tracecontext_test
PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace http_client_curl
opentelemetry_exporter_ostream_span ${CURL_LIBRARIES}
${NLOHMANN_JSON_LIB})
nlohmann_json::nlohmann_json)
endif()

0 comments on commit 4e24e5e

Please sign in to comment.