Skip to content

Commit

Permalink
Merge main into async changes (open-telemetry#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed May 16, 2022
1 parent 08a12b5 commit 0aebd6e
Show file tree
Hide file tree
Showing 77 changed files with 1,795 additions and 458 deletions.
7 changes: 7 additions & 0 deletions .github/.codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ comment:
# to coverage report file paths.
fixes:
- "/home/runner/::"

ignore:
- "docs/**/*"
- "docker/**/*"
- "examples/**/*"
- "**/test/**/*"
- "**.md"
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: cpp
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
6 changes: 3 additions & 3 deletions .github/workflows/dependencies_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
-
name: Build Image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}
context: ci/
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ if(WITH_PROMETHEUS)
if(NOT prometheus-cpp_FOUND)
message("Trying to use local prometheus-cpp from submodule")
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git)
set(SAVED_ENABLE_TESTING ${ENABLE_TESTING})
set(ENABLE_TESTING OFF)
add_subdirectory(third_party/prometheus-cpp)
set(ENABLE_TESTING ${SAVED_ENABLE_TESTING})
else()
message(
FATAL_ERROR
Expand Down Expand Up @@ -362,7 +365,7 @@ if(BUILD_TESTING)
${CMAKE_BINARY_DIR}/lib/libgmock.a)
elseif(WIN32)
# Make sure we are always bootsrapped with vcpkg on Windows
find_package(GTest)
find_package(GTest REQUIRED)
if(NOT (GTEST_FOUND OR GTest_FOUND))
install_windows_deps()
find_package(GTest REQUIRED)
Expand Down
22 changes: 13 additions & 9 deletions api/include/opentelemetry/baggage/baggage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ class Baggage
static constexpr char kMembersSeparator = ',';
static constexpr char kMetadataSeparator = ';';

Baggage() : kv_properties_(new opentelemetry::common::KeyValueProperties()) {}
Baggage(size_t size) : kv_properties_(new opentelemetry::common::KeyValueProperties(size)){};
Baggage() noexcept : kv_properties_(new opentelemetry::common::KeyValueProperties()) {}
Baggage(size_t size) noexcept
: kv_properties_(new opentelemetry::common::KeyValueProperties(size)){};

template <class T>
Baggage(const T &keys_and_values)
Baggage(const T &keys_and_values) noexcept
: kv_properties_(new opentelemetry::common::KeyValueProperties(keys_and_values))
{}

Expand All @@ -42,15 +43,16 @@ class Baggage
/* Get value for key in the baggage
@returns true if key is found, false otherwise
*/
bool GetValue(nostd::string_view key, std::string &value) const
bool GetValue(nostd::string_view key, std::string &value) const noexcept
{
return kv_properties_->GetValue(key, value);
}

