|
| 1 | +// Copyright 2021, OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#pragma once |
| 16 | + |
| 17 | +#include <opentelemetry/sdk/trace/exporter.h> |
| 18 | + |
| 19 | +OPENTELEMETRY_BEGIN_NAMESPACE |
| 20 | +namespace exporter |
| 21 | +{ |
| 22 | +namespace jaeger |
| 23 | +{ |
| 24 | +enum class TransportFormat |
| 25 | +{ |
| 26 | + kThriftUdp, |
| 27 | + kThriftUdpCompact, |
| 28 | + kThriftHttp, |
| 29 | + kProtobufGrpc, |
| 30 | +}; |
| 31 | + |
| 32 | +class ThriftSender; |
| 33 | + |
| 34 | +/** |
| 35 | + * Struct to hold Jaeger exporter options. |
| 36 | + */ |
| 37 | +struct JaegerExporterOptions |
| 38 | +{ |
| 39 | + // The endpoint to export to. |
| 40 | + std::string server_addr = "localhost"; |
| 41 | + uint16_t server_port = 6831; |
| 42 | + TransportFormat transport_format = TransportFormat::kThriftUdpCompact; |
| 43 | +}; |
| 44 | + |
| 45 | +namespace trace_sdk = opentelemetry::sdk::trace; |
| 46 | +namespace sdk_common = opentelemetry::sdk::common; |
| 47 | + |
| 48 | +class JaegerExporter final : public trace_sdk::SpanExporter |
| 49 | +{ |
| 50 | +public: |
| 51 | + /** |
| 52 | + * Create a JaegerExporter using all default options. |
| 53 | + */ |
| 54 | + JaegerExporter(); |
| 55 | + |
| 56 | + /** |
| 57 | + * Create a JaegerExporter using the given options. |
| 58 | + */ |
| 59 | + explicit JaegerExporter(const JaegerExporterOptions &options); |
| 60 | + |
| 61 | + /** |
| 62 | + * Create a span recordable. |
| 63 | + * @return a new initialized Recordable object. |
| 64 | + */ |
| 65 | + std::unique_ptr<trace_sdk::Recordable> MakeRecordable() noexcept override; |
| 66 | + |
| 67 | + /** |
| 68 | + * Export a batch of spans. |
| 69 | + * @param spans a span of unique pointers to span recordables. |
| 70 | + */ |
| 71 | + sdk_common::ExportResult Export( |
| 72 | + const nostd::span<std::unique_ptr<trace_sdk::Recordable>> &spans) noexcept override; |
| 73 | + |
| 74 | + /** |
| 75 | + * Shutdown the exporter. |
| 76 | + * @param timeout an option timeout, default to max. |
| 77 | + */ |
| 78 | + bool Shutdown( |
| 79 | + std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override |
| 80 | + { |
| 81 | + return true; |
| 82 | + } |
| 83 | + |
| 84 | +private: |
| 85 | + void InitializeEndpoint(); |
| 86 | + |
| 87 | +private: |
| 88 | + // The configuration options associated with this exporter. |
| 89 | + bool is_shutdown_ = false; |
| 90 | + JaegerExporterOptions options_; |
| 91 | + std::unique_ptr<ThriftSender> sender_; |
| 92 | +}; |
| 93 | + |
| 94 | +} // namespace jaeger |
| 95 | +} // namespace exporter |
| 96 | +OPENTELEMETRY_END_NAMESPACE |
0 commit comments