Skip to content

Commit

Permalink
Merge branch 'open-telemetry:main' into otel-webserver-samplers
Browse files Browse the repository at this point in the history
  • Loading branch information
starDigger authored Mar 13, 2024
2 parents f6d868a + 8bf5ebe commit 700e892
Show file tree
Hide file tree
Showing 58 changed files with 3,890 additions and 85 deletions.
61 changes: 61 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

# See Clang docs: http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Chromium

# Allow double brackets such as std::vector<std::vector<int>>.
Standard: Cpp11

# Indent 2 spaces at a time.
IndentWidth: 2

# Keep lines under 100 columns long.
ColumnLimit: 100

# Always break before braces
BreakBeforeBraces: Custom
BraceWrapping:
# TODO(lujc) wait for clang-format-9 support in Chromium tools
# AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false

# Keeps extern "C" blocks unindented.
AfterExternBlock: false

# Indent case labels.
IndentCaseLabels: true

# Right-align pointers and references
PointerAlignment: Right

# ANGLE likes to align things as much as possible.
AlignOperands: true
AlignConsecutiveAssignments: true

# Use 2 space negative offset for access modifiers
AccessModifierOffset: -2

# TODO(jmadill): Decide if we want this on. Doesn't have an "all or none" mode.
AllowShortCaseLabelsOnASingleLine: false

# Useful for spacing out functions in classes
KeepEmptyLinesAtTheStartOfBlocks: true

# Indent nested PP directives.
IndentPPDirectives: AfterHash

# Include blocks style
IncludeBlocks: Preserve
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,47 @@ can find their home here.

## Contributing

For information on how to contribute, consult [the contributing
guidelines](./CONTRIBUTING.md)
See [CONTRIBUTING.md](CONTRIBUTING.md)

