diff --git a/.vscode/launch.json b/.vscode/launch.json index 3532ca4d2a..0f7d2590bc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,24 +1,24 @@ { "version": "0.2.0", "configurations": [ - { - "name": "Debug on Windows", - "type": "cppvsdbg", - "request": "launch", - "program": "${workspaceFolder}/build/", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false - }, - { - "name": "Debug on Linux", - "type": "gdb", - "request": "launch", - "target": "${workspaceFolder}/bazel-bin/", - "cwd": "${workspaceRoot}", - "valuesFormatting": "parseText" - } + { + "name": "Debug on Windows", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceFolder}/build/exporters/ostream/Debug/ostream_log_test.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false + }, + { + "name": "Debug on Linux", + "type": "gdb", + "request": "launch", + "target": "${workspaceFolder}/bazel-bin/", + "cwd": "${workspaceRoot}", + "valuesFormatting": "parseText" + } ] } diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h index 4ac2c4fe01..75defd6b42 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client.h @@ -9,6 +9,17 @@ #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h" +#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" + +#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" +#include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h" + +#ifdef ENABLE_LOGS_PREVIEW +# include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h" +#endif + +#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter { @@ -33,14 +44,49 @@ class OtlpGrpcClient const OtlpGrpcExporterOptions &options); /** - * Create service stub to communicate with the OpenTelemetry Collector. + * Create gRPC CompletionQueue to async call RPC. + */ + static std::unique_ptr MakeCompletionQueue(); + + /** + * Create trace service stub to communicate with the OpenTelemetry Collector. + */ + static std::unique_ptr + MakeTraceServiceStub(const OtlpGrpcExporterOptions &options); + + /** + * Create metrics service stub to communicate with the OpenTelemetry Collector. + */ + static std::unique_ptr + MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options); + +#ifdef ENABLE_LOGS_PREVIEW + /** + * Create logs service stub to communicate with the OpenTelemetry Collector. */ - template - static std::unique_ptr MakeServiceStub( - const OtlpGrpcExporterOptions &options) - { - return ServiceType::NewStub(MakeChannel(options)); - } + static std::unique_ptr + MakeLogsServiceStub(const OtlpGrpcExporterOptions &options); +#endif + + static grpc::Status DelegateExport( + proto::collector::trace::v1::TraceService::StubInterface *stub, + grpc::ClientContext *context, + const proto::collector::trace::v1::ExportTraceServiceRequest &request, + proto::collector::trace::v1::ExportTraceServiceResponse *response); + + static grpc::Status DelegateExport( + proto::collector::metrics::v1::MetricsService::StubInterface *stub, + grpc::ClientContext *context, + const proto::collector::metrics::v1::ExportMetricsServiceRequest &request, + proto::collector::metrics::v1::ExportMetricsServiceResponse *response); + +#ifdef ENABLE_LOGS_PREVIEW + static grpc::Status DelegateExport( + proto::collector::logs::v1::LogsService::StubInterface *stub, + grpc::ClientContext *context, + const proto::collector::logs::v1::ExportLogsServiceRequest &request, + proto::collector::logs::v1::ExportLogsServiceResponse *response); +#endif }; } // namespace otlp } // namespace exporter diff --git a/exporters/otlp/src/otlp_grpc_client.cc b/exporters/otlp/src/otlp_grpc_client.cc index 158f276000..9250f87cc4 100644 --- a/exporters/otlp/src/otlp_grpc_client.cc +++ b/exporters/otlp/src/otlp_grpc_client.cc @@ -103,6 +103,60 @@ std::unique_ptr OtlpGrpcClient::MakeClientContext( return context; } +std::unique_ptr OtlpGrpcClient::MakeCompletionQueue() +{ + return std::unique_ptr(new grpc::CompletionQueue()); +} + +std::unique_ptr +OtlpGrpcClient::MakeTraceServiceStub(const OtlpGrpcExporterOptions &options) +{ + return proto::collector::trace::v1::TraceService::NewStub(MakeChannel(options)); +} + +std::unique_ptr +OtlpGrpcClient::MakeMetricsServiceStub(const OtlpGrpcExporterOptions &options) +{ + return proto::collector::metrics::v1::MetricsService::NewStub(MakeChannel(options)); +} + +#ifdef ENABLE_LOGS_PREVIEW +std::unique_ptr +OtlpGrpcClient::MakeLogsServiceStub(const OtlpGrpcExporterOptions &options) +{ + return proto::collector::logs::v1::LogsService::NewStub(MakeChannel(options)); +} +#endif + +grpc::Status OtlpGrpcClient::DelegateExport( + proto::collector::trace::v1::TraceService::StubInterface *stub, + grpc::ClientContext *context, + const proto::collector::trace::v1::ExportTraceServiceRequest &request, + proto::collector::trace::v1::ExportTraceServiceResponse *response) +{ + return stub->Export(context, request, response); +} + +grpc::Status OtlpGrpcClient::DelegateExport( + proto::collector::metrics::v1::MetricsService::StubInterface *stub, + grpc::ClientContext *context, + const proto::collector::metrics::v1::ExportMetricsServiceRequest &request, + proto::collector::metrics::v1::ExportMetricsServiceResponse *response) +{ + return stub->Export(context, request, response); +} + +#ifdef ENABLE_LOGS_PREVIEW +grpc::Status OtlpGrpcClient::DelegateExport( + proto::collector::logs::v1::LogsService::StubInterface *stub, + grpc::ClientContext *context, + const proto::collector::logs::v1::ExportLogsServiceRequest &request, + proto::collector::logs::v1::ExportLogsServiceResponse *response) +{ + return stub->Export(context, request, response); +} +#endif + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/src/otlp_grpc_exporter.cc b/exporters/otlp/src/otlp_grpc_exporter.cc index 5f4cbc99e2..c22ca5a54d 100644 --- a/exporters/otlp/src/otlp_grpc_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_exporter.cc @@ -23,9 +23,7 @@ namespace otlp OtlpGrpcExporter::OtlpGrpcExporter() : OtlpGrpcExporter(OtlpGrpcExporterOptions()) {} OtlpGrpcExporter::OtlpGrpcExporter(const OtlpGrpcExporterOptions &options) - : options_(options), - trace_service_stub_( - OtlpGrpcClient::MakeServiceStub(options)) + : options_(options), trace_service_stub_(OtlpGrpcClient::MakeTraceServiceStub(options)) {} OtlpGrpcExporter::OtlpGrpcExporter( @@ -60,7 +58,8 @@ sdk::common::ExportResult OtlpGrpcExporter::Export( auto context = OtlpGrpcClient::MakeClientContext(options_); proto::collector::trace::v1::ExportTraceServiceResponse response; - grpc::Status status = trace_service_stub_->Export(context.get(), request, &response); + grpc::Status status = + OtlpGrpcClient::DelegateExport(trace_service_stub_.get(), context.get(), request, &response); if (!status.ok()) { diff --git a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc index e8a3b8a46a..6f6bb38b65 100644 --- a/exporters/otlp/src/otlp_grpc_log_record_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_record_exporter.cc @@ -36,9 +36,7 @@ OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter() {} OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter(const OtlpGrpcExporterOptions &options) - : options_(options), - log_service_stub_( - OtlpGrpcClient::MakeServiceStub(options)) + : options_(options), log_service_stub_(OtlpGrpcClient::MakeLogsServiceStub(options)) {} OtlpGrpcLogRecordExporter::OtlpGrpcLogRecordExporter( @@ -74,7 +72,8 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export( auto context = OtlpGrpcClient::MakeClientContext(options_); proto::collector::logs::v1::ExportLogsServiceResponse response; - grpc::Status status = log_service_stub_->Export(context.get(), request, &response); + grpc::Status status = + OtlpGrpcClient::DelegateExport(log_service_stub_.get(), context.get(), request, &response); if (!status.ok()) { diff --git a/exporters/otlp/src/otlp_grpc_metric_exporter.cc b/exporters/otlp/src/otlp_grpc_metric_exporter.cc index 3fd50e421b..fd503f9836 100644 --- a/exporters/otlp/src/otlp_grpc_metric_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_metric_exporter.cc @@ -25,8 +25,7 @@ OtlpGrpcMetricExporter::OtlpGrpcMetricExporter(const OtlpGrpcMetricExporterOptio : options_(options), aggregation_temporality_selector_{ OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)}, - metrics_service_stub_( - OtlpGrpcClient::MakeServiceStub(options)) + metrics_service_stub_(OtlpGrpcClient::MakeMetricsServiceStub(options)) {} OtlpGrpcMetricExporter::OtlpGrpcMetricExporter( @@ -67,7 +66,8 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcMetricExporter::Export( auto context = OtlpGrpcClient::MakeClientContext(options_); proto::collector::metrics::v1::ExportMetricsServiceResponse response; - grpc::Status status = metrics_service_stub_->Export(context.get(), request, &response); + grpc::Status status = OtlpGrpcClient::DelegateExport(metrics_service_stub_.get(), context.get(), + request, &response); if (!status.ok()) {