]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/sdk/src/logs/simple_log_processor.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / sdk / src / logs / simple_log_processor.cc
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #ifdef ENABLE_LOGS_PREVIEW
5 # include "opentelemetry/sdk/logs/simple_log_processor.h"
6
7 # include <chrono>
8 # include <vector>
9
10 OPENTELEMETRY_BEGIN_NAMESPACE
11 namespace sdk
12 {
13 namespace logs
14 {
15 /**
16 * Initialize a simple log processor.
17 * @param exporter the configured exporter where log records are sent
18 */
19 SimpleLogProcessor::SimpleLogProcessor(std::unique_ptr<LogExporter> &&exporter)
20 : exporter_(std::move(exporter))
21 {}
22
23 std::unique_ptr<Recordable> SimpleLogProcessor::MakeRecordable() noexcept
24 {
25 return exporter_->MakeRecordable();
26 }
27
28 /**
29 * Batches the log record it receives in a batch of 1 and immediately sends it
30 * to the configured exporter
31 */
32 void SimpleLogProcessor::OnReceive(std::unique_ptr<Recordable> &&record) noexcept
33 {
34 nostd::span<std::unique_ptr<Recordable>> batch(&record, 1);
35 // Get lock to ensure Export() is never called concurrently
36 const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
37
38 if (exporter_->Export(batch) != sdk::common::ExportResult::kSuccess)
39 {
40 /* Alert user of the failed export */
41 }
42 }
43 /**
44 * The simple processor does not have any log records to flush so this method is not used
45 */
46 bool SimpleLogProcessor::ForceFlush(std::chrono::microseconds timeout) noexcept
47 {
48 return true;
49 }
50
51 bool SimpleLogProcessor::Shutdown(std::chrono::microseconds timeout) noexcept
52 {
53 // Should only shutdown exporter ONCE.
54 if (!shutdown_latch_.test_and_set(std::memory_order_acquire) && exporter_ != nullptr)
55 {
56 return exporter_->Shutdown(timeout);
57 }
58
59 return true;
60 }
61 } // namespace logs
62 } // namespace sdk
63 OPENTELEMETRY_END_NAMESPACE
64 #endif