]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/ThriftSender.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / ThriftSender.h
1 /*
2 * Copyright (c) 2017-2018 Uber Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef JAEGERTRACING_THRIFTSENDER_H
18 #define JAEGERTRACING_THRIFTSENDER_H
19
20 #include "jaegertracing/Compilers.h"
21 #include "jaegertracing/Span.h"
22 #include "jaegertracing/Sender.h"
23 #include "jaegertracing/thrift-gen/jaeger_types.h"
24 #include "jaegertracing/utils/Transport.h"
25 #include <thrift/transport/TBufferTransports.h>
26
27 namespace jaegertracing {
28
29 class ThriftSender : public Sender {
30 public:
31 ThriftSender(std::unique_ptr<utils::Transport>&& transporter);
32
33 ~ThriftSender() { close(); }
34
35 int append(const Span& span) override;
36
37 int flush() override;
38
39 void close() override { _transporter->close(); }
40
41 protected:
42 void setClient(std::unique_ptr<utils::Transport>&& client)
43 {
44 _transporter = std::move(client);
45 }
46
47 private:
48 void resetBuffers()
49 {
50 _spanBuffer.clear();
51 _byteBufferSize = _processByteSize;
52 }
53
54 template <typename ThriftType>
55 int calcSizeOfSerializedThrift(const ThriftType& base)
56 {
57 _thriftBuffer->resetBuffer();
58 auto _protocol = _protocolFactory->getProtocol(_thriftBuffer);
59 base.write(_protocol.get());
60 uint8_t* data = nullptr;
61 uint32_t size = 0;
62 _thriftBuffer->getBuffer(&data, &size);
63 return size;
64 }
65
66 std::unique_ptr<utils::Transport> _transporter;
67 int _maxSpanBytes;
68 int _byteBufferSize;
69 std::vector<thrift::Span> _spanBuffer;
70 thrift::Process _process;
71 int _processByteSize;
72 std::unique_ptr<apache::thrift::protocol::TProtocolFactory> _protocolFactory;
73 // reuse buffer across serializations of different ThriftType for size
74 // calculation
75 std::shared_ptr<apache::thrift::transport::TMemoryBuffer> _thriftBuffer;
76 };
77
78 } // namespace jaegertracing
79
80 #endif //JAEGERTRACING_THRIFTSENDER_H