Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
sudo ./ci/setup_ci_environment.sh
- name: run tests
run: ./ci/do_ci.sh cmake.test
- name: run prometheus exporter tests
run: ./ci/do_ci.sh cmake.exporter.prometheus.test

cmake_test_cxx20:
name: CMake C++20 test
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third_party/prometheus-cpp"]
path = third_party/prometheus-cpp
url = https://github.com/jupp0r/prometheus-cpp.git
7 changes: 7 additions & 0 deletions .markdown_link_check_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ignorePatterns": [
{
"pattern": "^https://github\\.com"
}
]
}
9 changes: 9 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"default": true,
"MD024": { "allow_different_nesting": true },
"MD029": { "style": "ordered" },
"ul-style": false, # MD004
"line-length": false, # MD013
"no-inline-html": false, # MD033
"fenced-code-language": false # MD040
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rewrap.wrappingColumn": 80,
"editor.rulers": [80],
"markdownlint.config": {
"MD004": false,
"MD013": false,
"MD024": {"allow_different_nesting": true},
"MD029": {"style": "ordered"},
"MD033": false,
"MD040": false,
},
}
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ endif()
option(WITH_OTPROTOCOL
"Whether to include the OpenTelemetry Protocol in the SDK" OFF)

option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK"
OFF)

set(WITH_PROTOBUF OFF)
if(WITH_OTPROTOCOL)
set(WITH_PROTOBUF ON)
Expand Down
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,17 @@ http_archive(
"https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip",
],
)

# C++ Prometheus Client library.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

http_archive(
name = "com_github_jupp0r_prometheus_cpp",
sha256 = "85ad6fea0f0dcb413104366b7d6109acdb015aff8767945511c5cad8202a28a6",
strip_prefix = "prometheus-cpp-0.9.0",
urls = ["https://github.com/jupp0r/prometheus-cpp/archive/v0.9.0.tar.gz"],
)

load("@com_github_jupp0r_prometheus_cpp//bazel:repositories.bzl", "prometheus_cpp_repositories")