/* Returns shared_ptr of new baggage object which contains new key-value pair. If key or value is
invalid, copy of current baggage is returned
*/
nostd::shared_ptr<Baggage> Set(const nostd::string_view &key, const nostd::string_view &value)
nostd::shared_ptr<Baggage> Set(const nostd::string_view &key,
const nostd::string_view &value) noexcept
{

nostd::shared_ptr<Baggage> baggage(new Baggage(kv_properties_->Size() + 1));
Expand Down Expand Up @@ -89,7 +91,7 @@ class Baggage
// if key does not exist, copy of current baggage is returned.
// Validity of key is not checked as invalid keys should never be populated in baggage in the
// first place.
nostd::shared_ptr<Baggage> Delete(nostd::string_view key)
nostd::shared_ptr<Baggage> Delete(nostd::string_view key) noexcept
{
// keeping size of baggage same as key might not be found in it
nostd::shared_ptr<Baggage> baggage(new Baggage(kv_properties_->Size()));
Expand All @@ -103,7 +105,7 @@ class Baggage
}

// Returns shared_ptr of baggage after extracting key-value pairs from header
static nostd::shared_ptr<Baggage> FromHeader(nostd::string_view header)
static nostd::shared_ptr<Baggage> FromHeader(nostd::string_view header) noexcept
{
if (header.size() > kMaxSize)
{
Expand Down Expand Up @@ -158,7 +160,7 @@ class Baggage
}

// Creates string from baggage object.
std::string ToHeader() const
std::string ToHeader() const noexcept
{
std::string header_s;
bool first = true;
Expand Down Expand Up @@ -249,7 +251,9 @@ class Baggage
};

auto from_hex = [](char c) -> char {
return std::isdigit(c) ? c - '0' : std::toupper(c) - 'A' + 10;
// c - '0' produces integer type which could trigger error/warning when casting to char,
// but the cast is safe here.
return static_cast<char>(std::isdigit(c) ? c - '0' : std::toupper(c) - 'A' + 10);
};

std::string ret;
Expand Down
7 changes: 4 additions & 3 deletions api/include/opentelemetry/baggage/baggage_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace baggage
static const std::string kBaggageHeader = "baggage";

inline nostd::shared_ptr<opentelemetry::baggage::Baggage> GetBaggage(
const opentelemetry::context::Context &context)
const opentelemetry::context::Context &context) noexcept
{
context::ContextValue context_value = context.GetValue(kBaggageHeader);
if (nostd::holds_alternative<nostd::shared_ptr<opentelemetry::baggage::Baggage>>(context_value))
Expand All @@ -28,8 +28,9 @@ inline nostd::shared_ptr<opentelemetry::baggage::Baggage> GetBaggage(
return empty_baggage;
}

inline context::Context SetBaggage(opentelemetry::context::Context &context,
nostd::shared_ptr<opentelemetry::baggage::Baggage> baggage)
inline context::Context SetBaggage(
opentelemetry::context::Context &context,
nostd::shared_ptr<opentelemetry::baggage::Baggage> baggage) noexcept
{
return context.SetValue(kBaggageHeader, baggage);
}
Expand Down
16 changes: 14 additions & 2 deletions api/include/opentelemetry/baggage/propagation/baggage_propagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,27 @@ class BaggagePropagator : public opentelemetry::context::propagation::TextMapPro
const opentelemetry::context::Context &context) noexcept override
{
auto baggage = opentelemetry::baggage::GetBaggage(context);
carrier.Set(kBaggageHeader, baggage->ToHeader());
auto header = baggage->ToHeader();
if (header.size())
{
carrier.Set(kBaggageHeader, header);
}
}

context::Context Extract(const opentelemetry::context::propagation::TextMapCarrier &carrier,
opentelemetry::context::Context &context) noexcept override
{
nostd::string_view baggage_str = carrier.Get(opentelemetry::baggage::kBaggageHeader);
auto baggage = opentelemetry::baggage::Baggage::FromHeader(baggage_str);
return opentelemetry::baggage::SetBaggage(context, baggage);

if (baggage->ToHeader().size())
{
return opentelemetry::baggage::SetBaggage(context, baggage);
}
else
{
return context;
}
}

bool Fields(nostd::function_ref<bool(nostd::string_view)> callback) const noexcept override
Expand Down
22 changes: 11 additions & 11 deletions api/include/opentelemetry/common/kv_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class KeyValueStringTokenizer
public:
KeyValueStringTokenizer(
nostd::string_view str,
const KeyValueStringTokenizerOptions &opts = KeyValueStringTokenizerOptions())
const KeyValueStringTokenizerOptions &opts = KeyValueStringTokenizerOptions()) noexcept
: str_(str), opts_(opts), index_(0)
{}

