MCPcopy Create free account
hub / github.com/apache/qpid-proton / on_message

Method on_message

cpp/examples/tracing_client.cpp:105–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 }
104
105 void on_message(proton::delivery &d, proton::message &response) override {
106 if (requests.empty()) return; // Spurious extra message!
107
108 // Converting the tag in proton::binary to std::string to add it as a span attribute. Tag in binary won't be visible.
109 proton::binary tag = d.tag();
110 std::string tag_in_string = std::string(tag);
111 std::stringstream ss;
112 for (int i = 0; i < (int)tag_in_string.length(); ++i)
113 ss << std::hex << (int)tag[i];
114 std::string delivery_tag = ss.str();
115
116 opentelemetry::trace::StartSpanOptions options;
117 options.kind = opentelemetry::trace::SpanKind::kClient;
118
119 // Get Tracer
120 opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer = provider->GetTracer("qpid-tracer", OPENTELEMETRY_SDK_VERSION);
121
122 // Start span with or without attributes as required.
123 opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> s = tracer->StartSpan("on_message",
124 {{"delivery_tag", delivery_tag}, {"message-received", to_string(response.body())}},
125 options);
126
127 // Mark span as active.
128 opentelemetry::trace::Scope sc = tracer->WithActiveSpan(s);
129
130 // Response has been received, thus erasing the 'scope' of the trace.
131 scope_map.erase(response.id());
132
133 std::cout << requests.front() << " => " << response.body() << std::endl;
134 requests.erase(requests.begin());
135
136 if (!requests.empty()) {
137 send_request();
138 } else {
139 d.connection().close();
140 }
141 }
142};
143
144int main(int argc, char **argv) {

Callers

nothing calls this directly

Calls 10

bodyMethod · 0.80
eraseMethod · 0.80
to_stringFunction · 0.50
emptyMethod · 0.45
tagMethod · 0.45
strMethod · 0.45
idMethod · 0.45
beginMethod · 0.45
closeMethod · 0.45
connectionMethod · 0.45

Tested by

no test coverage detected