Skip to content

Commit fea4f69

Browse files
committed
fix minor logic, logging, typo, and some comments
Signed-off-by: Emelia Lei <[email protected]>
1 parent b4cdef3 commit fea4f69

File tree

5 files changed

+39
-47
lines changed

5 files changed

+39
-47
lines changed

src/groups/bmq/bmqa/bmqa_messageeventbuilder.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
#include <bslma_managedptr.h>
3434
#include <bslmf_assert.h>
3535
#include <bsls_assert.h>
36-
#include <bsls_nullptr.h>
3736
#include <bsls_performancehint.h>
38-
#include <bslstl_sharedptr.h>
3937

4038
namespace BloombergLP {
4139
namespace bmqa {
@@ -154,9 +152,9 @@ MessageEventBuilder::packMessage(const bmqa::QueueId& queueId)
154152
// If distributed tracing is enabled, create a span and inject trace
155153
// span into message properties
156154
bsl::shared_ptr<bmqp::MessageProperties> propsWithDT;
157-
bsl::shared_ptr<bmqpi::DTSpan> span;
155+
bsl::shared_ptr<bmqpi::DTSpan> childSpan;
158156
if (d_impl.d_dtTracer_sp && d_impl.d_dtContext_sp) {
159-
copyPropertiesAndInjectDT(&propsWithDT, &span, builder, queueId);
157+
copyPropertiesAndInjectDT(&propsWithDT, &childSpan, builder, queueId);
160158
}
161159

162160
if (queueSpRef->isOldStyle()) {
@@ -182,7 +180,10 @@ MessageEventBuilder::packMessage(const bmqa::QueueId& queueId)
182180
}
183181

184182
// Add message related info into the event on success.
185-
msgImplRef.d_event_p->addMessageInfo(queueSpRef, guid, corrId, span);
183+
msgImplRef.d_event_p->addMessageInfo(queueSpRef,
184+
guid,
185+
corrId,
186+
childSpan);
186187
}
187188

188189
return rc;
@@ -305,9 +306,8 @@ void MessageEventBuilder::copyPropertiesAndInjectDT(
305306
bsl::vector<unsigned char> serializedSpan;
306307
int rc = d_impl.d_dtTracer_sp->serializeSpan(&serializedSpan, childSpan);
307308
if (rc != 0) {
308-
BALL_LOG_WARN << "Failed to serialize span for trace context "
309-
<< "injection, rc: " << rc;
310-
childSpan->finish();
309+
BALL_LOG_WARN
310+
<< "Failed to serialize span for trace span injection, rc: " << rc;
311311
return; // RETURN
312312
}
313313

@@ -318,9 +318,9 @@ void MessageEventBuilder::copyPropertiesAndInjectDT(
318318
bmqp::MessageProperties::k_TRACE_PROPERTY_NAME,
319319
traceSpanData);
320320
if (rc != 0) {
321-
BALL_LOG_WARN << "Failed to inject trace span into "
322-
<< "message properties, rc: " << rc;
323-
childSpan->finish();
321+
BALL_LOG_WARN
322+
<< "Failed to inject trace span into message properties, rc: "
323+
<< rc;
324324
return; // RETURN
325325
}
326326

src/groups/bmq/bmqa/bmqa_messageeventbuilder.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,9 @@
256256

257257
#include <bmqa_message.h>
258258
#include <bmqa_messageevent.h>
259-
#include <bmqp_puteventbuilder.h>
259+
#include <bmqp_messageproperties.h>
260260
#include <bmqpi_dtcontext.h>
261261
#include <bmqpi_dttracer.h>
262-
#include <bmqt_resultcode.h>
263262

264263
// BDE
265264
#include <bsl_memory.h>
@@ -272,6 +271,8 @@ class QueueId;
272271
}
273272
namespace bmqp {
274273
class MessageGUIDGenerator;
274+
class PutEventBuilder;
275+
class MessageProperties;
275276
}
276277

277278
namespace bmqa {
@@ -316,6 +317,7 @@ struct MessageEventBuilderImpl {
316317
/// Distributed tracing tracer object.
317318
bsl::shared_ptr<bmqpi::DTTracer> d_dtTracer_sp;
318319

320+
/// Distributed tracing context object.
319321
bsl::shared_ptr<bmqpi::DTContext> d_dtContext_sp;
320322
};
321323

@@ -390,7 +392,7 @@ class MessageEventBuilder {
390392
private:
391393
// ACCESSORS
392394

393-
/// Create a distributed tracing span and inject it into message
395+
/// Create a child distributed tracing span and inject it into the message
394396
/// properties. Load into the specified `properties` a copy of the
395397
/// message properties from the specified `builder` with the trace
396398
/// context injected, and load into the specified `span` the created

src/groups/bmq/bmqa/bmqa_session.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,9 @@ void Session::loadMessageEventBuilder(MessageEventBuilder* builder)
805805

806806
builderImplRef.d_guidGenerator_sp = d_impl.d_guidGenerator_sp;
807807

808-
// Set distributed tracing tracer
809-
const bsl::shared_ptr<bmqpi::DTTracer>& tracer =
810-
d_impl.d_sessionOptions.tracer();
811-
const bsl::shared_ptr<bmqpi::DTContext>& context =
812-
d_impl.d_sessionOptions.traceContext();
813-
if (tracer && context) {
814-
builderImplRef.d_dtTracer_sp = tracer;
815-
builderImplRef.d_dtContext_sp = context;
816-
}
808+
// Set distributed tracing tracer and context
809+
builderImplRef.d_dtTracer_sp = d_impl.d_sessionOptions.tracer();
810+
builderImplRef.d_dtContext_sp = d_impl.d_sessionOptions.traceContext();
817811

818812
// Get bmqimp::Event sharedptr from MessageEventBuilderImpl
819813
bsl::shared_ptr<bmqimp::Event>& eventImplSpRef =

src/groups/bmq/bmqimp/bmqimp_brokersession.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,7 +3611,9 @@ void BrokerSession::processPushEvent(const bmqp::Event& event)
36113611
msgIterator,
36123612
"bmq.message.push",
36133613
baggage);
3614-
d_consumerSpans[guid] = span;
3614+
if (span) {
3615+
d_consumerSpans[guid] = span;
3616+
}
36153617
}
36163618

36173619
// Update event stats
@@ -5623,7 +5625,7 @@ BrokerSession::BrokerSession(
56235625
, d_usingSessionEventHandler(eventHandlerCb) // UnspecifiedBool operator ...
56245626
, d_messageCorrelationIdContainer(
56255627
d_allocators.get("messageCorrelationIdContainer"))
5626-
, d_consumerSpans(d_allocators.get("consumerSpans"))
5628+
, d_consumerSpans(allocator)
56275629
, d_fsmThread(bslmt::ThreadUtil::invalidHandle())
56285630
, d_fsmThreadChecker()
56295631
, d_fsmEventQueue(k_FSMQUEUE_INITIAL_CAPACITY,
@@ -7108,38 +7110,32 @@ bslma::ManagedPtr<void> BrokerSession::restoreDTPropertyAndActivateChildSpan(
71087110
return bslma::ManagedPtr<void>(); // RETURN
71097111
}
71107112

7111-
bmqp::MessageProperties properties;
7112-
int rc = iterator.loadMessageProperties(&properties);
7113-
if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(rc != 0)) {
7114-
BSLS_PERFORMANCEHINT_UNLIKELY_HINT;
7115-
BALL_LOG_ERROR << id()
7116-
<< "Unable to load message properties, rc: " << rc
7117-
<< "";
7118-
return bslma::ManagedPtr<void>(); // RETURN
7119-
}
7120-
71217113
// If we fail at any step, create a span without parent
71227114
bsl::shared_ptr<bmqpi::DTSpan> childSpan;
71237115
bsl::vector<unsigned char> vecUnsignedChar;
71247116

7125-
if (!properties.hasProperty(
7126-
bmqp::MessageProperties::k_TRACE_PROPERTY_NAME)) {
7127-
BALL_LOG_INFO
7128-
<< "Not restoring distributed trace from message properties. No "
7129-
"distributed trace in message properties.";
7117+
bmqp::MessageProperties properties;
7118+
const int rc = iterator.loadMessageProperties(&properties);
7119+
if (rc != 0 || !properties.hasProperty(
7120+
bmqp::MessageProperties::k_TRACE_PROPERTY_NAME)) {
7121+
// If we fail to load message properties or the property
7122+
// is not present, create a span without parent
7123+
childSpan = tracer->createChildSpan(bsl::shared_ptr<bmqpi::DTSpan>(),
7124+
operation,
7125+
baggage);
71307126
}
71317127
else {
71327128
const bsl::vector<char>& vecChar = properties.getPropertyAsBinary(
71337129
bmqp::MessageProperties::k_TRACE_PROPERTY_NAME);
71347130

71357131
vecUnsignedChar.resize(vecChar.size());
71367132
bsl::copy(vecChar.begin(), vecChar.end(), vecUnsignedChar.begin());
7137-
}
71387133

7139-
tracer->deserializeAndCreateChildSpan(&childSpan,
7140-
vecUnsignedChar,
7141-
operation,
7142-
baggage);
7134+
tracer->deserializeAndCreateChildSpan(&childSpan,
7135+
vecUnsignedChar,
7136+
operation,
7137+
baggage);
7138+
}
71437139

71447140
// scope on the childSpan if we can successfully create one
71457141
return context->scope(childSpan);

src/groups/bmq/bmqimp/bmqimp_brokersession.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,8 +1495,8 @@ class BrokerSession BSLS_CPP11_FINAL {
14951495
bmqpi::DTSpan::Baggage()) const;
14961496

14971497
/// Restore the DTContext from the properties of the given `iterator` and
1498-
/// create a child span based on the current span. Return a managed pointer
1499-
/// to the current span which might be NULL.
1498+
/// create a child span based on the current span. Return a managed
1499+
/// pointer to the current span which might be NULL.
15001500
bslma::ManagedPtr<void> restoreDTPropertyAndActivateChildSpan(
15011501
const bmqp::PushMessageIterator& iterator,
15021502
const bsl::string_view& operation,

0 commit comments

Comments
 (0)