Expand All @@ -48,7 +48,7 @@ class KeyValueStringTokenizer
// @param key : key in kv pair
// @param key : value in kv pair
// @returns true if next kv pair was found, false otherwise.
bool next(bool &valid_kv, nostd::string_view &key, nostd::string_view &value)
bool next(bool &valid_kv, nostd::string_view &key, nostd::string_view &value) noexcept
{
valid_kv = true;
while (index_ < str_.size())
Expand Down Expand Up @@ -170,13 +170,13 @@ class KeyValueProperties
}

// Gets the key associated with this entry.
nostd::string_view GetKey() const { return key_.get(); }
nostd::string_view GetKey() const noexcept { return key_.get(); }

// Gets the value associated with this entry.
nostd::string_view GetValue() const { return value_.get(); }
nostd::string_view GetValue() const noexcept { return value_.get(); }

// Sets the value for this entry. This overrides the previous value.
void SetValue(nostd::string_view value) { value_ = CopyStringToPointer(value); }
void SetValue(nostd::string_view value) noexcept { value_ = CopyStringToPointer(value); }

private:
// Store key and value as raw char pointers to avoid using std::string.
Expand Down Expand Up @@ -206,15 +206,15 @@ class KeyValueProperties
public:
// Create Key-value list of given size
// @param size : Size of list.
KeyValueProperties(size_t size)
KeyValueProperties(size_t size) noexcept
: num_entries_(0), max_num_entries_(size), entries_(new Entry[size])
{}

// Create Empty Key-Value list
KeyValueProperties() : num_entries_(0), max_num_entries_(0), entries_(nullptr) {}
KeyValueProperties() noexcept : num_entries_(0), max_num_entries_(0), entries_(nullptr) {}

template <class T, class = typename std::enable_if<detail::is_key_value_iterable<T>::value>::type>
KeyValueProperties(const T &keys_and_values)
KeyValueProperties(const T &keys_and_values) noexcept
: num_entries_(0),
max_num_entries_(keys_and_values.size()),
entries_(new Entry[max_num_entries_])
Expand All @@ -227,7 +227,7 @@ class KeyValueProperties
}

