Skip to content

Commit

Permalink
Merge branch 'main' into sphinx-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Mar 4, 2021
2 parents 9305215 + 71d5b1d commit fc57519
Show file tree
Hide file tree
Showing 19 changed files with 1,061 additions and 14 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ Increment the:

## [Unreleased]

* Added `ForceFlush` to `TracerProvider` in SDK. ([#588](https://github.com/open-telemetry/opentelemetry-cpp/pull/588)).
* [EXPORTER] Added Zipkin Exporter. ([#471](https://github.com/open-telemetry/opentelemetry-cpp/pull/471))

## [0.2.0] 2021-03-02

* [SDK] Added `ForceFlush` to `TracerProvider`. ([#588](https://github.com/open-telemetry/opentelemetry-cpp/pull/588)).
* [SDK] Added Resource API. ([#502](https://github.com/open-telemetry/opentelemetry-cpp/pull/502))
* [API] Modified TraceState support for w3c trace context as per specs.
([#551](https://github.com/open-telemetry/opentelemetry-cpp/pull/551))
* [API] Added B3 Propagator. ([#523](https://github.com/open-telemetry/opentelemetry-cpp/pull/523))
* [Exporter] Added ETW Exporter. ([#376](https://github.com/open-telemetry/opentelemetry-cpp/pull/376))
* [CI] Enable cache for Bazel for faster builds. ([#505](https://github.com/open-telemetry/opentelemetry-cpp/pull/505))

## [0.0.1] 2020-12-16

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ if(WITH_STL)
endif()

option(WITH_OTLP "Whether to include the OpenTelemetry Protocol in the SDK" OFF)
option(WITH_ZIPKIN "Whether to include the Zipkin exporter in the SDK" OFF)

option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK"
OFF)
Expand Down
2 changes: 1 addition & 1 deletion api/docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PROJECT_NUMBER =
# for a project that appears at the top of each page and should give viewer a
# quick idea about the purpose of the project. Keep the description short.

PROJECT_BRIEF = "Version 0.1.0"
PROJECT_BRIEF = "Version 0.2.0"

# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
# in the documentation. The maximum height of the logo should not exceed 55
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 @@ -3,7 +3,7 @@
#include "opentelemetry/detail/preprocessor.h"

#define OPENTELEMETRY_ABI_VERSION_NO 0
#define OPENTELEMETRY_VERSION "0.1.0"
#define OPENTELEMETRY_VERSION "0.2.0"
#define OPENTELEMETRY_ABI_VERSION OPENTELEMETRY_STRINGIFY(OPENTELEMETRY_ABI_VERSION_NO)

// clang-format off
Expand Down
18 changes: 18 additions & 0 deletions exporters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021, 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.

if(WITH_OTLP)
add_subdirectory(otlp)
endif()
Expand All @@ -9,6 +23,10 @@ if(WITH_PROMETHEUS)
add_subdirectory(prometheus)
endif()

if(WITH_ZIPKIN)
add_subdirectory(zipkin)
endif()

if(WITH_ELASTICSEARCH)
add_subdirectory(elasticsearch)
endif()
Expand Down
31 changes: 31 additions & 0 deletions exporters/zipkin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2021, 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.

include_directories(include)
find_package(CURL)
if(CURL_FOUND)
add_definitions(-DWITH_CURL)
endif()
add_library(zipkin_trace_exporter src/zipkin_exporter.cc src/recordable.cc)
if(BUILD_TESTING)
add_executable(zipkin_recordable_test test/zipkin_recordable_test.cc)

target_link_libraries(zipkin_recordable_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} zipkin_trace_exporter)

gtest_add_tests(
TARGET zipkin_recordable_test
TEST_PREFIX exporter.
TEST_LIST zipkin_recordable_test)
endif() # BUILD_TESTING
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright The 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.
*/

#pragma once

#include "nlohmann/json.hpp"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace zipkin
{
using ZipkinSpan = nlohmann::json;

enum class TransportFormat
{
kJson,
kProtobuf
};

class Recordable final : public sdk::trace::Recordable
{
public:
const ZipkinSpan &span() const noexcept { return span_; }

void SetIds(trace::TraceId trace_id,
trace::SpanId span_id,
trace::SpanId parent_span_id) noexcept override;

void SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &value) noexcept override;

void AddEvent(nostd::string_view name,
core::SystemTimestamp timestamp,
const common::KeyValueIterable &attributes) noexcept override;

void AddLink(const opentelemetry::trace::SpanContext &span_context,
const common::KeyValueIterable &attributes) noexcept override;

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

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

void SetStartTime(opentelemetry::core::SystemTimestamp start_time) noexcept override;

virtual void SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept override;

void SetDuration(std::chrono::nanoseconds duration) noexcept override;

private:
ZipkinSpan span_;
};
} // namespace zipkin
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright The 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.
*/

#pragma once

#include "opentelemetry/exporters/zipkin/recordable.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"
#include "opentelemetry/ext/http/common/url_parser.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/span_data.h"

#include "nlohmann/json.hpp"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace zipkin
{

const std::string kZipkinEndpointDefault = "http://localhost:9411/api/v2/spans";

/**
* Struct to hold Zipkin exporter options.
*/
struct ZipkinExporterOptions
{
// The endpoint to export to. By default the OpenTelemetry Collector's default endpoint.
std::string endpoint = kZipkinEndpointDefault;
TransportFormat format = TransportFormat::kJson;
std::string service_name = "default-service";
std::string ipv4;
std::string ipv6;
};

namespace trace_sdk = opentelemetry::sdk::trace;
namespace http_client = opentelemetry::ext::http::client;

/**
* The Zipkin exporter exports span data in JSON format as expected by Zipkin
*/
class ZipkinExporter final : public trace_sdk::SpanExporter
{
public:
/**
* Create a ZipkinExporter using all default options.
*/
ZipkinExporter();

/**
* Create a ZipkinExporter using the given options.
*/
explicit ZipkinExporter(const ZipkinExporterOptions &options);

/**
* Create a span recordable.
* @return a newly initialized Recordable object
*/
std::unique_ptr<trace_sdk::Recordable> MakeRecordable() noexcept override;

/**
* Export a batch of span recordables in JSON format.
* @param spans a span of unique pointers to span recordables
*/
trace_sdk::ExportResult Export(
const nostd::span<std::unique_ptr<trace_sdk::Recordable>> &spans) noexcept override;

/**
* Shut down the exporter.
* @param timeout an optional timeout, default to max.
*/
bool Shutdown(
std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override
{
return true;
}

private:
void InitializeLocalEndpoint();

private:
// The configuration options associated with this exporter.
bool isShutdown_ = false;
ZipkinExporterOptions options_;
std::shared_ptr<http_client::HttpClientSync> http_client_;
opentelemetry::ext::http::common::UrlParser url_parser_;
nlohmann::json local_end_point_;
};
} // namespace zipkin
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Loading

0 comments on commit fc57519

Please sign in to comment.