Skip to content

Commit

Permalink
Add Recordable implementation for otprotocol exporter (open-telemetry#49
Browse files Browse the repository at this point in the history
)

* Start Recorder api

* Fill out Span api

* Reformat

* Fill out Tracer class

* Add cmake build

* Add commenting

* Fix formatting

* Reformat

* Fix date

* Make mutex mutable

* s/mutex_/mu_/

* Remove AddEvent with steady timestamp

* Fix typo

* Fill in IsRecordable

* Set up protobuf dependency

* Install protobuf in docker image

* Merge in Recordable

* Add exporter folder

* Integrate protobuf files into build

* Add otprotocol Recordable

* Set up protobuf with bazel

* Reformat

* Install git in CI

* Add otprotocol to cmake test

* Fix typo

* Fix install_protobuf.sh

* Fix install_protobuf.sh

* Fix install_protobuf.sh

* Fix do_ci.sh

* Add otprotocol windows tests

* Fix typo

* Make protobuf install optional for windows

* Fix install_windows_protobuf.ps1

* Remove unnecessary globs

* Refactor

* Rearrange  protobuf files

* Clean up workspace

* Fix formatting

* Update CI

* Restructure

* Reformat

* Refactor legacy test

* Fix legacy target

* Fix legacy target
  • Loading branch information
rnburn authored Apr 6, 2020
1 parent 79d87c6 commit 4ef44ed
Show file tree
Hide file tree
Showing 30 changed files with 1,199 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
- checkout
- run: ./ci/setup_ci_environment.sh
- run: ./ci/setup_cmake.sh
- run: ./ci/install_protobuf.sh
- run: ./ci/do_ci.sh cmake.test
- run: ./ci/do_ci.sh cmake.exporter.otprotocol.test
- store_artifacts:
path: ~/build/Testing/Temporary/LastTest.log
destination: Test.log
Expand Down Expand Up @@ -42,7 +44,7 @@ jobs:
- run: ./ci/setup_ci_environment.sh
- run: ./ci/install_bazelisk.sh
- run: ./ci/install_gcc48.sh
- run: CC=/usr/bin/g++-4.8 ./ci/do_ci.sh bazel.test
- run: CC=/usr/bin/g++-4.8 ./ci/do_ci.sh bazel.legacy.test

bazel_test:
resource_class: xlarge
Expand Down Expand Up @@ -121,7 +123,9 @@ jobs:
- checkout
- run: ./ci/setup_windows_cmake.ps1
- run: ./ci/setup_windows_ci_environment.ps1
- run: ./ci/install_windows_protobuf.ps1
- run: ./ci/do_ci.ps1 cmake.test
- run: ./ci/do_ci.sh cmake.exporter.otprotocol.test

windows_bazel:
executor: win/vs2019
Expand Down
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,31 @@ project(opentelemetry-cpp)

set(CMAKE_CXX_STANDARD 11)

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

set(WITH_PROTOBUF OFF)
if(WITH_OTPROTOCOL)
set(WITH_PROTOBUF ON)
endif()

include(CTest)

find_package(Threads)

if(WITH_PROTOBUF)
set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf CONFIG NAMES protobuf)
# Older versions of protobuf don't use cmake config files.
if(NOT protobuf_FOUND)
find_package(Protobuf REQUIRED)
endif()
endif()

if(WITH_OTPROTOCOL)
include(third_party/opentelemetry-proto/Protobuf.cmake)
endif()

