Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Recordable implementation for otprotocol exporter #49

Merged
merged 49 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3503d72
Start Recorder api
rnburn Mar 3, 2020
79b4f1d
Fill out Span api
rnburn Mar 3, 2020
8bcff6e
Reformat
rnburn Mar 3, 2020
c5e9a9e
Fill out Tracer class
rnburn Mar 3, 2020
a69206f
Add cmake build
rnburn Mar 4, 2020
87170e3
Add commenting
rnburn Mar 4, 2020
4c7d2c0
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
rnburn Mar 4, 2020
320add0
Fix formatting
rnburn Mar 4, 2020
1a3761e
Reformat
rnburn Mar 4, 2020
597f0f3
Fix date
rnburn Mar 4, 2020
0d8649f
Make mutex mutable
rnburn Mar 4, 2020
c15286e
s/mutex_/mu_/
rnburn Mar 4, 2020
3c6fbb0
Remove AddEvent with steady timestamp
rnburn Mar 5, 2020
b0d1548
Fix typo
rnburn Mar 6, 2020
6210da0
Fill in IsRecordable
rnburn Mar 6, 2020
c619e2b
Set up protobuf dependency
rnburn Mar 10, 2020
84d5ccd
Install protobuf in docker image
rnburn Mar 10, 2020
23c23b6
Merge branch 'recorder-interface' into otprotocol
rnburn Mar 10, 2020
eecc683
Merge in Recordable
rnburn Mar 10, 2020
414957f
Add exporter folder
rnburn Mar 10, 2020
c8fc557
Integrate protobuf files into build
rnburn Mar 11, 2020
b98eb9d
Add otprotocol Recordable
rnburn Mar 11, 2020
d2e2198
Set up protobuf with bazel
rnburn Mar 12, 2020
f470dd0
Reformat
rnburn Mar 12, 2020
51f9182
Install git in CI
rnburn Mar 12, 2020
d240118
Add otprotocol to cmake test
rnburn Mar 12, 2020
427314a
Fix typo
rnburn Mar 12, 2020
5f5050c
Fix install_protobuf.sh
rnburn Mar 12, 2020
092bd8d
Fix install_protobuf.sh
rnburn Mar 12, 2020
a979b8e
Fix install_protobuf.sh
rnburn Mar 12, 2020
fda73fe
Fix do_ci.sh
rnburn Mar 12, 2020
366e9e0
Add otprotocol windows tests
rnburn Mar 12, 2020
9094a52
Fix typo
rnburn Mar 12, 2020
b3d611b
Make protobuf install optional for windows
rnburn Mar 12, 2020
3b94521
Fix install_windows_protobuf.ps1
rnburn Mar 12, 2020
04284e0
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
rnburn Mar 13, 2020
27e8526
Remove unnecessary globs
rnburn Mar 13, 2020
1fbb06e
Refactor
rnburn Mar 17, 2020
2f3296c
Rearrange protobuf files
rnburn Mar 19, 2020
49c27fe
Clean up workspace
rnburn Mar 19, 2020
28c8e5b
Fix formatting
rnburn Mar 19, 2020
f16dd46
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
rnburn Mar 26, 2020
6f5316c
Update CI
rnburn Mar 26, 2020
2db1682
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
rnburn Apr 4, 2020
1d83819
Restructure
rnburn Apr 4, 2020
f64c826
Reformat
rnburn Apr 4, 2020
49c375f
Refactor legacy test
rnburn Apr 6, 2020
ab62b01
Fix legacy target
rnburn Apr 6, 2020
336d466
Fix legacy target
rnburn Apr 6, 2020
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
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.test_api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API is gcc 4.8 compatible but SDK is not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protobuf can't work with gcc-4.8.

Maybe I should exclude just some portions of the sdk from legacy compiler tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you. Sorry to hear about protobuf.


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_plugin_test:
executor: win/vs2019
Expand Down
21 changes: 21 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 Down
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(
g-easy marked this conversation as resolved.
Show resolved Hide resolved
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,6 +4,8 @@ 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_api`: build bazel targets and run tests for the api only.
* `bazel.test`: build bazel targets and run tests.
* `bazel.noexcept`: build bazel targets and run tests with exceptions disabled.
* `bazel.asan`: build bazel targets and run tests with AddressSanitizer.
Expand Down
21 changes: 21 additions & 0 deletions ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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
g-easy marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -54,6 +64,10 @@ EOF
make load_plugin_example
examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null
exit 0
elif [[ "$1" == "bazel.test_api" ]]; then
bazel build $BAZEL_OPTIONS //api/...
bazel test $BAZEL_TEST_OPTIONS //api/...
exit 0
elif [[ "$1" == "bazel.test" ]]; then
bazel build $BAZEL_OPTIONS //...
bazel test $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
g-easy marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions sdk/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(trace)
add_subdirectory(exporter)
3 changes: 3 additions & 0 deletions sdk/src/exporter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(WITH_OTPROTOCOL)
add_subdirectory(otprotocol)
endif()
30 changes: 30 additions & 0 deletions sdk/src/exporter/otprotocol/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 = "src/exporter/otprotocol",
deps = [
"//sdk/src/trace",
"@com_github_opentelemetry_proto//:trace_proto_cc",
],
)
3 changes: 3 additions & 0 deletions sdk/src/exporter/otprotocol/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>)
28 changes: 28 additions & 0 deletions sdk/src/exporter/otprotocol/recordable.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "src/exporter/otprotocol/recordable.h"

OPENTELEMETRY_BEGIN_NAMESPACE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should exporters live in the internal namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated out into an exporters folder, similar to how it's done for go and java.

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

void Recordable::SetStatus(trace_api::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 otprotocol
} // namespace exporter
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
33 changes: 33 additions & 0 deletions sdk/src/exporter/otprotocol/recordable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "src/trace/recordable.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think headers needed to implement exporters should be placed in sdk/include. However, this can be done in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved Recodable into the headers folder.


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

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace exporter
{
namespace otprotocol
{
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_api::CanonicalCode code, nostd::string_view description) noexcept override;

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

private:
proto::trace::v1::Span span_;
};
} // namespace otprotocol
} // namespace exporter
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
3 changes: 1 addition & 2 deletions sdk/src/trace/recordable.h
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.
g-easy marked this conversation as resolved.
Show resolved Hide resolved
*
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