-
Notifications
You must be signed in to change notification settings - Fork 439
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
Zipkin exporter #471
Merged
Merged
Zipkin exporter #471
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
8fd81b0
zipkin changes
lalitb a532b72
reformat
lalitb 861da22
fix cmake format
lalitb 586d5c9
fix build
lalitb babbc5d
remove formats
lalitb 5570d18
remove console debugs
lalitb 1039f4c
remove debug
lalitb fd5a5b6
Update exporters/zipkin/CMakeLists.txt
lalitb d4f22e3
fix endpoint
lalitb 0fbe3af
add noop response
lalitb 6d3e445
Merge branch 'master' into zipkin
lalitb cdf5dc4
fix nullptr for http errors
lalitb 19d789f
remove otlp stuff
lalitb 84b0458
fix sync mode
lalitb 93beff6
merge conflict
lalitb 81049c7
merge conflict
lalitb 791e2a1
fixes
lalitb aff76e2
fix
lalitb dcc758b
fix
lalitb b3e96c7
fix spell
lalitb 4c97dc7
fix
lalitb 3806ee2
fix
lalitb 0125752
fix
lalitb ae0a1a0
fix
lalitb 8c351c1
review fix
lalitb b2cfa8e
Merge branch 'main' into zipkin
lalitb 803eaa3
Merge branch 'main' into zipkin
lalitb 7283a85
fix
lalitb 67d6793
Merge branch 'main' into zipkin
lalitb 5764899
fix
lalitb 18390cf
fix
lalitb 590bbcf
Merge branch 'main' into zipkin
lalitb b54304d
fix
lalitb ad1506e
Merge branch 'zipkin' of github.com:lalitb/opentelemetry-cpp into zipkin
lalitb 7450085
Merge branch 'main' into zipkin
lalitb 11ffb1e
Merge branch 'main' into zipkin
lalitb e6e333f
Merge branch 'main' into zipkin
lalitb d4c7217
Merge branch 'main' into zipkin
lalitb 653d084
fix annotations as per specs
lalitb e0057f3
Merge branch 'zipkin' of github.com:lalitb/opentelemetry-cpp into zipkin
lalitb 6c89e4f
Merge branch 'main' into zipkin
lalitb 0eb9ce4
Merge branch 'main' into zipkin
lalitb 4633712
Update exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin…
lalitb 359a385
Update exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin…
lalitb 051fccf
fix comments
lalitb acb1040
add changelog
lalitb f97e6ca
fix md
lalitb fa6826a
fix
lalitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
lalitb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
70 changes: 70 additions & 0 deletions
70
exporters/zipkin/include/opentelemetry/exporters/zipkin/recordable.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
103 changes: 103 additions & 0 deletions
103
exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow I haven't noticed this before...
Do we need to include the actual year, or we can do something simpler like https://github.com/open-telemetry/opentelemetry-dotnet/blob/381908c089aac4fa9a2056d6bbf465b9853b81b8/src/OpenTelemetry/AssemblyInfo.cs#L2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where I copied from. Have fixed it now. Thanks for the comment.