1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
6 // We need include exporter.h first, which will include Windows.h with NOMINMAX on Windows
7 #include "opentelemetry/sdk/trace/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 OtlpHttpExporterOptions
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
= GetOtlpDefaultHttpEndpoint();
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
= GetOtlpDefaultTimeout();
51 // Additional HTTP headers
52 OtlpHeaders http_headers
= GetOtlpDefaultHeaders();
56 * The OTLP exporter exports span data in OpenTelemetry Protocol (OTLP) format.
58 class OtlpHttpExporter final
: public opentelemetry::sdk::trace::SpanExporter
62 * Create an OtlpHttpExporter using all default options.
67 * Create an OtlpHttpExporter using the given options.
69 explicit OtlpHttpExporter(const OtlpHttpExporterOptions
&options
);
72 * Create a span recordable.
73 * @return a newly initialized Recordable object
75 std::unique_ptr
<opentelemetry::sdk::trace::Recordable
> MakeRecordable() noexcept override
;
79 * @param spans a span of unique pointers to span recordables
81 opentelemetry::sdk::common::ExportResult
Export(
82 const nostd::span
<std::unique_ptr
<opentelemetry::sdk::trace::Recordable
>> &spans
) noexcept
86 * Shut down the exporter.
87 * @param timeout an optional timeout, the default timeout of 0 means that no
89 * @return return the status of this operation
91 bool Shutdown(std::chrono::microseconds timeout
= std::chrono::microseconds(0)) noexcept override
;
94 // The configuration options associated with this exporter.
95 const OtlpHttpExporterOptions options_
;
97 // Object that stores the HTTP sessions that have been created
98 std::unique_ptr
<OtlpHttpClient
> http_client_
;
100 friend class OtlpHttpExporterTestPeer
;
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
106 OtlpHttpExporter(std::unique_ptr
<OtlpHttpClient
> http_client
);
109 } // namespace exporter
110 OPENTELEMETRY_END_NAMESPACE