diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h index 638602715e..929dd745ee 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h @@ -58,10 +58,8 @@ class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogExporter * Shutdown this exporter. * @param timeout The maximum time to wait for the shutdown method to return. */ - bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override - { - return true; - } + bool Shutdown( + std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; private: // Configuration options for the exporter @@ -79,6 +77,7 @@ class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogExporter * @param stub the service stub to be used for exporting */ OtlpGrpcLogExporter(std::unique_ptr stub); + bool is_shutdown_ = false; }; } // namespace otlp diff --git a/exporters/otlp/src/otlp_grpc_log_exporter.cc b/exporters/otlp/src/otlp_grpc_log_exporter.cc index ef11c6ac63..e656e595db 100644 --- a/exporters/otlp/src/otlp_grpc_log_exporter.cc +++ b/exporters/otlp/src/otlp_grpc_log_exporter.cc @@ -125,6 +125,11 @@ std::unique_ptr OtlpGrpcLogExporter::MakeR opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export( const nostd::span> &logs) noexcept { + if (is_shutdown_) + { + OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC log] Export failed, exporter is shutdown"); + return sdk::common::ExportResult::kFailure; + } proto::collector::logs::v1::ExportLogsServiceRequest request; OtlpRecordableUtils::PopulateRequest(logs, &request); @@ -150,6 +155,12 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export( return sdk::common::ExportResult::kSuccess; } +bool OtlpGrpcLogExporter::Shutdown(std::chrono::microseconds timeout) noexcept +{ + is_shutdown_ = true; + return true; +} + } // namespace otlp } // namespace exporter OPENTELEMETRY_END_NAMESPACE diff --git a/exporters/otlp/test/otlp_grpc_log_exporter_test.cc b/exporters/otlp/test/otlp_grpc_log_exporter_test.cc index 2269c5e3dc..0f28e46c24 100644 --- a/exporters/otlp/test/otlp_grpc_log_exporter_test.cc +++ b/exporters/otlp/test/otlp_grpc_log_exporter_test.cc @@ -65,7 +65,7 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ShutdownTest) // exporter shuold not be shutdown by default nostd::span> batch_1(&recordable_1, 1); EXPECT_CALL(*mock_stub, Export(_, _, _)) - .Times(Exactly(2)) + .Times(Exactly(1)) .WillOnce(Return(grpc::Status::OK)) .WillOnce(Return(grpc::Status::CANCELLED)); @@ -132,11 +132,9 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ExportIntegrationTest) uint8_t trace_id_bin[opentelemetry::trace::TraceId::kSize] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - char trace_id_hex[2 * opentelemetry::trace::TraceId::kSize] = {0}; opentelemetry::trace::TraceId trace_id{trace_id_bin}; - uint8_t span_id_bin[opentelemetry::trace::SpanId::kSize] = {'7', '6', '5', '4', + uint8_t span_id_bin[opentelemetry::trace::SpanId::kSize] = {'7', '6', '5', '4', '3', '2', '1', '0'}; - char span_id_hex[2 * opentelemetry::trace::SpanId::kSize] = {0}; opentelemetry::trace::SpanId span_id{span_id_bin}; auto logger = provider->GetLogger("test");