Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build --enable_platform_specific_config
build --features=-supports_dynamic_linker
build --cxxopt=-std=c++17
build:windows --cxxopt=-std:c++17
build --copt="-Wall"
build --copt="-Werror"
build:windows --copt=/wd4716

try-import %workspace%/user.bazelrc
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ jobs:
run: |
sudo wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64
sudo chmod +x /usr/local/bin/bazel
- name: Run bazel test
- name: Run bazel test with c++11
run: |
bazel test //...
bazel test --cxxopt=-std=c++0x //...
- name: Run bazel test with c++17
run: |
bazel test --cxxopt=-std=c++17 //...

format:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![cpp2sky test](https://github.com/SkyAPM/cpp2sky/workflows/cpp2sky%20test/badge.svg)

Distributed tracing and monitor SDK in CPP for Apache SkyWalking APM
Distributed tracing and monitor SDK in CPP for Apache SkyWalking APM. This SDK is compatible with C++ 17, C++ 14, and C++ 11.
Copy link
Member

Choose a reason for hiding this comment

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

👍


## Build

Expand Down Expand Up @@ -152,7 +152,7 @@ configurations:
ignore_suffix: '/ignore, /hoge'
```

After setup configurations, try to put values with
After setup configurations, try to put values with

```
curl --request PUT --data-binary "@./config.yaml" http://localhost:8500/v1/kv/configuration-discovery.default.agentConfigurations
Expand Down
3 changes: 3 additions & 0 deletions cpp2sky/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ cc_library(
],
deps = [
":config_cc_proto",
"@com_google_absl//absl/memory:memory",
"@com_google_absl//absl/strings:strings",
"@com_google_absl//absl/types:optional",
],
visibility = ["//visibility:public"],
)
6 changes: 4 additions & 2 deletions cpp2sky/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
namespace cpp2sky {

template <class T>
static constexpr bool false_v = false;
class FalseValue {
static constexpr bool value = false;
};

#define CPP2SKY_STATIC_ASSERT(T, m) static_assert(false_v<T>, m)
#define CPP2SKY_STATIC_ASSERT(T, m) static_assert(FalseValue<T>::value, m)

} // namespace cpp2sky
5 changes: 3 additions & 2 deletions cpp2sky/internal/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#pragma once

#include <memory>
#include <string_view>

#include "absl/strings/string_view.h"