if(BUILD_TESTING)
find_package(GTest REQUIRED)
find_package(benchmark REQUIRED)
Expand All @@ -23,4 +44,6 @@ add_subdirectory(api)
include_directories(sdk/include)
include_directories(sdk)
add_subdirectory(sdk)
include_directories(.)
add_subdirectory(exporters)
add_subdirectory(examples)
21 changes: 21 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ workspace(name = "io_opentelemetry_cpp")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Uses older protobuf version because of
# https://github.com/protocolbuffers/protobuf/issues/7179
http_archive(
name = "com_google_protobuf",
sha256 = "b679cef31102ed8beddc39ecfd6368ee311cbee6f50742f13f21be7278781821",
strip_prefix = "protobuf-3.11.2",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-all-3.11.2.tar.gz",
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

new_local_repository(
name = "com_github_opentelemetry_proto",
build_file = "//bazel:opentelemetry_proto.BUILD",
path = "third_party/opentelemetry-proto",
)

# GoogleTest framework.
# Only needed for tests, not to build the OpenTelemetry library.
http_archive(
Expand Down
60 changes: 60 additions & 0 deletions bazel/opentelemetry_proto.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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.

package(default_visibility = ["//visibility:public"])

load("@rules_proto//proto:defs.bzl", "proto_library")

proto_library(
name = "common_proto",
srcs = [
"opentelemetry/proto/common/v1/common.proto",
],
)

cc_proto_library(
name = "common_proto_cc",
deps = [":common_proto"],
)

proto_library(
name = "resource_proto",
srcs = [
"opentelemetry/proto/resource/v1/resource.proto",
],
deps = [
":common_proto",
],
)

cc_proto_library(
name = "resource_proto_cc",
deps = [":resource_proto"],
)

proto_library(
name = "trace_proto",
srcs = [
"opentelemetry/proto/trace/v1/trace.proto",
],
deps = [
":common_proto",
":resource_proto",
],
)

cc_proto_library(
name = "trace_proto_cc",
deps = [":trace_proto"],
)
2 changes: 2 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ ADD setup_ci_environment.sh /setup-ci
ADD setup_cmake.sh /setup-ci
ADD install_gcc48.sh /setup-ci
ADD install_bazelisk.sh /setup-ci
ADD install_protobuf.sh /setup-ci
ADD install_format_tools.sh /setup-ci

RUN /setup-ci/setup_ci_environment.sh \
&& /setup-ci/setup_cmake.sh \
&& /setup-ci/install_gcc48.sh \
&& /setup-ci/install_bazelisk.sh \
&& /setup-ci/install_protobuf.sh \
&& /setup-ci/install_format_tools.sh
2 changes: 2 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do

* `cmake.test`: build cmake targets and run tests.
* `cmake.test_example_plugin`: build and test an example OpenTelemetry plugin.
* `cmake.exporter.otprotocol.test`: build and test the otprotocol exporter
* `bazel.test`: build bazel targets and run tests.
* `bazel.legacy.test`: build bazel targets and run tests for the targets meant to work with older compilers.
* `bazel.noexcept`: build bazel targets and run tests with exceptions disabled.
* `bazel.asan`: build bazel targets and run tests with AddressSanitizer.
* `bazel.tsan`: build bazel targets and run tests with ThreadSanitizer.
Expand Down
21 changes: 21 additions & 0 deletions ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ switch ($action) {
exit $exit
}
}
"cmake.exporter.otprotocol.test" {
cd "$BUILD_DIR"
cmake $SRC_DIR `
-DVCPKG_TARGET_TRIPLET=x64-windows `
-DWITH_OTPROTCOL=ON `
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR\scripts\buildsystems\vcpkg.cmake"
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
cmake --build .
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
}
"cmake.build_example_plugin" {
cd "$BUILD_DIR"
cmake $SRC_DIR `
Expand Down
14 changes: 14 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ if [[ "$1" == "cmake.test" ]]; then
make
make test
exit 0
elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake -DCMAKE_BUILD_TYPE=Debug \
-DWITH_OTPROTOCOL=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
"${SRC_DIR}"
make
make test
exit 0
elif [[ "$1" == "cmake.test_example_plugin" ]]; then
# Build the plugin
cd "${BUILD_DIR}"
Expand Down Expand Up @@ -58,6 +68,10 @@ elif [[ "$1" == "bazel.test" ]]; then
bazel build $BAZEL_OPTIONS //...
bazel test $BAZEL_TEST_OPTIONS //...
exit 0
elif [[ "$1" == "bazel.legacy.test" ]]; then
bazel build $BAZEL_OPTIONS -- //... -//exporters/otlp/...
bazel test $BAZEL_TEST_OPTIONS -- //... -//exporters/otlp/...
exit 0
elif [[ "$1" == "bazel.noexcept" ]]; then
bazel build --copt=-fno-exceptions $BAZEL_OPTIONS //...
bazel test --copt=-fno-exceptions $BAZEL_TEST_OPTIONS //...
Expand Down
13 changes: 13 additions & 0 deletions ci/install_protobuf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

[ -z "${PROTOBUF_VERSION}" ] && export PROTOBUF_VERSION="3.11.4"

cd /
wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz
tar zxf protobuf-cpp-${PROTOBUF_VERSION}.tar.gz --no-same-owner
cd protobuf-${PROTOBUF_VERSION}
./configure
make && make install
ldconfig
5 changes: 5 additions & 0 deletions ci/install_windows_protobuf.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$ErrorActionPreference = "Stop"
trap { $host.SetShouldExit(1) }

cd vcpkg
./vcpkg install protobuf:x64-windows
3 changes: 2 additions & 1 deletion ci/setup_ci_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ apt-get update
apt-get install --no-install-recommends --no-install-suggests -y \
build-essential \
ca-certificates \
wget
wget \
git
3 changes: 3 additions & 0 deletions exporters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(WITH_OTPROTOCOL)
add_subdirectory(otlp)
endif()
30 changes: 30 additions & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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.

package(default_visibility = ["//visibility:public"])

cc_library(
name = "recordable",
srcs = [
"recordable.cc",
],
hdrs = [
"recordable.h",
],
include_prefix = "exporters/otlp",
deps = [
"//sdk/src/trace",
"@com_github_opentelemetry_proto//:trace_proto_cc",
],
)
3 changes: 3 additions & 0 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(opentelemetry_exporter_otprotocol recordable.cc)
target_link_libraries(opentelemetry_exporter_otprotocol
$<TARGET_OBJECTS:opentelemetry_proto>)
25 changes: 25 additions & 0 deletions exporters/otlp/recordable.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "exporters/otlp/recordable.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
void Recordable::AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept
{
(void)name;
}

void Recordable::SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept
{
(void)code;
(void)description;
}

void Recordable::SetName(nostd::string_view name) noexcept
{
span_.set_name(name.data(), name.size());
}
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
29 changes: 29 additions & 0 deletions exporters/otlp/recordable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "opentelemetry/proto/trace/v1/trace.pb.h"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
class Recordable final : public sdk::trace::Recordable
{
public:
const proto::trace::v1::Span &span() const noexcept { return span_; }

// sdk::trace::Recordable
void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept override;

void SetStatus(trace::CanonicalCode code, nostd::string_view description) noexcept override;

void SetName(nostd::string_view name) noexcept override;

private:
proto::trace::v1::Span span_;
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace_api = opentelemetry::trace;
namespace trace
{
namespace trace_api = opentelemetry::trace;

/**
* Maintains a representation of a span in a format that can be processed by a recorder.
*
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/trace/recorder.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/trace_id.h"
#include "opentelemetry/version.h"
#include "src/trace/recordable.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/trace/span.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <mutex>

#include "opentelemetry/version.h"
#include "src/trace/tracer.h"

#include <mutex>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
Expand Down
Loading

0 comments on commit 4ef44ed

Please sign in to comment.