]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / exporters / otlp / include / opentelemetry / exporters / otlp / otlp_http_exporter.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5
6 // We need include exporter.h first, which will include Windows.h with NOMINMAX on Windows
7 #include "opentelemetry/sdk/trace/exporter.h"
8
9 #include "opentelemetry/exporters/otlp/otlp_http_client.h"
10
11 #include "opentelemetry/exporters/otlp/otlp_environment.h"
12
13 #include <chrono>
14 #include <memory>
15 #include <string>
16
17 OPENTELEMETRY_BEGIN_NAMESPACE
18 namespace exporter
19 {
20 namespace otlp
21 {
22
23 /**
24 * Struct to hold OTLP exporter options.
25 */
26 struct OtlpHttpExporterOptions
27 {
28 // The endpoint to export to. By default
29 // @see
30 // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md
31 // @see https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver/otlpreceiver
32 std::string url = GetOtlpDefaultHttpEndpoint();
33
34 // By default, post json data
35 HttpRequestContentType content_type = HttpRequestContentType::kJson;
36
37 // If convert bytes into hex. By default, we will convert all bytes but id into base64
38 // This option is ignored if content_type is not kJson
39 JsonBytesMappingKind json_bytes_mapping = JsonBytesMappingKind::kHexId;
40
41 // If using the json name of protobuf field to set the key of json. By default, we will use the
42 // field name just like proto files.
43 bool use_json_name = false;
44
45 // Whether to print the status of the exporter in the console
46 bool console_debug = false;
47
48 // TODO: Enable/disable to verify SSL certificate
49 std::chrono::system_clock::duration timeout = GetOtlpDefaultTimeout();
50
51 // Additional HTTP headers
52 OtlpHeaders http_headers = GetOtlpDefaultHeaders();
53 };
54
55 /**
56 * The OTLP exporter exports span data in OpenTelemetry Protocol (OTLP) format.
57 */
58 class OtlpHttpExporter final : public opentelemetry::sdk::trace::SpanExporter
59 {
60 public:
61 /**
62 * Create an OtlpHttpExporter using all default options.
63 */
64 OtlpHttpExporter();
65
66 /**
67 * Create an OtlpHttpExporter using the given options.
68 */
69 explicit OtlpHttpExporter(const OtlpHttpExporterOptions &options);
70
71 /**
72 * Create a span recordable.
73 * @return a newly initialized Recordable object
74 */
75 std::unique_ptr<opentelemetry::sdk::trace::Recordable> MakeRecordable() noexcept override;
76
77 /**
78 * Export
79 * @param spans a span of unique pointers to span recordables
80 */
81 opentelemetry::sdk::common::ExportResult Export(
82 const nostd::span<std::unique_ptr<opentelemetry::sdk::trace::Recordable>> &spans) noexcept
83 override;
84
85 /**
86 * Shut down the exporter.
87 * @param timeout an optional timeout, the default timeout of 0 means that no
88 * timeout is applied.
89 * @return return the status of this operation
90 */
91 bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override;
92
93 private:
94 // The configuration options associated with this exporter.
95 const OtlpHttpExporterOptions options_;
96
97 // Object that stores the HTTP sessions that have been created
98 std::unique_ptr<OtlpHttpClient> http_client_;
99 // For testing
100 friend class OtlpHttpExporterTestPeer;
101 /**
102 * Create an OtlpHttpExporter using the specified http client.
103 * Only tests can call this constructor directly.
104 * @param http_client the http client to be used for exporting
105 */
106 OtlpHttpExporter(std::unique_ptr<OtlpHttpClient> http_client);
107 };
108 } // namespace otlp
109 } // namespace exporter
110 OPENTELEMETRY_END_NAMESPACE