]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_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_log_exporter.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5 #ifdef ENABLE_LOGS_PREVIEW
6
7 # include "opentelemetry/sdk/logs/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 OtlpHttpLogExporterOptions
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 = GetOtlpDefaultHttpLogEndpoint();
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 = GetOtlpDefaultLogTimeout();
50
51 // Additional HTTP headers
52 OtlpHeaders http_headers = GetOtlpDefaultLogHeaders();
53 };
54
55 /**
56 * The OTLP exporter exports log data in OpenTelemetry Protocol (OTLP) format.
57 */
58 class OtlpHttpLogExporter final : public opentelemetry::sdk::logs::LogExporter
59 {
60 public:
61 /**
62 * Create an OtlpHttpLogExporter with default exporter options.
63 */
64 OtlpHttpLogExporter();
65
66 /**
67 * Create an OtlpHttpLogExporter with user specified options.
68 * @param options An object containing the user's configuration options.
69 */
70 OtlpHttpLogExporter(const OtlpHttpLogExporterOptions &options);
71
72 /**
73 * Creates a recordable that stores the data in a JSON object
74 */
75 std::unique_ptr<opentelemetry::sdk::logs::Recordable> MakeRecordable() noexcept override;
76
77 /**
78 * Exports a vector of log records to the Elasticsearch instance. Guaranteed to return after a
79 * timeout specified from the options passed from the constructor.
80 * @param records A list of log records to send to Elasticsearch.
81 */
82 opentelemetry::sdk::common::ExportResult Export(
83 const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &records) noexcept
84 override;
85
86 /**
87 * Shutdown this exporter.
88 * @param timeout The maximum time to wait for the shutdown method to return
89 */
90 bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override;
91
92 private:
93 // Configuration options for the exporter
94 const OtlpHttpLogExporterOptions options_;
95
96 // Object that stores the HTTP sessions that have been created
97 std::unique_ptr<OtlpHttpClient> http_client_;
98 // For testing
99 friend class OtlpHttpLogExporterTestPeer;
100 /**
101 * Create an OtlpHttpLogExporter using the specified http client.
102 * Only tests can call this constructor directly.
103 * @param http_client the http client to be used for exporting
104 */
105 OtlpHttpLogExporter(std::unique_ptr<OtlpHttpClient> http_client);
106 };
107 } // namespace otlp
108 } // namespace exporter
109 OPENTELEMETRY_END_NAMESPACE
110 #endif