DreamPearl commented on a change in pull request #355: URL: https://github.com/apache/qpid-proton/pull/355#discussion_r831945915
########## File path: cpp/src/tracing.cpp ########## @@ -0,0 +1,255 @@ +/* + * + * 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 <opentelemetry/sdk/trace/simple_processor.h> +#include <opentelemetry/sdk/trace/tracer_provider.h> +#include <opentelemetry/trace/provider.h> +#include <opentelemetry/trace/span.h> +#include <opentelemetry/trace/tracer.h> +#include <opentelemetry/trace/context.h> +#include <opentelemetry/nostd/unique_ptr.h> +#include <opentelemetry/context/propagation/global_propagator.h> +#include <opentelemetry/trace/propagation/http_trace_context.h> +#include <opentelemetry/exporters/jaeger/jaeger_exporter.h> +#include <opentelemetry/exporters/ostream/span_exporter.h> + +#include <proton/messaging_handler.hpp> + +#include <proton/annotation_key.hpp> +#include <proton/delivery.hpp> +#include <proton/message.hpp> +#include <proton/receiver.hpp> +#include <proton/sender.hpp> +#include <proton/source.hpp> +#include <proton/target.hpp> +#include <proton/tracing.hpp> +#include <proton/tracker.hpp> +#include <proton/transfer.hpp> + +#include "proton/link.hpp" +#include <proton/link.h> + +#include "tracing_private.hpp" + +#include <iostream> +#include <sstream> +#include <memory> + +namespace proton +{ +namespace nostd = opentelemetry::nostd; +namespace sdktrace = opentelemetry::sdk::trace; + +const std::string kContextKey = "x-opt-qpid-tracestate"; + +// TODO: Delete map entries to avoid memory leakage in future +std::map<binary, nostd::shared_ptr<opentelemetry::trace::Span>> tag_span; + +class AMQPMapCarrier : public opentelemetry::context::propagation::TextMapCarrier { + public: + AMQPMapCarrier(const proton::map<annotation_key, value>* message_annotations) : message_annotations_(message_annotations) {} + virtual nostd::string_view Get(nostd::string_view key) const noexcept override { + std::string key_to_compare = key.data(); + + proton::value v_tracing_map = message_annotations_->get(annotation_key(kContextKey)); + proton::map<proton::annotation_key, proton::value> tracing_map; + + if (!v_tracing_map.empty()) + get(v_tracing_map, tracing_map); + + if (tracing_map.exists(annotation_key(key_to_compare))) { + value extracted_value = tracing_map.get(annotation_key(key_to_compare)); + std::string extracted_string = to_string(extracted_value); + extracted_strings.push_back(extracted_string); + nostd::string_view final_extracted_string = nostd::string_view(extracted_strings.back()); + + return final_extracted_string; + } + return ""; + } + virtual void Set(nostd::string_view key, + nostd::string_view val) noexcept override { + + proton::value v_tracing_map = message_annotations_->get(annotation_key(kContextKey)); + proton::map<proton::annotation_key, proton::value> tracing_map; + + if (!v_tracing_map.empty()) + get(v_tracing_map, tracing_map); + + tracing_map.put(annotation_key(std::string(key)), value(std::string(val))); + ((proton::map<proton::annotation_key, proton::value>*)message_annotations_)->put(annotation_key(kContextKey), tracing_map); + } + + const proton::map<annotation_key, value>* message_annotations_; + mutable std::vector<std::string> extracted_strings; +}; + +nostd::shared_ptr<opentelemetry::trace::Tracer> get_tracer() { + auto provider = opentelemetry::trace::Provider::GetTracerProvider(); + nostd::shared_ptr<opentelemetry::trace::Tracer> tracer = provider->GetTracer("qpid-tracer"); + return tracer; +} + +class OpentelemetryTracing : public Tracing { + public: + void message_encode(const message& m, std::vector<char>& buf, const binary& tag, const tracker& track) override { + proton::message message_cp = m; + Tracing& ot = Tracing::getTracing(); Review comment: Make sense. And I went with removing the send span completely. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