prometheus_cpp_repositories()
5 changes: 3 additions & 2 deletions api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstring>
#include "opentelemetry/context/context_value.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
Expand Down Expand Up @@ -65,7 +66,7 @@ class Context
{
if (key.size() == data->key_length_)
{
if (memcmp(key.data(), data->key_, data->key_length_) == 0)
if (std::memcmp(key.data(), data->key_, data->key_length_) == 0)
{
return data->value_;
}
Expand All @@ -81,7 +82,7 @@ class Context
{
if (key.size() == data->key_length_)
{
if (memcmp(key.data(), data->key_, data->key_length_) == 0)
if (std::memcmp(key.data(), data->key_, data->key_length_) == 0)
{
return true;
}
Expand Down
20 changes: 20 additions & 0 deletions api/include/opentelemetry/nostd/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ class string_view
inline bool operator==(string_view lhs, string_view rhs) noexcept
{
return lhs.length() == rhs.length() &&
#if _MSC_VER == 1900
// Avoid SCL error in Visual Studio 2015
(std::memcmp(lhs.data(), rhs.data(), lhs.length()) == 0);
#else
std::equal(lhs.data(), lhs.data() + lhs.length(), rhs.data());
#endif
}

inline bool operator==(string_view lhs, const std::string &rhs) noexcept
Expand Down Expand Up @@ -172,3 +177,18 @@ inline std::ostream &operator<<(std::ostream &os, string_view s)
}
} // namespace nostd
OPENTELEMETRY_END_NAMESPACE

namespace std
{
template <>
struct hash<OPENTELEMETRY_NAMESPACE::nostd::string_view>
{
std::size_t operator()(const OPENTELEMETRY_NAMESPACE::nostd::string_view &k) const
{
// TODO: for C++17 that has native support for std::basic_string_view it would
// be more performance-efficient to provide a zero-copy hash.
auto s = std::string(k.data(), k.size());
return std::hash<std::string>{}(s);
}
};
} // namespace std
4 changes: 1 addition & 3 deletions api/include/opentelemetry/plugin/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class Span final : public trace::Span

bool IsRecording() const noexcept override { return span_->IsRecording(); }

trace::Tracer &tracer() const noexcept override { return *tracer_; }

void SetToken(nostd::unique_ptr<context::Token> &&token) noexcept override {}
trace::SpanContext GetContext() const noexcept override { return span_->GetContext(); }

private:
std::shared_ptr<trace::Tracer> tracer_;
Expand Down
57 changes: 57 additions & 0 deletions api/include/opentelemetry/trace/default_span.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once
#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/trace/canonical_code.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/span_context.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
class DefaultSpan : public Span
{
public:
// Returns an invalid span.
static DefaultSpan GetInvalid() { return DefaultSpan(SpanContext::GetInvalid()); }

trace::SpanContext GetContext() const noexcept { return span_context_; }

bool IsRecording() const noexcept { return false; }

void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept {}

void AddEvent(nostd::string_view name) noexcept {}

void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept {}

void AddEvent(nostd::string_view name,
core::SystemTimestamp timestamp,
const KeyValueIterable &attributes) noexcept
{}

void AddEvent(nostd::string_view name, const KeyValueIterable &attributes) noexcept
{
this->AddEvent(name, std::chrono::system_clock::now(), attributes);
}

void SetStatus(CanonicalCode status, nostd::string_view description) noexcept {}

void UpdateName(nostd::string_view name) noexcept {}

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

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

DefaultSpan() = default;

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

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

private:
SpanContext span_context_;
};

} // namespace trace
OPENTELEMETRY_END_NAMESPACE
35 changes: 35 additions & 0 deletions api/include/opentelemetry/trace/default_tracer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/trace/default_span.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/tracer.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
class DefaultTracer : public Tracer
{
public:
~DefaultTracer() = default;

/**
* Starts a span.
*
* Optionally sets attributes at Span creation from the given key/value pairs.
*
* Attributes will be processed in order, previous attributes with the same
* key will be overwritten.
*/
nostd::unique_ptr<Span> StartSpan(nostd::string_view name,
const KeyValueIterable &attributes,
const StartSpanOptions &options = {}) override noexcept
{
return nostd::unique_ptr<Span>(new DefaultSpan::GetInvalid());
}

void ForceFlushWithMicroseconds(uint64_t timeout) override noexcept {}

void CloseWithMicroseconds(uint64_t timeout) override noexcept {}
};
} // namespace trace
OPENTELEMETRY_END_NAMESPACE
6 changes: 3 additions & 3 deletions api/include/opentelemetry/trace/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/trace/tracer.h"
#include "opentelemetry/trace/tracer_provider.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -47,12 +48,11 @@ class NoopSpan final : public Span

bool IsRecording() const noexcept override { return false; }

Tracer &tracer() const noexcept override { return *tracer_; }

void SetToken(nostd::unique_ptr<context::Token> && /* token */) noexcept override {}
SpanContext GetContext() const noexcept override { return span_context_; }

private:
std::shared_ptr<Tracer> tracer_;
SpanContext span_context_;
};

/**
Expand Down
43 changes: 43 additions & 0 deletions api/include/opentelemetry/trace/propagation/http_text_format.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include <cstdint>
#include "opentelemetry/context/context.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
namespace propagation
{

// The HTTPTextFormat class provides an interface that enables extracting and injecting
// context into headers of HTTP requests. HTTP frameworks and clients
// can integrate with HTTPTextFormat by providing the object containing the
// headers, and a getter and setter function for the extraction and
// injection of values, respectively.
template <typename T>
class HTTPTextFormat
{
public:
// Rules that manages how context will be extracted from carrier.
using Getter = nostd::string_view (*)(const T &carrier, nostd::string_view trace_type);

// Rules that manages how context will be injected to carrier.
using Setter = void (*)(T &carrier,
nostd::string_view trace_type,
nostd::string_view trace_description);

// Returns the context that is stored in the HTTP header carrier with the getter as extractor.
virtual context::Context Extract(Getter get_from_carrier,
const T &carrier,
context::Context &context) noexcept = 0;

// Sets the context for a HTTP header carrier with self defined rules.
virtual void Inject(Setter set_from_carrier,
T &carrier,
const context::Context &context) noexcept = 0;
};
} // namespace propagation
} // namespace trace
OPENTELEMETRY_END_NAMESPACE
Loading