namespace cpp2sky {

Expand All @@ -26,7 +27,7 @@ class Matcher {
/**
* Check whether to match rule.
*/
virtual bool match(std::string_view target) = 0;
virtual bool match(absl::string_view target) = 0;
};

using MatcherPtr = std::unique_ptr<Matcher>;
Expand Down
7 changes: 4 additions & 3 deletions cpp2sky/propagation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#pragma once

#include <memory>
#include <string_view>

#include "absl/strings/string_view.h"

namespace cpp2sky {

Expand Down Expand Up @@ -86,8 +87,8 @@ class SpanContextExtension {

using SpanContextExtensionPtr = std::shared_ptr<SpanContextExtension>;

SpanContextPtr createSpanContext(std::string_view ctx);
SpanContextPtr createSpanContext(absl::string_view ctx);

SpanContextExtensionPtr createSpanContextExtension(std::string_view ctx);
SpanContextExtensionPtr createSpanContextExtension(absl::string_view ctx);

} // namespace cpp2sky
13 changes: 5 additions & 8 deletions cpp2sky/trace_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@

#include <spdlog/logger.h>

#include <string_view>
#include <type_traits>

#include "cpp2sky/assert.h"
#include "absl/strings/string_view.h"

namespace cpp2sky {

static constexpr std::string_view SPDLOG_LOG_FORMAT =
static constexpr absl::string_view SPDLOG_LOG_FORMAT =
"{\"level\": \"%^%l%$\", \"msg\": \"%v";

template <class T>
std::string logFormat() {
if constexpr (std::is_same_v<T, spdlog::logger>) {
return SPDLOG_LOG_FORMAT.data();
} else {
CPP2SKY_STATIC_ASSERT(T, "non-supported logger type");
}
static_assert(std::is_same<T, spdlog::logger>::value,
"non-supported logger type");
return SPDLOG_LOG_FORMAT.data();
}

} // namespace cpp2sky
37 changes: 19 additions & 18 deletions cpp2sky/tracing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

#include <list>
#include <memory>
#include <optional>
#include <string_view>

#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "cpp2sky/config.pb.h"
#include "cpp2sky/propagation.h"
#include "cpp2sky/time.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ class TracingSpan {
/**
* Get peer address.
*/
virtual std::string_view peer() const = 0;
virtual absl::string_view peer() const = 0;

/**
* Get span type.
Expand Down Expand Up @@ -88,7 +89,7 @@ class TracingSpan {
/**
* Get operation name.
*/
virtual std::string_view operationName() const = 0;
virtual absl::string_view operationName() const = 0;

/**
* Set parent span ID of this span.
Expand All @@ -98,10 +99,10 @@ class TracingSpan {
/**
* Set start time to calculate execution time.
*/
virtual void startSpan(std::string_view operation_name) = 0;
virtual void startSpan(std::string_view operation_name,
virtual void startSpan(absl::string_view operation_name) = 0;
virtual void startSpan(absl::string_view operation_name,
TimePoint<SystemTime> current_time) = 0;
virtual void startSpan(std::string_view operation_name,
virtual void startSpan(absl::string_view operation_name,
TimePoint<SteadyTime> current_time) = 0;

/**
Expand All @@ -114,7 +115,7 @@ class TracingSpan {
/**
* Set peer address for this span (lvalue)
*/
virtual void setPeer(std::string_view remote_address) = 0;
virtual void setPeer(absl::string_view remote_address) = 0;

/**
* Set span type. Entry or Exit. Entry span means origin span which doesn't
Expand Down Expand Up @@ -142,15 +143,15 @@ class TracingSpan {
/**
* Set tag to current span.
*/
virtual void addTag(std::string_view key, std::string_view value) = 0;
virtual void addTag(absl::string_view key, absl::string_view value) = 0;

/**
* Add log related with current span.
*/
virtual void addLog(std::string_view key, std::string_view value) = 0;
virtual void addLog(std::string_view key, std::string_view value,
virtual void addLog(absl::string_view key, absl::string_view value) = 0;
virtual void addLog(absl::string_view key, absl::string_view value,
TimePoint<SystemTime> current_time) = 0;
virtual void addLog(std::string_view key, std::string_view value,
virtual void addLog(absl::string_view key, absl::string_view value,
TimePoint<SteadyTime> current_time) = 0;

/**
Expand All @@ -161,7 +162,7 @@ class TracingSpan {
/**
* Set operation name.
*/
virtual void setOperationName(std::string_view operation_name) = 0;
virtual void setOperationName(absl::string_view operation_name) = 0;

/**
* Add parent segment reference to current span.
Expand Down Expand Up @@ -231,8 +232,8 @@ class TracingContext {
* @param target_address Target address to send request. For more detail:
* https://github.com/apache/skywalking-data-collect-protocol/blob/master/language-agent/Tracing.proto#L97-L101
*/
virtual std::optional<std::string> createSW8HeaderValue(
const std::string_view target_address) = 0;
virtual absl::optional<std::string> createSW8HeaderValue(
const absl::string_view target_address) = 0;

/**
* Generate Apache SkyWalking native segment object. This method **SHOULD**
Expand Down Expand Up @@ -260,7 +261,7 @@ class TracingContext {
* logging format following with any format extracted with
* cpp2sky::logFormat().
*/
virtual std::string logMessage(std::string_view message) const = 0;
virtual std::string logMessage(absl::string_view message) const = 0;
};

using TracingContextPtr = std::shared_ptr<TracingContext>;
Expand All @@ -272,7 +273,7 @@ using TracingContextPtr = std::shared_ptr<TracingContext>;
class StartEntrySpan {
public:
StartEntrySpan(TracingContextPtr tracing_context,
std::string_view operation_name)
absl::string_view operation_name)
: span_(tracing_context->createEntrySpan()) {
span_->startSpan(operation_name.data());
}
Expand All @@ -291,7 +292,7 @@ class StartEntrySpan {
class StartExitSpan {
public:
StartExitSpan(TracingContextPtr tracing_context, TracingSpanPtr parent_span,
std::string_view operation_name)
absl::string_view operation_name)
: span_(tracing_context->createExitSpan(parent_span)) {
span_->startSpan(operation_name.data());
}
Expand Down
6 changes: 3 additions & 3 deletions cpp2sky/well_known_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#pragma once

#include <string_view>
#include "absl/strings/string_view.h"

namespace cpp2sky {

static constexpr std::string_view kPropagationHeader = "sw8";
static constexpr std::string_view kPropagationExtensionHeader = "sw8-x";
static constexpr absl::string_view kPropagationHeader = "sw8";
static constexpr absl::string_view kPropagationExtensionHeader = "sw8-x";

} // namespace cpp2sky
1 change: 1 addition & 0 deletions source/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ cc_library(
"tracing_context_impl.cc",
],
deps = [
"@com_google_absl//absl/memory:memory",
"@skywalking_data_collect_protocol//language-agent:tracing_protocol_cc_proto",
"//cpp2sky:config_cc_proto",
"//cpp2sky:cpp2sky_data_interface",
Expand Down
5 changes: 2 additions & 3 deletions source/cds_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class GrpcAsyncConfigDiscoveryServiceClient final
std::shared_ptr<grpc::ChannelCredentials> cred);
~GrpcAsyncConfigDiscoveryServiceClient();

void sendMessage(CdsRequest request);
void sendMessage(CdsRequest request) override;
void startStream() override {}
CircularBuffer<CdsRequest>& pendingMessages() override { assert(false); }
grpc::CompletionQueue& completionQueue() override { return cq_; }
Expand All @@ -63,7 +63,7 @@ class GrpcAsyncConfigDiscoveryServiceStream final
DynamicConfig& config);

// AsyncStream
void sendMessage(CdsRequest request);
void sendMessage(CdsRequest request) override;

// AsyncStreamCallback
void onReady() override {}
Expand All @@ -80,7 +80,6 @@ class GrpcAsyncConfigDiscoveryServiceStream final
CdsResponse commands_;
grpc::Status status_;
grpc::ClientContext ctx_;
StreamState state_{StreamState::Initialized};
DynamicConfig& config_;

StreamCallbackTag read_done_{StreamState::ReadDone, this};
Expand Down
11 changes: 6 additions & 5 deletions source/dynamic_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
namespace cpp2sky {

namespace { // well known fields on response commands.
static constexpr std::string_view UUID_FIELD = "UUID";
static constexpr std::string_view SERIAL_NUMBER_FIELD = "SerialNumber";
static constexpr std::string_view IGNORE_SUFFIX = "ignore_suffix";
static constexpr absl::string_view UUID_FIELD = "UUID";
static constexpr absl::string_view SERIAL_NUMBER_FIELD = "SerialNumber";
static constexpr absl::string_view IGNORE_SUFFIX = "ignore_suffix";
} // namespace

using namespace spdlog;
Expand Down Expand Up @@ -69,12 +69,13 @@ void DynamicConfig::onConfigChange(skywalking::v3::Commands commands) {
config_.ignore_operation_name_suffix()) {
will_destroy_suffixes += current_suffix + ",";
}
will_destroy_suffixes = absl::StripSuffix(will_destroy_suffixes, ",");
will_destroy_suffixes =
std::string(absl::StripSuffix(will_destroy_suffixes, ","));

config_.clear_ignore_operation_name_suffix();

for (const auto& next_suffix : absl::StrSplit(target.value(), ",")) {
*config_.add_ignore_operation_name_suffix() = next_suffix;
*config_.add_ignore_operation_name_suffix() = std::string(next_suffix);
}

info("{} updated from {} to {}", IGNORE_SUFFIX.data(),
Expand Down
2 changes: 1 addition & 1 deletion source/dynamic_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include <mutex>
#include <set>
#include <string_view>

#include "absl/strings/string_view.h"
#include "cpp2sky/config.pb.h"
#include "language-agent/ConfigurationDiscoveryService.pb.h"

Expand Down
4 changes: 2 additions & 2 deletions source/grpc_async_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
#include "grpc_async_client_impl.h"

#include <chrono>
#include <string_view>
#include <thread>

#include "absl/strings/string_view.h"
#include "cpp2sky/exception.h"
#include "spdlog/spdlog.h"

namespace cpp2sky {

namespace {
static constexpr std::string_view authenticationKey = "authentication";
static constexpr absl::string_view authenticationKey = "authentication";
}

using namespace spdlog;
Expand Down
2 changes: 1 addition & 1 deletion source/matchers/suffix_matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace cpp2sky {

bool SuffixMatcher::match(std::string_view target) {
bool SuffixMatcher::match(absl::string_view target) {
for (const auto& ignore_suffix : target_suffixes_) {
if (absl::EndsWith(target, ignore_suffix)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion source/matchers/suffix_matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SuffixMatcher : public Matcher {
explicit SuffixMatcher(std::vector<std::string>&& target_suffixes)
: target_suffixes_(std::move(target_suffixes)) {}

bool match(std::string_view target) override;
bool match(absl::string_view target) override;

private:
std::vector<std::string> target_suffixes_;
Expand Down
Loading