Skip to content

Commit

Permalink
[EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options (open-tele…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Nov 13, 2023
1 parent 5bd9c65 commit 3dfcf93
Show file tree
Hide file tree
Showing 28 changed files with 945 additions and 222 deletions.
28 changes: 26 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ Increment the:
[#2385](https://github.com/open-telemetry/opentelemetry-cpp/pull/2385)
* [API] Add a new AddLink() operation to Span
[#2380](https://github.com/open-telemetry/opentelemetry-cpp/pull/2380)
* [SDK] Fix GetLogger with empty library
name[#2398](https://github.com/open-telemetry/opentelemetry-cpp/pull/2398)
* [SDK] Fix GetLogger with empty library name
[#2398](https://github.com/open-telemetry/opentelemetry-cpp/pull/2398)
* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options
[#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388)

Important changes:

Expand Down Expand Up @@ -56,6 +58,14 @@ Important changes:
* These build options are scheduled to be removed by the next release,
building without SSL/TLS will no longer be possible.

* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options
[#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388)
* `OtlpGrpcMetricExporterOptions` used to honor `_TRACES_`
environment variables, instead of `_METRICS_` environment variables.
* The implementation of `OtlpGrpcMetricExporterOptions` is now fixed.
* Please check configuration variables,
to make sure `_METRICS_` variables are set as expected.

Breaking changes:

* [BUILD] Remove WITH_REMOVE_METER_PREVIEW, use WITH_ABI_VERSION_2 instead
Expand All @@ -77,6 +87,20 @@ Breaking changes:
instead of nostd::string_view for name, version and schema to
maintain a single export definition for DLL.

* [EXPORTER] Rework OTLP/HTTP and OTLP/GRPC exporter options
[#2388](https://github.com/open-telemetry/opentelemetry-cpp/pull/2388)
* `OtlpGrpcLogRecordExporter` incorrectly used `OtlpGrpcExporterOptions`,
which are options for traces and not logs.
* This created a bug: the `OtlpGrpcLogRecordExporter` honors `_TRACES_`
environment variables, instead of `_LOGS_` environment variables.
* `OtlpGrpcLogRecordExporter` is changed to use
`OtlpGrpcLogRecordExporterOptions` instead, fixing the bug.
* User code that initializes the SDK with a GRPC Log exporter,
and uses exporter options, should adjust to replace
`OtlpGrpcExporterOptions` with `OtlpGrpcLogRecordExporterOptions`.
* Please check configuration variables,
to make sure `_LOGS_` variables are set as expected.

## [1.12.0] 2023-10-16

* [BUILD] Support `pkg-config`
Expand Down
14 changes: 10 additions & 4 deletions examples/otlp/grpc_log_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/logger_provider_factory.h"
Expand Down Expand Up @@ -37,6 +39,7 @@ namespace trace_sdk = opentelemetry::sdk::trace;
namespace
{
opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts;
opentelemetry::exporter::otlp::OtlpGrpcLogRecordExporterOptions log_opts;
void InitTracer()
{
// Create OTLP exporter instance
Expand Down Expand Up @@ -65,7 +68,7 @@ void CleanupTracer()
void InitLogger()
{
// Create OTLP exporter instance
auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(opts);
auto exporter = otlp::OtlpGrpcLogRecordExporterFactory::Create(log_opts);
auto processor = logs_sdk::SimpleLogRecordProcessorFactory::Create(std::move(exporter));
nostd::shared_ptr<logs::LoggerProvider> provider(
logs_sdk::LoggerProviderFactory::Create(std::move(processor)));
Expand All @@ -92,11 +95,14 @@ int main(int argc, char *argv[])
{
if (argc > 1)
{
opts.endpoint = argv[1];
opts.endpoint = argv[1];
log_opts.endpoint = argv[1];
if (argc > 2)
{
opts.use_ssl_credentials = true;
opts.ssl_credentials_cacert_path = argv[2];
opts.use_ssl_credentials = true;
log_opts.use_ssl_credentials = true;
opts.ssl_credentials_cacert_path = argv[2];
log_opts.ssl_credentials_cacert_path = argv[2];
}
}
InitLogger();
Expand Down
30 changes: 27 additions & 3 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cc_library(
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_client.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_utils.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
Expand All @@ -73,9 +73,11 @@ cc_library(
srcs = [
"src/otlp_grpc_exporter.cc",
"src/otlp_grpc_exporter_factory.cc",
"src/otlp_grpc_exporter_options.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h",
Expand Down Expand Up @@ -143,6 +145,7 @@ cc_library(
srcs = [
"src/otlp_http_exporter.cc",
"src/otlp_http_exporter_factory.cc",
"src/otlp_http_exporter_options.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
Expand Down Expand Up @@ -170,10 +173,11 @@ cc_library(
srcs = [
"src/otlp_grpc_metric_exporter.cc",
"src/otlp_grpc_metric_exporter_factory.cc",
"src/otlp_grpc_metric_exporter_options.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h",
Expand Down Expand Up @@ -201,6 +205,7 @@ cc_library(
srcs = [
"src/otlp_http_metric_exporter.cc",
"src/otlp_http_metric_exporter_factory.cc",
"src/otlp_http_metric_exporter_options.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
Expand Down Expand Up @@ -228,6 +233,7 @@ cc_library(
srcs = [
"src/otlp_http_log_record_exporter.cc",
"src/otlp_http_log_record_exporter_factory.cc",
"src/otlp_http_log_record_exporter_options.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
Expand Down Expand Up @@ -255,12 +261,14 @@ cc_library(
srcs = [
"src/otlp_grpc_log_record_exporter.cc",
"src/otlp_grpc_log_record_exporter_factory.cc",
"src/otlp_grpc_log_record_exporter_options.cc",
],
hdrs = [
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
Expand Down Expand Up @@ -436,6 +444,22 @@ cc_test(
],
)

cc_test(
name = "otlp_grpc_metric_exporter_test",
srcs = ["test/otlp_grpc_metric_exporter_test.cc"],
tags = [
"otlp",
"otlp_grpc_metric",
"test",
],
deps = [
":otlp_grpc_metric_exporter",
"//api",
"//sdk/src/metrics",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "otlp_grpc_metric_exporter_factory_test",
srcs = ["test/otlp_grpc_metric_exporter_factory_test.cc"],
Expand Down
35 changes: 27 additions & 8 deletions exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ if(WITH_OTLP_GRPC)
list(APPEND OPENTELEMETRY_OTLP_TARGETS
opentelemetry_exporter_otlp_grpc_client)

add_library(opentelemetry_exporter_otlp_grpc
src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc)
add_library(
opentelemetry_exporter_otlp_grpc
src/otlp_grpc_exporter.cc src/otlp_grpc_exporter_factory.cc
src/otlp_grpc_exporter_options.cc)

set_target_properties(opentelemetry_exporter_otlp_grpc
PROPERTIES EXPORT_NAME otlp_grpc_exporter)
Expand All @@ -73,7 +75,8 @@ if(WITH_OTLP_GRPC)
add_library(
opentelemetry_exporter_otlp_grpc_log
src/otlp_grpc_log_record_exporter.cc
src/otlp_grpc_log_record_exporter_factory.cc)
src/otlp_grpc_log_record_exporter_factory.cc
src/otlp_grpc_log_record_exporter_options.cc)

set_target_properties(opentelemetry_exporter_otlp_grpc_log
PROPERTIES EXPORT_NAME otlp_grpc_log_record_exporter)
Expand All @@ -88,7 +91,8 @@ if(WITH_OTLP_GRPC)

add_library(
opentelemetry_exporter_otlp_grpc_metrics
src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc)
src/otlp_grpc_metric_exporter.cc src/otlp_grpc_metric_exporter_factory.cc
src/otlp_grpc_metric_exporter_options.cc)

set_target_properties(opentelemetry_exporter_otlp_grpc_metrics
PROPERTIES EXPORT_NAME otlp_grpc_metrics_exporter)
Expand Down Expand Up @@ -130,8 +134,10 @@ if(WITH_OTLP_HTTP)
list(APPEND OPENTELEMETRY_OTLP_TARGETS
opentelemetry_exporter_otlp_http_client)

add_library(opentelemetry_exporter_otlp_http
src/otlp_http_exporter.cc src/otlp_http_exporter_factory.cc)
add_library(
opentelemetry_exporter_otlp_http
src/otlp_http_exporter.cc src/otlp_http_exporter_factory.cc
src/otlp_http_exporter_options.cc)

set_target_properties(opentelemetry_exporter_otlp_http
PROPERTIES EXPORT_NAME otlp_http_exporter)
Expand All @@ -147,7 +153,8 @@ if(WITH_OTLP_HTTP)
add_library(
opentelemetry_exporter_otlp_http_log
src/otlp_http_log_record_exporter.cc
src/otlp_http_log_record_exporter_factory.cc)
src/otlp_http_log_record_exporter_factory.cc
src/otlp_http_log_record_exporter_options.cc)

set_target_properties(opentelemetry_exporter_otlp_http_log
PROPERTIES EXPORT_NAME otlp_http_log_record_exporter)
Expand All @@ -162,7 +169,8 @@ if(WITH_OTLP_HTTP)

add_library(
opentelemetry_exporter_otlp_http_metric
src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc)
src/otlp_http_metric_exporter.cc src/otlp_http_metric_exporter_factory.cc
src/otlp_http_metric_exporter_options.cc)

set_target_properties(opentelemetry_exporter_otlp_http_metric
PROPERTIES EXPORT_NAME otlp_http_metric_exporter)
Expand Down Expand Up @@ -295,6 +303,17 @@ if(BUILD_TESTING)
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_log_record_exporter_factory_test)

add_executable(otlp_grpc_metric_exporter_test
test/otlp_grpc_metric_exporter_test.cc)
target_link_libraries(
otlp_grpc_metric_exporter_test ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${GMOCK_LIB} opentelemetry_exporter_otlp_grpc
opentelemetry_exporter_otlp_grpc_metrics)
gtest_add_tests(
TARGET otlp_grpc_metric_exporter_test
TEST_PREFIX exporter.otlp.
TEST_LIST otlp_grpc_metric_exporter_test)

add_executable(otlp_grpc_metric_exporter_factory_test
test/otlp_grpc_metric_exporter_factory_test.cc)
target_link_libraries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <memory>

#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h"

#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"

Expand All @@ -23,6 +23,8 @@ namespace exporter
namespace otlp
{

struct OtlpGrpcClientOptions;

/**
* The OTLP gRPC client contains utility functions of gRPC.
*/
Expand All @@ -32,13 +34,13 @@ class OtlpGrpcClient
/**
* Create gRPC channel from the exporter options.
*/
static std::shared_ptr<grpc::Channel> MakeChannel(const OtlpGrpcExporterOptions &options);
static std::shared_ptr<grpc::Channel> MakeChannel(const OtlpGrpcClientOptions &options);

/**
* Create gRPC client context to call RPC.
*/
static std::unique_ptr<grpc::ClientContext> MakeClientContext(
const OtlpGrpcExporterOptions &options);
const OtlpGrpcClientOptions &options);

/**
* Create gRPC CompletionQueue to async call RPC.
Expand All @@ -49,19 +51,19 @@ class OtlpGrpcClient
* Create trace service stub to communicate with the OpenTelemetry Collector.
*/
static std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface>
MakeTraceServiceStub(const OtlpGrpcExporterOptions &options);
MakeTraceServiceStub(const OtlpGrpcClientOptions &options);

/**
* Create metrics service stub to communicate with the OpenTelemetry Collector.
*/
static std::unique_ptr<proto::collector::metrics::v1::MetricsService::StubInterface>
MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options);
MakeMetricsServiceStub(const OtlpGrpcClientOptions &options);

/**
* Create logs service stub to communicate with the OpenTelemetry Collector.
*/
static std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface>
MakeLogsServiceStub(const OtlpGrpcExporterOptions &options);
MakeLogsServiceStub(const OtlpGrpcClientOptions &options);

static grpc::Status DelegateExport(
proto::collector::trace::v1::TraceService::StubInterface *stub,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

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

#include <chrono>
#include <string>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{

struct OtlpGrpcClientOptions
{
/** The endpoint to export to. */
std::string endpoint;

/** Use SSL. */
bool use_ssl_credentials;

/** CA CERT, path to a file. */
std::string ssl_credentials_cacert_path;

/** CA CERT, as a string. */
std::string ssl_credentials_cacert_as_string;

#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW
/** CLIENT KEY, path to a file. */
std::string ssl_client_key_path;

/** CLIENT KEY, as a string. */
std::string ssl_client_key_string;

/** CLIENT CERT, path to a file. */
std::string ssl_client_cert_path;

/** CLIENT CERT, as a string. */
std::string ssl_client_cert_string;
#endif

/** Export timeout. */
std::chrono::system_clock::duration timeout;

/** Additional HTTP headers. */
OtlpHeaders metadata;

/** User agent. */
std::string user_agent;
};

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Loading

0 comments on commit 3dfcf93

Please sign in to comment.