1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #ifdef ENABLE_LOGS_PREVIEW
7 # include "opentelemetry/sdk/logs/exporter.h"
9 # include "opentelemetry/exporters/otlp/otlp_http_client.h"
11 # include "opentelemetry/exporters/otlp/otlp_environment.h"
17 OPENTELEMETRY_BEGIN_NAMESPACE
24 * Struct to hold OTLP exporter options.
26 struct OtlpHttpLogExporterOptions
28 // The endpoint to export to. By default
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();
34 // By default, post json data
35 HttpRequestContentType content_type
= HttpRequestContentType::kJson
;
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
;
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;
45 // Whether to print the status of the exporter in the console
46 bool console_debug
= false;
48 // TODO: Enable/disable to verify SSL certificate
49 std::chrono::system_clock::duration timeout
= GetOtlpDefaultLogTimeout();
51 // Additional HTTP headers
52 OtlpHeaders http_headers
= GetOtlpDefaultLogHeaders();
56 * The OTLP exporter exports log data in OpenTelemetry Protocol (OTLP) format.
58 class OtlpHttpLogExporter final
: public opentelemetry::sdk::logs::LogExporter
62 * Create an OtlpHttpLogExporter with default exporter options.
64 OtlpHttpLogExporter();
67 * Create an OtlpHttpLogExporter with user specified options.
68 * @param options An object containing the user's configuration options.
70 OtlpHttpLogExporter(const OtlpHttpLogExporterOptions
&options
);
73 * Creates a recordable that stores the data in a JSON object
75 std::unique_ptr
<opentelemetry::sdk::logs::Recordable
> MakeRecordable() noexcept override
;
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.
82 opentelemetry::sdk::common::ExportResult
Export(
83 const nostd::span
<std::unique_ptr
<opentelemetry::sdk::logs::Recordable
>> &records
) noexcept
87 * Shutdown this exporter.
88 * @param timeout The maximum time to wait for the shutdown method to return
90 bool Shutdown(std::chrono::microseconds timeout
= std::chrono::microseconds(0)) noexcept override
;
93 // Configuration options for the exporter
94 const OtlpHttpLogExporterOptions options_
;
96 // Object that stores the HTTP sessions that have been created
97 std::unique_ptr
<OtlpHttpClient
> http_client_
;
99 friend class OtlpHttpLogExporterTestPeer
;
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
105 OtlpHttpLogExporter(std::unique_ptr
<OtlpHttpClient
> http_client
);
108 } // namespace exporter
109 OPENTELEMETRY_END_NAMESPACE