Skip to content

Commit

Permalink
Merge branch 'main' into multi-callback-approach
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Aug 3, 2022
2 parents a2c9ceb + d299348 commit f4b6b37
Show file tree
Hide file tree
Showing 36 changed files with 894 additions and 110 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug on Windows",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/build/<path-to-bin-file>",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
},
{
"name": "Debug on Linux",
"type": "gdb",
"request": "launch",
"target": "${workspaceFolder}/bazel-bin/<path to the bin file>",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
}
]
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Increment the:

## [Unreleased]

* [LOG SDK] Add log sdk builders (#1486) [#1524](https://github.com/open-telemetry/opentelemetry-cpp/pull/1524)

## [1.5.0] 2022-07-29

* [EXPORTER BUILD] Add resources to dep list of prometheus exporter test [#1527](https://github.com/open-telemetry/opentelemetry-cpp/pull/1527)
Expand Down
21 changes: 8 additions & 13 deletions examples/otlp/grpc_log_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

#ifdef ENABLE_LOGS_PREVIEW
// Make sure to include GRPC exporter first because otherwise Abseil may create
// ambiguity with `nostd::variant`. See issue:
// https://github.com/open-telemetry/opentelemetry-cpp/issues/880
# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h"

# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h"
# include "opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h"
# include "opentelemetry/logs/provider.h"
# include "opentelemetry/sdk/logs/logger_provider.h"
# include "opentelemetry/sdk/logs/simple_log_processor.h"
# include "opentelemetry/sdk/logs/logger_provider_factory.h"
# include "opentelemetry/sdk/logs/simple_log_processor_factory.h"
# include "opentelemetry/sdk/trace/simple_processor_factory.h"
# include "opentelemetry/sdk/trace/tracer_provider_factory.h"
# include "opentelemetry/trace/provider.h"
Expand Down Expand Up @@ -47,12 +43,11 @@ void InitTracer()
void InitLogger()
{
// Create OTLP exporter instance
auto exporter = std::unique_ptr<logs_sdk::LogExporter>(new otlp::OtlpGrpcLogExporter(opts));
auto sdkProvider = std::shared_ptr<logs_sdk::LoggerProvider>(
new logs_sdk::LoggerProvider(std::unique_ptr<logs_sdk::LogProcessor>(
new logs_sdk::SimpleLogProcessor(std::move(exporter)))));
auto apiProvider = nostd::shared_ptr<logs::LoggerProvider>(sdkProvider);
auto provider = nostd::shared_ptr<logs::LoggerProvider>(apiProvider);
auto exporter = otlp::OtlpGrpcLogExporterFactory::Create(opts);
auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter));
nostd::shared_ptr<logs::LoggerProvider> provider(
logs_sdk::LoggerProviderFactory::Create(std::move(processor)));

opentelemetry::logs::Provider::SetLoggerProvider(provider);
}
} // namespace
Expand Down
19 changes: 9 additions & 10 deletions examples/otlp/http_log_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#ifdef ENABLE_LOGS_PREVIEW
# include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
# include "opentelemetry/exporters/otlp/otlp_http_log_exporter.h"
# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h"
# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h"
# include "opentelemetry/logs/provider.h"
# include "opentelemetry/sdk/logs/logger_provider.h"
# include "opentelemetry/sdk/logs/simple_log_processor.h"
# include "opentelemetry/sdk/logs/logger_provider_factory.h"
# include "opentelemetry/sdk/logs/simple_log_processor_factory.h"
# include "opentelemetry/sdk/trace/simple_processor_factory.h"
# include "opentelemetry/sdk/trace/tracer_provider_factory.h"
# include "opentelemetry/trace/provider.h"
Expand Down Expand Up @@ -46,13 +47,11 @@ void InitLogger()
{
logger_opts.console_debug = true;
// Create OTLP exporter instance
auto exporter =
std::unique_ptr<logs_sdk::LogExporter>(new otlp::OtlpHttpLogExporter(logger_opts));
auto sdkProvider = std::shared_ptr<logs_sdk::LoggerProvider>(
new logs_sdk::LoggerProvider(std::unique_ptr<logs_sdk::LogProcessor>(
new logs_sdk::SimpleLogProcessor(std::move(exporter)))));
auto apiProvider = nostd::shared_ptr<logs::LoggerProvider>(sdkProvider);
auto provider = nostd::shared_ptr<logs::LoggerProvider>(apiProvider);
auto exporter = otlp::OtlpHttpLogExporterFactory::Create(logger_opts);
auto processor = logs_sdk::SimpleLogProcessorFactory::Create(std::move(exporter));
std::shared_ptr<logs::LoggerProvider> provider =
logs_sdk::LoggerProviderFactory::Create(std::move(processor));

opentelemetry::logs::Provider::SetLoggerProvider(provider);
}
} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# include "nlohmann/json.hpp"
# include "opentelemetry/common/spin_lock_mutex.h"
# include "opentelemetry/ext/http/client/curl/http_client_curl.h"
# include "opentelemetry/ext/http/client/http_client_factory.h"
# include "opentelemetry/nostd/type_traits.h"
# include "opentelemetry/sdk/logs/exporter.h"
# include "opentelemetry/sdk/logs/log_record.h"
Expand Down Expand Up @@ -104,7 +104,7 @@ class ElasticsearchLogExporter final : public opentelemetry::sdk::logs::LogExpor
ElasticsearchExporterOptions options_;

