@@ -68,6 +68,10 @@ auto ExpectFlush(std::int64_t id, std::uint64_t size) {
6868 return AllOf (EventNamed (" gl-cpp.flush" ), ExpectSent (id, size));
6969}
7070
71+ auto ExpectClose (std::int64_t id, std::uint64_t size) {
72+ return AllOf (EventNamed (" gl-cpp.close" ), ExpectSent (id, size));
73+ }
74+
7175auto ExpectQuery (std::int64_t id) {
7276 namespace sc = ::opentelemetry::semconv;
7377 return AllOf (EventNamed (" gl-cpp.query" ),
@@ -248,6 +252,48 @@ TEST(WriterConnectionTracing, Cancel) {
248252 sc::thread::kThreadId , _)))))));
249253}
250254
255+ TEST (WriterConnectionTracing, Close) {
256+ auto span_catcher = InstallSpanCatcher ();
257+
258+ auto mock = std::make_unique<MockAsyncWriterConnection>();
259+ EXPECT_CALL (*mock, Close).WillOnce ([] {
260+ return make_ready_future (Status{});
261+ });
262+ auto actual = MakeTracingWriterConnection (
263+ internal::MakeSpan (" test-span-name" ), std::move (mock));
264+ auto status = actual->Close (WritePayload{std::string (1024 , ' A' )}).get ();
265+ EXPECT_STATUS_OK (status);
266+
267+ auto spans = span_catcher->GetSpans ();
268+ EXPECT_THAT (spans, ElementsAre (AllOf (
269+ SpanNamed (" test-span-name" ),
270+ SpanWithStatus (opentelemetry::trace::StatusCode::kOk ),
271+ SpanHasInstrumentationScope (), SpanKindIsClient (),
272+ SpanHasEvents (ExpectClose (1 , 1024 )))));
273+ }
274+
275+ TEST (WriterConnectionTracing, CloseError) {
276+ auto span_catcher = InstallSpanCatcher ();
277+
278+ auto mock = std::make_unique<MockAsyncWriterConnection>();
279+ EXPECT_CALL (*mock, Close).WillOnce ([] {
280+ return make_ready_future (PermanentError ());
281+ });
282+ auto actual = MakeTracingWriterConnection (
283+ internal::MakeSpan (" test-span-name" ), std::move (mock));
284+ auto status = actual->Close (WritePayload{std::string (1024 , ' A' )}).get ();
285+ EXPECT_THAT (status, StatusIs (PermanentError ().code ()));
286+
287+ auto spans = span_catcher->GetSpans ();
288+ EXPECT_THAT (
289+ spans,
290+ ElementsAre (AllOf (SpanNamed (" test-span-name" ),
291+ SpanWithStatus (opentelemetry::trace::StatusCode::kError ,
292+ PermanentError ().message ()),
293+ SpanHasInstrumentationScope (), SpanKindIsClient (),
294+ SpanHasEvents (ExpectClose (1 , 1024 )))));
295+ }
296+
251297} // namespace
252298GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
253299} // namespace storage_internal
0 commit comments