Skip to content

Commit b2a0a56

Browse files
authored
otlp gRPC log export should fail after shutdown (#1064)
1 parent 4a49b1b commit b2a0a56

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_exporter.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogExporter
5858
* Shutdown this exporter.
5959
* @param timeout The maximum time to wait for the shutdown method to return.
6060
*/
61-
bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override
62-
{
63-
return true;
64-
}
61+
bool Shutdown(
62+
std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override;
6563

6664
private:
6765
// Configuration options for the exporter
@@ -79,6 +77,7 @@ class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogExporter
7977
* @param stub the service stub to be used for exporting
8078
*/
8179
OtlpGrpcLogExporter(std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub);
80+
bool is_shutdown_ = false;
8281
};
8382

8483
} // namespace otlp

exporters/otlp/src/otlp_grpc_log_exporter.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ std::unique_ptr<opentelemetry::sdk::logs::Recordable> OtlpGrpcLogExporter::MakeR
125125
opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export(
126126
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs) noexcept
127127
{
128+
if (is_shutdown_)
129+
{
130+
OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC log] Export failed, exporter is shutdown");
131+
return sdk::common::ExportResult::kFailure;
132+
}
128133
proto::collector::logs::v1::ExportLogsServiceRequest request;
129134
OtlpRecordableUtils::PopulateRequest(logs, &request);
130135

@@ -150,6 +155,12 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export(
150155
return sdk::common::ExportResult::kSuccess;
151156
}
152157

158+
bool OtlpGrpcLogExporter::Shutdown(std::chrono::microseconds timeout) noexcept
159+
{
160+
is_shutdown_ = true;
161+
return true;
162+
}
163+
153164
} // namespace otlp
154165
} // namespace exporter
155166
OPENTELEMETRY_END_NAMESPACE

exporters/otlp/test/otlp_grpc_log_exporter_test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ShutdownTest)
6565
// exporter shuold not be shutdown by default
6666
nostd::span<std::unique_ptr<sdk::logs::Recordable>> batch_1(&recordable_1, 1);
6767
EXPECT_CALL(*mock_stub, Export(_, _, _))
68-
.Times(Exactly(2))
68+
.Times(Exactly(1))
6969
.WillOnce(Return(grpc::Status::OK))
7070
.WillOnce(Return(grpc::Status::CANCELLED));
7171

@@ -132,11 +132,9 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ExportIntegrationTest)
132132

133133
uint8_t trace_id_bin[opentelemetry::trace::TraceId::kSize] = {
134134
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
135-
char trace_id_hex[2 * opentelemetry::trace::TraceId::kSize] = {0};
136135
opentelemetry::trace::TraceId trace_id{trace_id_bin};
137-
uint8_t span_id_bin[opentelemetry::trace::SpanId::kSize] = {'7', '6', '5', '4',
136+
uint8_t span_id_bin[opentelemetry::trace::SpanId::kSize] = {'7', '6', '5', '4',
138137
'3', '2', '1', '0'};
139-
char span_id_hex[2 * opentelemetry::trace::SpanId::kSize] = {0};
140138
opentelemetry::trace::SpanId span_id{span_id_bin};
141139

142140
auto logger = provider->GetLogger("test");

0 commit comments

Comments
 (0)