Skip to content

Commit

Permalink
Merge branch 'main' into metrics-sdk-views-2
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Dec 27, 2021
2 parents 31f681d + de276f5 commit 5e14816
Show file tree
Hide file tree
Showing 27 changed files with 303 additions and 75 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ Increment the:

## [Unreleased]

## [1.1.1] 2021-12-20

* [SDK] Rename OTEL_CPP_GET_ATTR macro, and define it using fully qualified attr function ([#1140](https://github.com/open-telemetry/opentelemetry-cpp/pull/1140))
* [SDK] Default resource attributes and attributes in OTEL_RESOURCE_ATTRIBUTES are missing when using Otlp*LogExporter ([#1082](https://github.com/open-telemetry/opentelemetry-cpp/pull/1082))
* [METRICS] Add Meter and MeterProvider in the SDK ([#1078](https://github.com/open-telemetry/opentelemetry-cpp/pull/1078))
* [EXPORTER] ZipkinExporter shutdown ([#1153](https://github.com/open-telemetry/opentelemetry-cpp/pull/1153))
* [EXPORTER] Jaeger exporter shutdown ([#1150](https://github.com/open-telemetry/opentelemetry-cpp/pull/1150))
* [EXPORTER] Bugfix: `jaeger::TUDPTransport::write` crash when `getaddrinfo` returns error ([#1116](https://github.com/open-telemetry/opentelemetry-cpp/pull/1116))
* [EXPORTER] Bugfix: Jaeger exporter: extend supported attributes types ([#1106](https://github.com/open-telemetry/opentelemetry-cpp/pull/1106))
* [EXPORTER] Fix otlp generates null span ids ([#1106](https://github.com/open-telemetry/opentelemetry-cpp/pull/1106))
* [EXPORTER] Fix otlp generates null span ids ([#1113](https://github.com/open-telemetry/opentelemetry-cpp/pull/1113))
* [EXPORTER] Jaeger bazel (Linux only) ([#1077](https://github.com/open-telemetry/opentelemetry-cpp/pull/1077))
* [DOCS] Add note on DLL support ([#1137](https://github.com/open-telemetry/opentelemetry-cpp/pull/1137))
* [DOCS] Improve the instructions for Bazel build ([#1136](https://github.com/open-telemetry/opentelemetry-cpp/pull/1136))
* [DOCS] Document dependencies ([#1119](https://github.com/open-telemetry/opentelemetry-cpp/pull/1119))
* [DOCS] Dockerfile for quick demo/troubleshooting purpose ([#905](https://github.com/open-telemetry/opentelemetry-cpp/pull/905))
* [TESTS] Fix data race in BM_ThreadYieldSpinLockThrashing ([#1099](https://github.com/open-telemetry/opentelemetry-cpp/pull/1099))
* [EXAMPLE] Otlp gRPC log example ([#1083](https://github.com/open-telemetry/opentelemetry-cpp/pull/1083))
* [BUILD] C++20 not Building with VS2019 ([#1144](https://github.com/open-telemetry/opentelemetry-cpp/pull/1144))
* [BUILD] Mark tags to bazel targets([#1075](https://github.com/open-telemetry/opentelemetry-cpp/pull/1075))

## [1.1.0] 2021-11-19

Expand Down
17 changes: 9 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ endif(WIN32)

option(
WITH_API_ONLY
"Only build the API (use as a header-only library). Overrides WITH_EXAMPLES"
"Only build the API (use as a header-only library). Overrides WITH_EXAMPLES and all options to enable exporters"
OFF)
option(WITH_EXAMPLES "Whether to build examples" ON)

Expand Down Expand Up @@ -269,13 +269,14 @@ endif()
include(GNUInstallDirs)

if((NOT WITH_API_ONLY)
OR WITH_ELASTICSEARCH
OR WITH_ZIPKIN
OR WITH_OTLP
OR WITH_OTLP_HTTP
OR WITH_ZPAGES
OR BUILD_W3CTRACECONTEXT_TEST
OR WITH_ETW)
AND (WITH_ELASTICSEARCH
OR WITH_ZIPKIN
OR WITH_OTLP
OR WITH_OTLP_HTTP
OR WITH_ZPAGES
OR BUILD_W3CTRACECONTEXT_TEST
OR WITH_ETW
))
# nlohmann_json package is required for most SDK build configurations
find_package(nlohmann_json QUIET)
set(nlohmann_json_clone FALSE)
Expand Down
7 changes: 6 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ You can link OpenTelemetry C++ SDK with libraries provided in [dependencies.md](
unittests. We use CMake version 3.15.2 in our build system. To install CMake,
consult the [Installing CMake](https://cmake.org/install/) guide.
- [GoogleTest](https://github.com/google/googletest) framework to build and run
the unittests. We use GoogleTest version 1.10.0 in our build system. To
the unittests. Refer to [third_party_release](https://github.com/open-telemetry/opentelemetry-cpp/blob/main/third_party_release#L5)
for version of GoogleTest used in CI. To
install GoogleTest, consult the [GoogleTest Build
Instructions](https://github.com/google/googletest/blob/master/googletest/README.md#generic-build-instructions).
- [Google Benchmark](https://github.com/google/benchmark) framework to build and run
benchmark tests. Refer to [third_party_release](https://github.com/open-telemetry/opentelemetry-cpp/blob/main/third_party_release#L4)
for version of Benchmark used in CI. To install Benchmark,
consult the [GoogleBenchmark Build Instructions](https://github.com/google/benchmark#installation).
- Apart from above core requirements, the Exporters and Propagators have their
build dependencies which are not covered here. E.g, Otlp Exporter needs
grpc/protobuf library, Zipkin exporter needs nlohmann-json and libcurl, ETW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include "opentelemetry/common/string_util.h"
#include "opentelemetry/version.h"

#define OTEL_GET_TRACE_ATTR(name) opentelemetry::trace::attr(OTEL_CPP_CONST_HASHCODE(name))

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{

#define OTEL_CPP_GET_ATTR(name) attr(OTEL_CPP_CONST_HASHCODE(name))

/**
* Stores the Constants for semantic kAttribute names outlined by the OpenTelemetry specifications.
* <see
Expand Down
2 changes: 1 addition & 1 deletion api/include/opentelemetry/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "opentelemetry/detail/preprocessor.h"

#define OPENTELEMETRY_ABI_VERSION_NO 1
#define OPENTELEMETRY_VERSION "1.1.0"
#define OPENTELEMETRY_VERSION "1.1.1"
#define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO)

// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion docs/public/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
author = 'OpenTelemetry authors'

# The full version, including alpha/beta/rc tags
release = '1.1.0'
release = '1.1.1'

# Run sphinx on subprojects and copy output
# -----------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions examples/grpc/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class GreeterClient
std::string span_name = "GreeterClient/Greet";
auto span = get_tracer("grpc")->StartSpan(
span_name,
{{OTEL_CPP_GET_ATTR(AttrRpcSystem), "grpc"},
{OTEL_CPP_GET_ATTR(AttrRpcService), "grpc-example.GreetService"},
{OTEL_CPP_GET_ATTR(AttrRpcMethod), "Greet"},
{OTEL_CPP_GET_ATTR(AttrNetPeerIp), ip},
{OTEL_CPP_GET_ATTR(AttrNetPeerPort), port}},
{{OTEL_GET_TRACE_ATTR(AttrRpcSystem), "grpc"},
{OTEL_GET_TRACE_ATTR(AttrRpcService), "grpc-example.GreetService"},
{OTEL_GET_TRACE_ATTR(AttrRpcMethod), "Greet"},
{OTEL_GET_TRACE_ATTR(AttrNetPeerIp), ip},
{OTEL_GET_TRACE_ATTR(AttrNetPeerPort), port}},
options);

auto scope = get_tracer("grpc-client")->WithActiveSpan(span);
Expand All @@ -66,7 +66,7 @@ class GreeterClient
if (status.ok())
{
span->SetStatus(StatusCode::kOk);
span->SetAttribute(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), status.error_code());
span->SetAttribute(OTEL_GET_TRACE_ATTR(AttrRpcGrpcStatusCode), status.error_code());
// Make sure to end your spans!
span->End();
return response.response();
Expand All @@ -75,7 +75,7 @@ class GreeterClient
{
std::cout << status.error_code() << ": " << status.error_message() << std::endl;
span->SetStatus(StatusCode::kError);
span->SetAttribute(OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), status.error_code());
span->SetAttribute(OTEL_GET_TRACE_ATTR(AttrRpcGrpcStatusCode), status.error_code());
// Make sure to end your spans!
span->End();
return "RPC failed";
Expand Down
8 changes: 4 additions & 4 deletions examples/grpc/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class GreeterServer final : public Greeter::Service
std::string span_name = "GreeterService/Greet";
auto span =
get_tracer("grpc")->StartSpan(span_name,
{{OTEL_CPP_GET_ATTR(AttrRpcSystem), "grpc"},
{OTEL_CPP_GET_ATTR(AttrRpcService), "GreeterService"},
{OTEL_CPP_GET_ATTR(AttrRpcMethod), "Greet"},
{OTEL_CPP_GET_ATTR(AttrRpcGrpcStatusCode), 0}},
{{OTEL_GET_TRACE_ATTR(AttrRpcSystem), "grpc"},
{OTEL_GET_TRACE_ATTR(AttrRpcService), "GreeterService"},
{OTEL_GET_TRACE_ATTR(AttrRpcMethod), "Greet"},
{OTEL_GET_TRACE_ATTR(AttrRpcGrpcStatusCode), 0}},
options);
auto scope = get_tracer("grpc")->WithActiveSpan(span);

Expand Down
8 changes: 4 additions & 4 deletions examples/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void sendRequest(const std::string &url)
std::string span_name = url_parser.path_;
auto span = get_tracer("http-client")
->StartSpan(span_name,
{{OTEL_CPP_GET_ATTR(AttrHttpUrl), url_parser.url_},
{OTEL_CPP_GET_ATTR(AttrHttpScheme), url_parser.scheme_},
{OTEL_CPP_GET_ATTR(AttrHttpMethod), "GET"}},
{{OTEL_GET_TRACE_ATTR(AttrHttpUrl), url_parser.url_},
{OTEL_GET_TRACE_ATTR(AttrHttpScheme), url_parser.scheme_},
{OTEL_GET_TRACE_ATTR(AttrHttpMethod), "GET"}},
options);
auto scope = get_tracer("http-client")->WithActiveSpan(span);

Expand All @@ -44,7 +44,7 @@ void sendRequest(const std::string &url)
{
// set span attributes
auto status_code = result.GetResponse().GetStatusCode();
span->SetAttribute(OTEL_CPP_GET_ATTR(AttrHttpStatusCode), status_code);
span->SetAttribute(OTEL_GET_TRACE_ATTR(AttrHttpStatusCode), status_code);
result.GetResponse().ForEachHeader(
[&span](nostd::string_view header_name, nostd::string_view header_value) {
span->SetAttribute("http.header." + std::string(header_name.data()), header_value);
Expand Down
12 changes: 6 additions & 6 deletions examples/http/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class RequestHandler : public HTTP_SERVER_NS::HttpRequestCallback
// start span with parent context extracted from http header
auto span = get_tracer("http-server")
->StartSpan(span_name,
{{OTEL_CPP_GET_ATTR(AttrHttpServerName), server_name},
{OTEL_CPP_GET_ATTR(AttrNetHostPort), server_port},
{OTEL_CPP_GET_ATTR(AttrHttpMethod), request.method},
{OTEL_CPP_GET_ATTR(AttrHttpScheme), "http"},
{OTEL_CPP_GET_ATTR(AttrHttpRequestContentLength),
{{OTEL_GET_TRACE_ATTR(AttrHttpServerName), server_name},
{OTEL_GET_TRACE_ATTR(AttrNetHostPort), server_port},
{OTEL_GET_TRACE_ATTR(AttrHttpMethod), request.method},
{OTEL_GET_TRACE_ATTR(AttrHttpScheme), "http"},
{OTEL_GET_TRACE_ATTR(AttrHttpRequestContentLength),
static_cast<uint64_t>(request.content.length())},
{OTEL_CPP_GET_ATTR(AttrHttpClientIp), request.client}},
{OTEL_GET_TRACE_ATTR(AttrHttpClientIp), request.client}},
options);

auto scope = get_tracer("http_server")->WithActiveSpan(span);
Expand Down
16 changes: 16 additions & 0 deletions exporters/jaeger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,19 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "jaeger_exporter_test",
srcs = ["test/jaeger_exporter_test.cc"],
copts = ["-fexceptions"],
defines = ["BAZEL_BUILD"],
tags = [
"jaeger",
"test",
],
deps = [
":opentelemetry_exporter_jaeger_trace",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)
24 changes: 24 additions & 0 deletions exporters/jaeger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,28 @@ if(BUILD_TESTING)
TARGET jaeger_recordable_test
TEST_PREFIX exporter.
TEST_LIST jaeger_recordable_test)

add_executable(jaeger_exporter_test test/jaeger_exporter_test.cc)
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1)
if(MSVC)
if(GMOCK_LIB)
unset(GMOCK_LIB CACHE)
endif()
endif()
if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
find_library(GMOCK_LIB gmockd PATH_SUFFIXES lib)
else()
find_library(GMOCK_LIB gmock PATH_SUFFIXES lib)
endif()
target_link_libraries(
jaeger_exporter_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
${GMOCK_LIB} opentelemetry_exporter_jaeger_trace)

target_include_directories(jaeger_exporter_test
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src)

gtest_add_tests(
TARGET jaeger_exporter_test
TEST_PREFIX exporter.
TEST_LIST jaeger_exporter_test)
endif() # BUILD_TESTING
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ class JaegerExporter final : public opentelemetry::sdk::trace::SpanExporter
* @param timeout an option timeout, default to max.
*/
bool Shutdown(
std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override
{
return true;
}
std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override;

private:
void InitializeEndpoint();
Expand All @@ -78,6 +75,14 @@ class JaegerExporter final : public opentelemetry::sdk::trace::SpanExporter
bool is_shutdown_ = false;
JaegerExporterOptions options_;
std::unique_ptr<ThriftSender> sender_;
// For testing
friend class JaegerExporterTestPeer;
/**
* Create an JaegerExporter using the specified thrift sender.
* Only tests can call this constructor directly.
* @param sender the thrift sender to be used for exporting
*/
JaegerExporter(std::unique_ptr<ThriftSender> sender);
};

} // namespace jaeger
Expand Down
10 changes: 10 additions & 0 deletions exporters/jaeger/src/jaeger_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ JaegerExporter::JaegerExporter(const JaegerExporterOptions &options) : options_(

JaegerExporter::JaegerExporter() : JaegerExporter(JaegerExporterOptions()) {}

JaegerExporter::JaegerExporter(std::unique_ptr<ThriftSender> sender)
: options_(JaegerExporterOptions()), sender_(std::move(sender))
{}

std::unique_ptr<trace_sdk::Recordable> JaegerExporter::MakeRecordable() noexcept
{
return std::unique_ptr<sdk::trace::Recordable>(new JaegerRecordable);
Expand Down Expand Up @@ -85,6 +89,12 @@ void JaegerExporter::InitializeEndpoint()
assert(false);
}

bool JaegerExporter::Shutdown(std::chrono::microseconds timeout) noexcept
{
is_shutdown_ = true;
return true;
}

} // namespace jaeger
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
12 changes: 6 additions & 6 deletions exporters/jaeger/src/thrift_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ int ThriftSender::Append(std::unique_ptr<JaegerRecordable> &&span) noexcept
max_span_bytes -= process_bytes_size_;
}

thrift::Span &jaeger_span = *span->Span();
jaeger_span.__set_tags(span->Tags());
jaeger_span.__set_logs(span->Logs());
auto jaeger_span = std::unique_ptr<thrift::Span>(span->Span());
jaeger_span->__set_tags(span->Tags());
jaeger_span->__set_logs(span->Logs());

const uint32_t span_size = CalcSizeOfSerializedThrift(jaeger_span);
const uint32_t span_size = CalcSizeOfSerializedThrift(*jaeger_span);
if (span_size > max_span_bytes)
{
OTEL_INTERNAL_LOG_ERROR("[JAEGER TRACE Exporter] Append() failed: too large span");
Expand All @@ -51,7 +51,7 @@ int ThriftSender::Append(std::unique_ptr<JaegerRecordable> &&span) noexcept
byte_buffer_size_ += span_size;
if (byte_buffer_size_ <= max_span_bytes)
{
span_buffer_.push_back(jaeger_span);
span_buffer_.push_back(*jaeger_span);
if (byte_buffer_size_ < max_span_bytes)
{
return 0;
Expand All @@ -64,7 +64,7 @@ int ThriftSender::Append(std::unique_ptr<JaegerRecordable> &&span) noexcept
}

const auto flushed = Flush();
span_buffer_.push_back(jaeger_span);
span_buffer_.push_back(*jaeger_span);
byte_buffer_size_ = span_size + process_bytes_size_;

return flushed;
Expand Down
4 changes: 4 additions & 0 deletions exporters/jaeger/src/thrift_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class ThriftSender : public Sender
uint32_t byte_buffer_size_ = 0;
uint32_t process_bytes_size_ = 0;
uint32_t max_span_bytes_ = 0;
friend class MockThriftSender;

protected:
ThriftSender() = default;
};

} // namespace jaeger
Expand Down
Loading

0 comments on commit 5e14816

Please sign in to comment.