diff --git a/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp b/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp index 624de94e56..3e1c77861d 100644 --- a/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp @@ -2798,6 +2798,12 @@ class DTTestSpan : public bmqpi::DTSpan { { return d_operation; } + + int finish() const BSLS_KEYWORD_OVERRIDE + { + // NOT IMPLEMENTED + return 0; + } }; class DTTestTracer : public bmqpi::DTTracer { @@ -2834,6 +2840,26 @@ class DTTestTracer : public bmqpi::DTTracer { d_allocator_p); return result; } + + int + serializeSpan(BSLS_ANNOTATION_UNUSED bsl::vector* buffer, + BSLS_ANNOTATION_UNUSED const bsl::shared_ptr& + dtSpan) const BSLS_KEYWORD_OVERRIDE + { + // NOT IMPLEMENTED + return 0; + } + + int deserializeAndCreateChildSpan( + BSLS_ANNOTATION_UNUSED bsl::shared_ptr* child, + BSLS_ANNOTATION_UNUSED const bsl::vector& buffer, + BSLS_ANNOTATION_UNUSED const bsl::string_view& operation, + BSLS_ANNOTATION_UNUSED const bmqpi::DTSpan::Baggage& baggage) const + BSLS_KEYWORD_OVERRIDE + { + // NOT IMPLEMENTED + return 0; + } }; } // close unnamed namespace diff --git a/src/groups/bmq/bmqpi/bmqpi_dtspan.h b/src/groups/bmq/bmqpi/bmqpi_dtspan.h index 6c1869f96a..bcd207e707 100644 --- a/src/groups/bmq/bmqpi/bmqpi_dtspan.h +++ b/src/groups/bmq/bmqpi/bmqpi_dtspan.h @@ -49,6 +49,7 @@ class DTSpan { // PUBLIC CREATORS /// Destructor + /// Upon destruction, `finish()` will be called to mark the end of a span. virtual ~DTSpan(); // PUBLIC ACCESSORS @@ -56,6 +57,13 @@ class DTSpan { /// Returns the name of the operation that this `DTSpan` represents. virtual bsl::string_view operation() const = 0; + /// Mark the end of the `DTSpan`. Only the timing of the first call for a + /// given `DTSpan` will be recorded, and implementations are free to ignore + /// all further calls. A finished Span can not be re-started. If finish() + /// is not directly called, it will be called from the destructor. + /// Return 0 on success, or a non-zero error code on error. + virtual int finish() const = 0; + // ============= // class Baggage // ============= diff --git a/src/groups/bmq/bmqpi/bmqpi_dtspan.t.cpp b/src/groups/bmq/bmqpi/bmqpi_dtspan.t.cpp index e2353b9636..98868d5233 100644 --- a/src/groups/bmq/bmqpi/bmqpi_dtspan.t.cpp +++ b/src/groups/bmq/bmqpi/bmqpi_dtspan.t.cpp @@ -29,6 +29,7 @@ using namespace BloombergLP; /// A test implementation of the `bmqpi::DTSpan` protocol. struct DTSpanTestImp : public bsls::ProtocolTestImp { bsl::string_view operation() const BSLS_KEYWORD_OVERRIDE; + int finish() const BSLS_KEYWORD_OVERRIDE; }; // Define one of DTSpanTestImp methods out-of-line, to instruct the compiler to @@ -38,6 +39,11 @@ bsl::string_view DTSpanTestImp::operation() const return markDone(); } +int DTSpanTestImp::finish() const +{ + return markDone(); +}; + // ============================================================================ // TESTS // ============================================================================ diff --git a/src/groups/bmq/bmqpi/bmqpi_dttracer.h b/src/groups/bmq/bmqpi/bmqpi_dttracer.h index 45f7bbd848..ec26a60005 100644 --- a/src/groups/bmq/bmqpi/bmqpi_dttracer.h +++ b/src/groups/bmq/bmqpi/bmqpi_dttracer.h @@ -32,6 +32,7 @@ // BDE #include #include +#include namespace BloombergLP { namespace bmqpi { @@ -56,6 +57,22 @@ class DTTracer { const bsl::shared_ptr& parent, const bsl::string_view& operation, const DTSpan::Baggage& baggage = DTSpan::Baggage()) const = 0; + + /// Serialize the specified `dtSpan` into the specified `buffer`. + /// Return 0 on success, or a non-zero error code on error with `buffer` + /// being valid-but-unspecified. + virtual int serializeSpan(bsl::vector* buffer, + const bsl::shared_ptr& dtSpan) const = 0; + + /// Deserialize the specified `buffer` as a span, and then construct a + /// new `DTSpan` in `child`, representing `operation` as a child of the + /// deserialized span and having the key-value tags defined by `baggage`. + /// Return 0 on success, or a non-zero error code on error. + virtual int deserializeAndCreateChildSpan( + bsl::shared_ptr* child, + const bsl::vector& buffer, + const bsl::string_view& operation, + const DTSpan::Baggage& baggage = DTSpan::Baggage()) const = 0; }; } // close package namespace diff --git a/src/groups/bmq/bmqpi/bmqpi_dttracer.t.cpp b/src/groups/bmq/bmqpi/bmqpi_dttracer.t.cpp index 51355d652e..47d2685501 100644 --- a/src/groups/bmq/bmqpi/bmqpi_dttracer.t.cpp +++ b/src/groups/bmq/bmqpi/bmqpi_dttracer.t.cpp @@ -31,10 +31,21 @@ using namespace BloombergLP; /// A test implementation of the `bmqpi::DTTracer` protocol. struct DTTracerTestImp : public bsls::ProtocolTestImp { - virtual bsl::shared_ptr createChildSpan( + bsl::shared_ptr createChildSpan( const bsl::shared_ptr& parent, const bsl::string_view& operation, const bmqpi::DTSpan::Baggage& baggage) const BSLS_KEYWORD_OVERRIDE; + + int serializeSpan(bsl::vector* buffer, + const bsl::shared_ptr& dtSpan) const + BSLS_KEYWORD_OVERRIDE; + + int deserializeAndCreateChildSpan( + bsl::shared_ptr* child, + const bsl::vector& buffer, + const bsl::string_view& operation, + const bmqpi::DTSpan::Baggage& baggage = bmqpi::DTSpan::Baggage()) const + BSLS_KEYWORD_OVERRIDE; }; // Define one of DTTracerTestImp methods out-of-line, to instruct the @@ -47,6 +58,21 @@ DTTracerTestImp::createChildSpan(const bsl::shared_ptr&, return markDone(); } +int DTTracerTestImp::serializeSpan(bsl::vector*, + const bsl::shared_ptr&) const +{ + return markDone(); +} + +int DTTracerTestImp::deserializeAndCreateChildSpan( + bsl::shared_ptr*, + const bsl::vector&, + const bsl::string_view&, + const bmqpi::DTSpan::Baggage&) const +{ + return markDone(); +} + // ============================================================================ // TESTS // ============================================================================ @@ -100,8 +126,13 @@ static void test1_breathingTest() BMQTST_ASSERT(tracer.testVirtualDestructor()); PV("Verify that all methods are public and virtual"); - bmqpi::DTSpan::Baggage empty; + bmqpi::DTSpan::Baggage empty(bmqtst::TestHelperUtil::allocator()); + bsl::vector emptyVec(bmqtst::TestHelperUtil::allocator()); BSLS_PROTOCOLTEST_ASSERT(tracer, createChildSpan(NULL, "", empty)); + BSLS_PROTOCOLTEST_ASSERT(tracer, serializeSpan(NULL, NULL)); + BSLS_PROTOCOLTEST_ASSERT( + tracer, + deserializeAndCreateChildSpan(NULL, emptyVec, "", empty)); } // ============================================================================