opentracting
class CustomHeaderWriter : public opentracing::HTTPHeadersWriter{
public:
CustomHeaderWriter(httplib::Headers* headers) {
headers_ =headers;
}
~CustomHeaderWriter(){
headers_=nullptr;
}
opentracing::expected<void> Set(opentracing::string_view key, opentracing::string_view value) const{
headers_->emplace(key.data(), value.data());
opentracing::expected<void> _void;
return _void;
};
private:
httplib::Headers* headers_;
};
/*
httplib::Headers headers;
CustomHeaderWriter header_write(&headers);
opentracing::Tracer::Global()->Inject(context, header_write);
std::shared_ptr<httplib::Response> res;
//res = cli.Post(path.c_str(), headers,image_data, "application/octet-stream");
*/
class CustomHeaderReader : public opentracing::HTTPHeadersReader {
public:
CustomHeaderReader(const httplib::Request* req) {
req_ = req;
};
~CustomHeaderReader(){
req_=nullptr;
};
opentracing::expected<void> ForeachKey(
std::function<opentracing::expected<void> (opentracing::string_view key, opentracing::string_view value)> f) const {
for(auto it = req_->headers.begin(); it!=req_->headers.end();it++){
f(it->first, it->second);
}
};
private:
const httplib::Request* req_;
};
/*
CustomHeaderReader header_reader(&req);
auto context = opentracing::Tracer::Global()->Extract(header_reader);
auto root_span = opentracing::Tracer::Global()->StartSpan("startnewspan", { opentracing::ChildOf(context->get()) });
*/