// Object that stores the HTTP sessions that have been created
std::unique_ptr<ext::http::client::HttpClient> http_client_;
std::shared_ptr<ext::http::client::HttpClient> http_client_;
mutable opentelemetry::common::SpinLockMutex lock_;
bool isShutdown() const noexcept;
};
Expand Down
5 changes: 3 additions & 2 deletions exporters/elasticsearch/src/es_log_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# include <sstream> // std::stringstream

# include <condition_variable>
# include <mutex>
# include "opentelemetry/exporters/elasticsearch/es_log_exporter.h"
# include "opentelemetry/exporters/elasticsearch/es_log_recordable.h"
Expand Down Expand Up @@ -225,11 +226,11 @@ class AsyncResponseHandler : public http_client::EventHandler

ElasticsearchLogExporter::ElasticsearchLogExporter()
: options_{ElasticsearchExporterOptions()},
http_client_{new ext::http::client::curl::HttpClient()}
http_client_{ext::http::client::HttpClientFactory::Create()}
{}

ElasticsearchLogExporter::ElasticsearchLogExporter(const ElasticsearchExporterOptions &options)
: options_{options}, http_client_{new ext::http::client::curl::HttpClient()}
: options_{options}, http_client_{ext::http::client::HttpClientFactory::Create()}
{}

std::unique_ptr<sdklogs::Recordable> ElasticsearchLogExporter::MakeRecordable() noexcept
Expand Down
37 changes: 37 additions & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ cc_library(
name = "otlp_http_log_exporter",
srcs = [
"src/otlp_http_log_exporter.cc",
"src/otlp_http_log_exporter_factory.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_http_log_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_http_log_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
Expand Down Expand Up @@ -192,11 +195,13 @@ cc_library(
name = "otlp_grpc_log_exporter",
srcs = [
"src/otlp_grpc_log_exporter.cc",
"src/otlp_grpc_log_exporter_factory.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter_factory.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
Expand Down Expand Up @@ -324,6 +329,22 @@ cc_test(
],
)

cc_test(
name = "otlp_http_log_exporter_factory_test",
srcs = ["test/otlp_http_log_exporter_factory_test.cc"],
tags = [
"otlp",
"otlp_http_log",
"test",
],
deps = [
":otlp_http_log_exporter",
"//api",
"//ext/src/http/client/nosend:http_client_nosend",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "otlp_http_metric_exporter_test",
srcs = ["test/otlp_http_metric_exporter_test.cc"],
Expand Down Expand Up @@ -356,6 +377,22 @@ cc_test(
],
)

cc_test(
name = "otlp_grpc_log_exporter_factory_test",
srcs = ["test/otlp_grpc_log_exporter_factory_test.cc"],
tags = [
"otlp",
"otlp_grpc_log",
"test",
],
deps = [
":otlp_grpc_log_exporter",
"//api",
"//sdk/src/logs",
"@com_google_googletest//:gtest_main",
],
)

otel_cc_benchmark(
name = "otlp_grpc_exporter_benchmark",
srcs = ["test/otlp_grpc_exporter_benchmark.cc"],
Expand Down
32 changes: 28 additions & 4 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ if(WITH_OTLP_GRPC)

list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_grpc)

add_library(opentelemetry_exporter_otlp_grpc_log
src/otlp_grpc_log_exporter.cc)
add_library(
opentelemetry_exporter_otlp_grpc_log src/otlp_grpc_log_exporter.cc
src/otlp_grpc_log_exporter_factory.cc)

set_target_properties(opentelemetry_exporter_otlp_grpc_log
PROPERTIES EXPORT_NAME otlp_grpc_log_exporter)
Expand Down Expand Up @@ -90,8 +91,9 @@ if(WITH_OTLP_HTTP)
list(APPEND OPENTELEMETRY_OTLP_TARGETS opentelemetry_exporter_otlp_http)

if(WITH_LOGS_PREVIEW)
add_library(opentelemetry_exporter_otlp_http_log
src/otlp_http_log_exporter.cc)
add_library(
opentelemetry_exporter_otlp_http_log
src/otlp_http_log_exporter.cc src/otlp_http_log_exporter_factory.cc)

set_target_properties(opentelemetry_exporter_otlp_http_log
PROPERTIES EXPORT_NAME otlp_http_log_exporter)
Expand Down Expand Up @@ -216,6 +218,17 @@ if(BUILD_TESTING)
TARGET otlp_grpc_log_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_log_exporter_test)

add_executable(otlp_grpc_log_exporter_factory_test
test/otlp_grpc_log_exporter_factory_test.cc)
target_link_libraries(
otlp_grpc_log_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB}
opentelemetry_exporter_otlp_grpc_log opentelemetry_logs)
gtest_add_tests(
TARGET otlp_grpc_log_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_log_exporter_factory_test)
endif()
endif()

Expand Down Expand Up @@ -254,6 +267,17 @@ if(BUILD_TESTING)
TARGET otlp_http_log_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_log_exporter_test)

add_executable(otlp_http_log_exporter_factory_test
test/otlp_http_log_exporter_factory_test.cc)
target_link_libraries(
otlp_http_log_exporter_factory_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB}
opentelemetry_exporter_otlp_http_log opentelemetry_logs)
gtest_add_tests(
TARGET otlp_http_log_exporter_factory_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_http_log_exporter_factory_test)
endif()

