[ 
https://issues.apache.org/jira/browse/PROTON-2487?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17599486#comment-17599486
 ] 

ASF GitHub Bot commented on PROTON-2487:
----------------------------------------

DreamPearl commented on code in PR #355:
URL: https://github.com/apache/qpid-proton/pull/355#discussion_r961662573


##########
cpp/examples/tracing_client.cpp:
##########
@@ -0,0 +1,204 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "options.hpp"
+#include <proton/connection.hpp>
+#include <proton/container.hpp>
+#include <proton/delivery.hpp>
+#include <proton/message.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/receiver_options.hpp>
+#include <proton/source_options.hpp>
+#include <proton/tracing.hpp>
+#include <proton/tracker.hpp>
+#include <proton/message_id.hpp>
+
+#include <bits/stdc++.h>
+#include <iostream>
+#include <string>
+#include <vector>
+#include <map>
+
+// Include opentelemetry header files
+#include <opentelemetry/sdk/trace/simple_processor.h>
+#include <opentelemetry/sdk/trace/tracer_provider.h>
+#include <opentelemetry/trace/provider.h>
+#include <opentelemetry/nostd/unique_ptr.h>
+#include <opentelemetry/exporters/jaeger/jaeger_exporter.h>
+#include <opentelemetry/exporters/ostream/span_exporter.h>
+#include <opentelemetry/sdk/resource/resource.h>
+
+#include <opentelemetry/trace/span.h>
+#include <opentelemetry/trace/tracer.h>
+#include <opentelemetry/trace/context.h>
+
+using proton::receiver_options;
+using proton::source_options;
+
+opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider> 
provider;
+std::map<proton::message_id, std::shared_ptr<opentelemetry::trace::Scope>> 
scope_map;
+
+int id_counter = 0;
+
+class client : public proton::messaging_handler {
+  private:
+    std::string url;
+    std::vector<std::string> requests;
+    proton::sender sender;
+    proton::receiver receiver;
+
+  public:
+    client(const std::string &u, const std::vector<std::string>& r) : url(u), 
requests(r) {}
+
+    void on_container_start(proton::container &c) override {
+        sender = c.open_sender(url);
+        // Create a receiver requesting a dynamically created queue
+        // for the message source.
+        receiver_options opts = 
receiver_options().source(source_options().dynamic(true));
+        receiver = sender.connection().open_receiver("", opts);
+    }
+
+    void send_request() {
+        proton::message req;
+        req.body(requests.front());
+        req.reply_to(receiver.source().address());
+        req.id(id_counter);
+
+        opentelemetry::trace::StartSpanOptions options;
+        options.kind = opentelemetry::trace::SpanKind::kClient;
+
+        // Start a span here before send
+        opentelemetry::nostd::shared_ptr<opentelemetry::trace::Tracer> tracer 
= provider->GetTracer("qpid-tracer", OPENTELEMETRY_SDK_VERSION);
+        opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span = 
tracer->StartSpan("send_request",
+            {{"reply_to", req.reply_to()}, {"message", to_string(req.body())}},
+            options);
+        opentelemetry::trace::Scope scope = tracer->WithActiveSpan(span);
+
+        // Storing the 'scope' in a map to keep it alive and erasing it when a 
response is received.
+        scope_map[req.id()] = 
std::make_shared<opentelemetry::trace::Scope>(std::move(scope));
+        id_counter++;
+
+        sender.send(req);

Review Comment:
   This `send_request` span will show the complete request and response cycle.





> [cpp] Implement distributed tracing
> -----------------------------------
>
>                 Key: PROTON-2487
>                 URL: https://issues.apache.org/jira/browse/PROTON-2487
>             Project: Qpid Proton
>          Issue Type: New Feature
>          Components: cpp-binding
>    Affects Versions: proton-c-0.37.0
>            Reporter: Rakhi Kumari
>            Assignee: Rakhi Kumari
>            Priority: Major
>             Fix For: proton-c-0.38.0
>
>
> Implement distributed tracing using opentelemetry.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to