We meet weekly, and the time of the meeting alternates between Monday at 13:00
PT and Wednesday at 9:00 PT. The meeting is subject to change depending on
contributors' availability. Check the [OpenTelemetry community
calendar](https://github.com/open-telemetry/community#calendar)
for specific dates and Zoom meeting links.

Meeting notes are available as a public [Google
doc](https://docs.google.com/document/d/1i1E4-_y4uJ083lCutKGDhkpi3n4_e774SBLi9hPLocw/edit?usp=sharing).
For edit access, get in touch on
[Slack](https://cloud-native.slack.com/archives/C01N3AT62SJ).

[Maintainers](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer)
([@open-telemetry/cpp-contrib-maintainers](https://github.com/orgs/open-telemetry/teams/cpp-contrib-maintainers)):

* [Ehsan Saei](https://github.com/esigo)
* [Lalit Kumar Bhasin](https://github.com/lalitb), Microsoft
* [Marc Alff](https://github.com/marcalff), Oracle
* [Tom Tan](https://github.com/ThomsonTan), Microsoft

[Approvers](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver)
([@open-telemetry/cpp-contrib-approvers](https://github.com/orgs/open-telemetry/teams/cpp-contrib-approvers)):

* [DEBAJIT DAS](https://github.com/DebajitDas), Cisco
* [Johannes Tax](https://github.com/pyohannes), Grafana Labs
* [Josh Suereth](https://github.com/jsuereth), Google
* [Kumar Pratyush](https://github.com/kpratyus), Cisco
* [Max Golovanov](https://github.com/maxgolov), Microsoft
* [Siim Kallas](https://github.com/seemk), Splunk
* [Tobias Stadler](https://github.com/tobiasstadler)
* [Tomasz Rojek](https://github.com/TomRoSystems)

[Emeritus
Maintainer/Approver/Triager](https://github.com/open-telemetry/community/blob/main/community-membership.md#emeritus-maintainerapprovertriager):

* None

### Thanks to all the people who have contributed

[![contributors](https://contributors-img.web.app/image?repo=open-telemetry/opentelemetry-cpp-contrib)](https://github.com/open-telemetry/opentelemetry-cpp-contrib/graphs/contributors)

## Support

Expand Down
84 changes: 45 additions & 39 deletions exporters/fluentd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,78 +49,84 @@ else()
message("nlohmann_json package was not found. Cloning from github")
endif()

find_package(CURL REQUIRED)
find_package(Threads REQUIRED)
if(MAIN_PROJECT)
find_package(CURL REQUIRED)
find_package(Threads REQUIRED)
endif()

include_directories(include)

# create fluentd trace exporter
add_library(opentelemetry_exporter_fluentd_trace src/trace/fluentd_exporter.cc
src/trace/recordable.cc)
add_library(opentelemetry_exporter_geneva_trace src/trace/fluentd_exporter.cc
src/trace/recordable.cc)
if(MAIN_PROJECT)
target_include_directories(opentelemetry_exporter_fluentd_trace
target_include_directories(opentelemetry_exporter_geneva_trace
PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS})
target_link_libraries(
opentelemetry_exporter_fluentd_trace
opentelemetry_exporter_geneva_trace
PUBLIC ${OPENTELEMETRY_CPP_LIBRARIES}
INTERFACE nlohmann_json::nlohmann_json)
set_target_properties(opentelemetry_exporter_geneva_trace
PROPERTIES EXPORT_NAME trace)
else()
target_link_libraries(
opentelemetry_exporter_fluentd_trace
opentelemetry_exporter_geneva_trace
PUBLIC opentelemetry_trace opentelemetry_resources opentelemetry_common
INTERFACE nlohmann_json::nlohmann_json)
endif()

set_target_properties(opentelemetry_exporter_fluentd_trace
PROPERTIES EXPORT_NAME trace)

# create fluentd logs exporter

add_library(opentelemetry_exporter_fluentd_logs src/log/fluentd_exporter.cc
src/log/recordable.cc)
add_library(opentelemetry_exporter_geneva_logs src/log/fluentd_exporter.cc
src/log/recordable.cc)
if(MAIN_PROJECT)
target_include_directories(opentelemetry_exporter_fluentd_logs
target_include_directories(opentelemetry_exporter_geneva_logs
PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS})
target_link_libraries(
opentelemetry_exporter_fluentd_logs
opentelemetry_exporter_geneva_logs
PUBLIC ${OPENTELEMETRY_CPP_LIBRARIES}
INTERFACE nlohmann_json::nlohmann_json)

set_target_properties(opentelemetry_exporter_geneva_logs
PROPERTIES EXPORT_NAME logs)
else()
target_link_libraries(
opentelemetry_exporter_fluentd_logs
opentelemetry_exporter_geneva_logs
PUBLIC opentelemetry_logs opentelemetry_resources opentelemetry_common
INTERFACE nlohmann_json::nlohmann_json)
endif()
set_target_properties(opentelemetry_exporter_fluentd_logs PROPERTIES EXPORT_NAME
logs)

if(nlohmann_json_clone)
add_dependencies(opentelemetry_exporter_fluentd_trace
add_dependencies(opentelemetry_exporter_geneva_logs
nlohmann_json::nlohmann_json)
add_dependencies(opentelemetry_exporter_fluentd_logs
add_dependencies(opentelemetry_exporter_geneva_logs
nlohmann_json::nlohmann_json)
include_directories(${PROJECT_BINARY_DIR}/include)
endif()

add_subdirectory(example)
if(MAIN_PROJECT)
option(WITH_EXAMPLES "Build examples" ON)
endif()

install(
TARGETS opentelemetry_exporter_fluentd_trace
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (WITH_EXAMPLES)
add_subdirectory(example)
endif()

install(
TARGETS opentelemetry_exporter_fluentd_logs
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(OPENTELEMETRY_INSTALL)
install(
TARGETS opentelemetry_exporter_geneva_logs
opentelemetry_exporter_geneva_trace
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(
DIRECTORY include/opentelemetry/exporters/fluentd/
DESTINATION include/opentelemetry/exporters/fluentd/
FILES_MATCHING
PATTERN "*.h")
install(
DIRECTORY include/opentelemetry/exporters/
DESTINATION include/opentelemetry/exporters/
FILES_MATCHING
PATTERN "*.h")
endif()

if(BUILD_TESTING)
include(GoogleTest)
Expand All @@ -137,7 +143,7 @@ if(BUILD_TESTING)
opentelemetry_common
opentelemetry_trace
opentelemetry_resources
opentelemetry_exporter_fluentd_trace)
opentelemetry_exporter_geneva_trace)

if(nlohmann_json_clone)
add_dependencies(fluentd_recordable_trace_test nlohmann_json::nlohmann_json)
Expand All @@ -160,7 +166,7 @@ if(BUILD_TESTING)
opentelemetry_common
opentelemetry_logs
opentelemetry_resources
opentelemetry_exporter_fluentd_logs)
opentelemetry_exporter_geneva_logs)

if(nlohmann_json_clone)
add_dependencies(fluentd_recordable_logs_test nlohmann_json::nlohmann_json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ inline std::string AttributeValueToString(
result = std::to_string(nostd::get<double>(value));
} else if (nostd::holds_alternative<const char*>(value)) {
result = std::string(nostd::get<const char*>(value));
} else if (nostd::holds_alternative<opentelemetry::v1::nostd::string_view>(value)) {
result = std::string(nostd::get<opentelemetry::v1::nostd::string_view>(value).data());
} else if (nostd::holds_alternative<opentelemetry::nostd::string_view>(value)) {
result = std::string(nostd::get<opentelemetry::nostd::string_view>(value).data());
} else {
LOG_WARN("[Fluentd Exporter] AttributeValueToString - "
" Nested attributes not supported - ignored");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Recordable final : public sdk::trace::Recordable {
const opentelemetry::sdk::instrumentationscope::InstrumentationScope
&instrumentation_scope) noexcept override;

void SetTraceFlags(opentelemetry::trace::TraceFlags flags) noexcept override;

private:
std::string tag_;
nlohmann::json events_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <opentelemetry/exporters/fluentd/common/fluentd_common.h>
#include<string>

OPENTELEMETRY_BEGIN_NAMESPACE

namespace exporters {

namespace geneva {

constexpr const char *kUnixDomainScheme = "unix://";
constexpr const size_t kUnixDomainSchemeLength = 7; // length of "unix://"
struct GenevaExporterOptions {

/** socker path for unix domain socket. Should start with unix://
* Example unix:///tmp/.socket_geneva_exporter
*/
std::string socket_endpoint ;

/* number of retries before failing */

size_t retry_count = 2;

/**
* The maximum buffer/queue size. After the size is reached, spans/logs are
* dropped.
*/
size_t max_queue_size = 2048; // max buffer size dropping logs/spans

/* The time interval between two consecutive exports. */
std::chrono::milliseconds schedule_delay_millis = std::chrono::milliseconds(5000);

/**
* The maximum batch size of every export. It must be smaller or
* equal to max_queue_size.
*/
size_t max_export_batch_size = 512;
};

}
}
OPENTELEMETRY_END_NAMESPACE

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "geneva_exporter_options.h"
#include <opentelemetry/exporters/fluentd/common/socket_tools.h>
#include <opentelemetry/exporters/fluentd/log/fluentd_exporter.h>
#include <opentelemetry/sdk/logs/batch_log_record_processor.h>
#include <opentelemetry/sdk/logs/logger_provider.h>
#include <opentelemetry/logs/provider.h>

OPENTELEMETRY_BEGIN_NAMESPACE

namespace exporters {

namespace geneva {

class GenevaLoggerExporter {

public:

static inline bool InitializeGenevaExporter( const GenevaExporterOptions options ) {
// Use only unix-domain IPC for agent connectivity
if (options.socket_endpoint.size() > kUnixDomainSchemeLength && options.socket_endpoint.substr(0, kUnixDomainSchemeLength) == std::string(kUnixDomainScheme)){
opentelemetry::exporter::fluentd::common::FluentdExporterOptions fluentd_options;
fluentd_options.retry_count = options.retry_count;
fluentd_options.endpoint = options.socket_endpoint;
auto exporter = std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>(
new opentelemetry::exporter::fluentd::logs::FluentdExporter(fluentd_options));
auto processor = std::unique_ptr<opentelemetry::sdk::logs::LogRecordProcessor>(
new opentelemetry::sdk::logs::BatchLogRecordProcessor(std::move(exporter), options.max_queue_size, options.schedule_delay_millis, options.max_export_batch_size));
auto provider = std::shared_ptr<opentelemetry::logs::LoggerProvider>(
new opentelemetry::sdk::logs::LoggerProvider(std::move(processor)));
// Set the global logger provider
opentelemetry::logs::Provider::SetLoggerProvider(provider);
return true;
} else {
#if defined(__EXCEPTIONS)
throw new std::runtime_error("Invalid endpoint! Unix domain socket should have unix:// as url-scheme");
#endif
return false;
}
}

};
}
}
OPENTELEMETRY_END_NAMESPACE
Loading

0 comments on commit 700e892

Please sign in to comment.