]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright The OpenTelemetry Authors |
2 | // SPDX-License-Identifier: Apache-2.0 | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include <opentelemetry/common/spin_lock_mutex.h> | |
7 | #include <opentelemetry/ext/http/client/http_client.h> | |
8 | #include <opentelemetry/sdk/trace/exporter.h> | |
9 | ||
10 | OPENTELEMETRY_BEGIN_NAMESPACE | |
11 | namespace exporter | |
12 | { | |
13 | namespace jaeger | |
14 | { | |
15 | enum class TransportFormat | |
16 | { | |
17 | kThriftUdp, | |
18 | kThriftUdpCompact, | |
19 | kThriftHttp, | |
20 | kProtobufGrpc, | |
21 | }; | |
22 | ||
23 | class ThriftSender; | |
24 | ||
25 | /** | |
26 | * Struct to hold Jaeger exporter options. | |
27 | */ | |
28 | struct JaegerExporterOptions | |
29 | { | |
30 | TransportFormat transport_format = TransportFormat::kThriftUdpCompact; | |
31 | std::string endpoint = "localhost"; | |
32 | uint16_t server_port = 6831; | |
33 | // Only applicable when using kThriftHttp transport. | |
34 | ext::http::client::Headers headers; | |
35 | }; | |
36 | ||
37 | class JaegerExporter final : public opentelemetry::sdk::trace::SpanExporter | |
38 | { | |
39 | public: | |
40 | /** | |
41 | * Create a JaegerExporter using all default options. | |
42 | */ | |
43 | JaegerExporter(); | |
44 | ||
45 | /** | |
46 | * Create a JaegerExporter using the given options. | |
47 | */ | |
48 | explicit JaegerExporter(const JaegerExporterOptions &options); | |
49 | ||
50 | /** | |
51 | * Create a span recordable. | |
52 | * @return a new initialized Recordable object. | |
53 | */ | |
54 | std::unique_ptr<opentelemetry::sdk::trace::Recordable> MakeRecordable() noexcept override; | |
55 | ||
56 | /** | |
57 | * Export a batch of spans. | |
58 | * @param spans a span of unique pointers to span recordables. | |
59 | */ | |
60 | opentelemetry::sdk::common::ExportResult Export( | |
61 | const nostd::span<std::unique_ptr<opentelemetry::sdk::trace::Recordable>> &spans) noexcept | |
62 | override; | |
63 | ||
64 | /** | |
65 | * Shutdown the exporter. | |
66 | * @param timeout an option timeout, default to max. | |
67 | */ | |
68 | bool Shutdown( | |
69 | std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override; | |
70 | ||
71 | private: | |
72 | void InitializeEndpoint(); | |
73 | ||
74 | private: | |
75 | // The configuration options associated with this exporter. | |
76 | bool is_shutdown_ = false; | |
77 | JaegerExporterOptions options_; | |
78 | std::unique_ptr<ThriftSender> sender_; | |
79 | mutable opentelemetry::common::SpinLockMutex lock_; | |
80 | bool isShutdown() const noexcept; | |
81 | // For testing | |
82 | friend class JaegerExporterTestPeer; | |
83 | /** | |
84 | * Create an JaegerExporter using the specified thrift sender. | |
85 | * Only tests can call this constructor directly. | |
86 | * @param sender the thrift sender to be used for exporting | |
87 | */ | |
88 | JaegerExporter(std::unique_ptr<ThriftSender> sender); | |
89 | }; | |
90 | ||
91 | } // namespace jaeger | |
92 | } // namespace exporter | |
93 | OPENTELEMETRY_END_NAMESPACE |