1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
4 #include "opentelemetry/exporters/otlp/otlp_http_exporter.h"
5 #include "opentelemetry/exporters/otlp/otlp_recordable.h"
6 #include "opentelemetry/exporters/otlp/otlp_recordable_utils.h"
8 #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"
10 #include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h"
12 #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
14 namespace nostd
= opentelemetry::nostd
;
16 OPENTELEMETRY_BEGIN_NAMESPACE
22 OtlpHttpExporter::OtlpHttpExporter() : OtlpHttpExporter(OtlpHttpExporterOptions()) {}
24 OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions
&options
)
26 http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options
.url
,
28 options
.json_bytes_mapping
,
29 options
.use_json_name
,
30 options
.console_debug
,
32 options
.http_headers
)))
35 OtlpHttpExporter::OtlpHttpExporter(std::unique_ptr
<OtlpHttpClient
> http_client
)
36 : options_(OtlpHttpExporterOptions()), http_client_(std::move(http_client
))
38 // ----------------------------- Exporter methods ------------------------------
40 std::unique_ptr
<opentelemetry::sdk::trace::Recordable
> OtlpHttpExporter::MakeRecordable() noexcept
42 return std::unique_ptr
<opentelemetry::sdk::trace::Recordable
>(
43 new exporter::otlp::OtlpRecordable());
46 opentelemetry::sdk::common::ExportResult
OtlpHttpExporter::Export(
47 const nostd::span
<std::unique_ptr
<opentelemetry::sdk::trace::Recordable
>> &spans
) noexcept
51 return opentelemetry::sdk::common::ExportResult::kSuccess
;
54 proto::collector::trace::v1::ExportTraceServiceRequest service_request
;
55 OtlpRecordableUtils::PopulateRequest(spans
, &service_request
);
56 return http_client_
->Export(service_request
);
59 bool OtlpHttpExporter::Shutdown(std::chrono::microseconds timeout
) noexcept
61 return http_client_
->Shutdown(timeout
);
65 } // namespace exporter
66 OPENTELEMETRY_END_NAMESPACE