if(NOT WITH_METRICS_PREVIEW)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#ifdef ENABLE_LOGS_PREVIEW

# include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"
# include "opentelemetry/sdk/logs/exporter.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{

/**
* Factory class for OtlpGrpcLogExporter.
*/
class OtlpGrpcLogExporterFactory
{
public:
/**
* Create a OtlpGrpcLogExporter.
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogExporter> Create();

/**
* Create a OtlpGrpcLogExporter.
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogExporter> Create(
const OtlpGrpcExporterOptions &options);
};

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

#endif /* ENABLE_LOGS_PREVIEW */
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class OtlpHttpClient
event_handle.swap(input_handle);
}

inline explicit HttpSessionData(HttpSessionData &&other)
inline HttpSessionData(HttpSessionData &&other)
{
session.swap(other.session);
event_handle.swap(other.event_handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# include "opentelemetry/exporters/otlp/otlp_http_client.h"

# include "opentelemetry/exporters/otlp/otlp_environment.h"
# include "opentelemetry/exporters/otlp/otlp_http_log_exporter_options.h"

# include <chrono>
# include <cstddef>
Expand All @@ -21,47 +22,6 @@ namespace exporter
namespace otlp
{

/**
* Struct to hold OTLP exporter options.
*/
struct OtlpHttpLogExporterOptions
{
// The endpoint to export to. By default
// @see
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md
// @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver
std::string url = GetOtlpDefaultHttpLogEndpoint();

// By default, post json data
HttpRequestContentType content_type = HttpRequestContentType::kJson;

// If convert bytes into hex. By default, we will convert all bytes but id into base64
// This option is ignored if content_type is not kJson
JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId;

// If using the json name of protobuf field to set the key of json. By default, we will use the
// field name just like proto files.
bool use_json_name = false;

// Whether to print the status of the exporter in the console
bool console_debug = false;

// TODO: Enable/disable to verify SSL certificate
std::chrono::system_clock::duration timeout = GetOtlpDefaultLogTimeout();

// Additional HTTP headers
OtlpHeaders http_headers = GetOtlpDefaultLogHeaders();

# ifdef ENABLE_ASYNC_EXPORT
// Concurrent requests
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlpgrpc-concurrent-requests
std::size_t max_concurrent_requests = 64;

// Requests per connections
std::size_t max_requests_per_connection = 8;
# endif
};

/**
* The OTLP exporter exports log data in OpenTelemetry Protocol (OTLP) format.
*/
Expand Down
Loading

0 comments on commit f4b6b37

Please sign in to comment.