Skip to content

Commit

Permalink
Using STD library for API surface (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgolov authored Dec 22, 2020
1 parent 5e946f9 commit 1e7b9d8
Show file tree
Hide file tree
Showing 64 changed files with 2,537 additions and 1,401 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ jobs:
- name: run tests
run: ./ci/do_ci.sh bazel.tsan

bazel_osx:
name: Bazel on MacOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: run tests
run: ./ci/do_ci.sh bazel.test

benchmark:
name: Benchmark
runs-on: ubuntu-latest
Expand Down Expand Up @@ -195,15 +205,6 @@ jobs:
- name: run tests
run: ./ci/do_ci.sh format

osx_test:
name: Bazel on MacOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: run tests
run: ./ci/do_ci.sh bazel.test

windows:
name: CMake -> exporter proto
Expand Down
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,48 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

option(WITH_STL "Whether to use Standard Library for C++latest features" OFF)

option(WITH_ABSEIL "Whether to use Abseil for C++latest features" OFF)

if(WITH_ABSEIL)
add_definitions(-DHAVE_ABSEIL)
find_package(absl CONFIG REQUIRED)

# Abseil headers-only lib is needed for absl::variant to work vs2015.
# `nostd::mpark::variant` is not compiling in vs2015.
set(CORE_RUNTIME_LIBS absl::any absl::base absl::bits absl::city)

# target_link_libraries(main PRIVATE absl::any absl::base absl::bits
# absl::city)
endif()

if(WITH_STL)
# Require at least C++17. C++20 is needed to avoid gsl::span
add_definitions(-DHAVE_CPP_STDLIB -DHAVE_GSL)

if(CMAKE_MINOR_VERSION VERSION_GREATER "3.18")
# Ask for 20, may get anything below
set(CMAKE_CXX_STANDARD 20)
else()
# Ask for 17, may get anything below
set(CMAKE_CXX_STANDARD 17)
endif()

# Guidelines Support Library path. Used if we are not on not get C++20.
#
# TODO: respect WITH_ABSEIL as alternate implementation of std::span
set(GSL_DIR third_party/ms-gsl)
include_directories(${GSL_DIR}/include)

# Optimize for speed to reduce the hops
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_SPEED "/O2")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} /Zc:__cplusplus ${CMAKE_CXX_FLAGS_SPEED}")
endif()
endif()

option(WITH_OTLP "Whether to include the OpenTelemetry Protocol in the SDK" OFF)

option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK"
Expand Down
57 changes: 57 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,63 @@
"type": "BOOL"
}
]
},
{
"name": "stdlib-x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "WITH_STL",
"value": "True",
"type": "BOOL"
},
{
"name": "WITH_OTLP",
"value": "True",
"type": "BOOL"
},
{
"name": "WITH_EXAMPLES",
"value": "true",
"type": "BOOL"
}
]
},
{
"name": "stdlib-x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\vs2019\\${name}",
"installRoot": "${projectDir}\\out\\vs2019\\${name}\\install",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"cmakeToolchain": "",
"variables": [
{
"name": "WITH_STL",
"value": "True",
"type": "BOOL"
},
{
"name": "WITH_OTLP",
"value": "True",
"type": "BOOL"
},
{
"name": "WITH_EXAMPLES",
"value": "true",
"type": "BOOL"
}
]
}
]
}
6 changes: 6 additions & 0 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ install(
if(BUILD_TESTING)
add_subdirectory(test)
endif()

if(WITH_STL)
message("Building with standard library types...")
else()
message("Building with nostd types...")
endif()
44 changes: 29 additions & 15 deletions api/include/opentelemetry/common/attribute_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@
OPENTELEMETRY_BEGIN_NAMESPACE
namespace common
{
using AttributeValue = nostd::variant<bool,
int,
int64_t,
unsigned int,
uint64_t,
double,
nostd::string_view,
nostd::span<const bool>,
nostd::span<const int>,
nostd::span<const int64_t>,
nostd::span<const unsigned int>,
nostd::span<const uint64_t>,
nostd::span<const double>,
nostd::span<const nostd::string_view>>;
using AttributeValue =
nostd::variant<bool,
int32_t,
int64_t,
uint32_t,
uint64_t,
double,
nostd::string_view,
#ifdef HAVE_CSTRING_TYPE
// TODO: add C-string as possible value on API surface
const char *,
#endif
#ifdef HAVE_SPAN_BYTE
// TODO: 8-bit byte arrays / binary blobs are not part of OT spec yet!
// Ref: https://github.com/open-telemetry/opentelemetry-specification/issues/780
nostd::span<const uint8_t>,
#endif
nostd::span<const bool>,
nostd::span<const int32_t>,
nostd::span<const int64_t>,
nostd::span<const uint32_t>,
nostd::span<const uint64_t>,
nostd::span<const double>,
nostd::span<const nostd::string_view>>;

enum AttributeType
{
Expand All @@ -34,8 +44,12 @@ enum AttributeType
TYPE_UINT64,
TYPE_DOUBLE,
TYPE_STRING,
#ifdef HAVE_CSTRING_TYPE
TYPE_CSTRING,
// TYPE_SPAN_BYTE, // TODO: not part of OT spec yet
#endif
#ifdef HAVE_SPAN_BYTE
TYPE_SPAN_BYTE,
#endif
TYPE_SPAN_BOOL,
TYPE_SPAN_INT,
TYPE_SPAN_INT64,
Expand Down
18 changes: 18 additions & 0 deletions api/include/opentelemetry/common/key_value_iterable.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,23 @@ class KeyValueIterable
*/
virtual size_t size() const noexcept = 0;
};

//
// NULL object pattern empty iterable.
//
class NullKeyValueIterable : public KeyValueIterable
{
public:
NullKeyValueIterable(){};

virtual bool ForEachKeyValue(
nostd::function_ref<bool(nostd::string_view, common::AttributeValue)>) const noexcept
{
return true;
};

virtual size_t size() const noexcept { return 0; }
};

} // namespace common
OPENTELEMETRY_END_NAMESPACE
1 change: 1 addition & 0 deletions api/include/opentelemetry/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/type_traits.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/trace_flags.h"
#include "opentelemetry/trace/trace_id.h"
Expand Down
14 changes: 14 additions & 0 deletions api/include/opentelemetry/nostd/function_ref.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2020, OpenTelemetry Authors
//
// 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.

#pragma once

#include <memory>
Expand Down
Loading

0 comments on commit 1e7b9d8

Please sign in to comment.