// Adds new kv pair into kv properties
void AddEntry(nostd::string_view key, nostd::string_view value)
void AddEntry(nostd::string_view key, nostd::string_view value) noexcept
{
if (num_entries_ < max_num_entries_)
{
Expand All @@ -238,7 +238,7 @@ class KeyValueProperties

// Returns all kv pair entries
bool GetAllEntries(
nostd::function_ref<bool(nostd::string_view, nostd::string_view)> callback) const
nostd::function_ref<bool(nostd::string_view, nostd::string_view)> callback) const noexcept
{
for (size_t i = 0; i < num_entries_; i++)
{
Expand All @@ -252,7 +252,7 @@ class KeyValueProperties
}

// Return value for key if exists, return false otherwise
bool GetValue(nostd::string_view key, std::string &value) const
bool GetValue(nostd::string_view key, std::string &value) const noexcept
{
for (size_t i = 0; i < num_entries_; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/common/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace common
class StringUtil
{
public:
static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right)
static nostd::string_view Trim(nostd::string_view str, size_t left, size_t right) noexcept
{
while (str[static_cast<std::size_t>(left)] == ' ' && left <= right)
{
Expand All @@ -39,7 +39,7 @@ class StringUtil
return str.substr(left, 1 + right - left);
}

static nostd::string_view Trim(nostd::string_view str)
static nostd::string_view Trim(nostd::string_view str) noexcept
{
if (str.empty())
{
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class Context
// Creates a context object from a map of keys and identifiers, this will
// hold a shared_ptr to the head of the DataList linked list
template <class T>
Context(const T &keys_and_values)
Context(const T &keys_and_values) noexcept
{
head_ = nostd::shared_ptr<DataList>{new DataList(keys_and_values)};
}

// Creates a context object from a key and value, this will
// hold a shared_ptr to the head of the DataList linked list
Context(nostd::string_view key, ContextValue value)
Context(nostd::string_view key, ContextValue value) noexcept
{
head_ = nostd::shared_ptr<DataList>{new DataList(key, value)};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <initializer_list>
#include <memory>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/context/runtime_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class RuntimeContext
}
};

inline Token::~Token()
inline Token::~Token() noexcept
{
context::RuntimeContext::Detach(*this);
}
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/trace/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace trace
{

// Get Span from explicit context
inline nostd::shared_ptr<Span> GetSpan(const opentelemetry::context::Context &context)
inline nostd::shared_ptr<Span> GetSpan(const opentelemetry::context::Context &context) noexcept
{
context::ContextValue span = context.GetValue(kSpanKey);
if (nostd::holds_alternative<nostd::shared_ptr<Span>>(span))
Expand All @@ -24,7 +24,7 @@ inline nostd::shared_ptr<Span> GetSpan(const opentelemetry::context::Context &co

// Set Span into explicit context
inline context::Context SetSpan(opentelemetry::context::Context &context,
nostd::shared_ptr<Span> span)
nostd::shared_ptr<Span> span) noexcept
{
return context.SetValue(kSpanKey, span);
}
Expand Down
8 changes: 4 additions & 4 deletions api/include/opentelemetry/trace/default_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ class DefaultSpan : public Span

void End(const EndSpanOptions & /* options */ = {}) noexcept {}

nostd::string_view ToString() { return "DefaultSpan"; }
nostd::string_view ToString() const noexcept { return "DefaultSpan"; }

DefaultSpan(SpanContext span_context) : span_context_(span_context) {}
DefaultSpan(SpanContext span_context) noexcept : span_context_(span_context) {}

// movable and copiable
DefaultSpan(DefaultSpan &&spn) : span_context_(spn.GetContext()) {}
DefaultSpan(const DefaultSpan &spn) : span_context_(spn.GetContext()) {}
DefaultSpan(DefaultSpan &&spn) noexcept : span_context_(spn.GetContext()) {}
DefaultSpan(const DefaultSpan &spn) noexcept : span_context_(spn.GetContext()) {}

private:
SpanContext span_context_;
Expand Down
9 changes: 5 additions & 4 deletions api/include/opentelemetry/trace/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ class NoopTracer final : public Tracer, public std::enable_shared_from_this<Noop
class NoopTracerProvider final : public opentelemetry::trace::TracerProvider
{
public:
NoopTracerProvider()
NoopTracerProvider() noexcept
: tracer_{nostd::shared_ptr<opentelemetry::trace::NoopTracer>(
new opentelemetry::trace::NoopTracer)}
{}

nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer(nostd::string_view library_name,
nostd::string_view library_version,
nostd::string_view schema_url) override
nostd::shared_ptr<opentelemetry::trace::Tracer> GetTracer(
nostd::string_view library_name,
nostd::string_view library_version,
nostd::string_view schema_url) noexcept override
{
return tracer_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ class HttpTraceContext : public opentelemetry::context::propagation::TextMapProp
nostd::span<char, 2>{&trace_parent[kTraceIdSize + kSpanIdSize + 5], 2});

carrier.Set(kTraceParent, nostd::string_view(trace_parent, sizeof(trace_parent)));
carrier.Set(kTraceState, span_context.trace_state()->ToHeader());
const auto trace_state = span_context.trace_state()->ToHeader();
if (!trace_state.empty())
{
carrier.Set(kTraceState, trace_state);
}
}

static SpanContext ExtractContextFromTraceHeaders(nostd::string_view trace_parent,
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/trace/span_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SpanContext final
* sampled
* @param is_remote true if this context was propagated from a remote parent.
*/
SpanContext(bool sampled_flag, bool is_remote)
SpanContext(bool sampled_flag, bool is_remote) noexcept
: trace_id_(),
span_id_(),
trace_flags_(opentelemetry::trace::TraceFlags((uint8_t)sampled_flag)),
Expand Down
Loading

0 comments on commit 0aebd6e

Please sign in to comment.