]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / exporters / ostream / include / opentelemetry / exporters / ostream / metric_exporter.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5 #ifndef ENABLE_METRICS_PREVIEW
6
7 # include <iostream>
8 # include <string>
9 # include "opentelemetry/common/spin_lock_mutex.h"
10 # include "opentelemetry/sdk/metrics/data/metric_data.h"
11 # include "opentelemetry/sdk/metrics/instruments.h"
12 # include "opentelemetry/sdk/metrics/metric_exporter.h"
13 # include "opentelemetry/version.h"
14
15 OPENTELEMETRY_BEGIN_NAMESPACE
16 namespace exporter
17 {
18 namespace metrics
19 {
20
21 /**
22 * The OStreamMetricExporter exports record data through an ostream
23 */
24 class OStreamMetricExporter final : public opentelemetry::sdk::metrics::MetricExporter
25 {
26 public:
27 /**
28 * Create an OStreamMetricExporter. This constructor takes in a reference to an ostream that the
29 * export() function will send metrics data into.
30 * The default ostream is set to stdout
31 */
32 explicit OStreamMetricExporter(std::ostream &sout = std::cout) noexcept;
33
34 /**
35 * Export
36 * @param data metrics data
37 */
38 sdk::common::ExportResult Export(const sdk::metrics::ResourceMetrics &data) noexcept override;
39
40 /**
41 * Force flush the exporter.
42 */
43 bool ForceFlush(
44 std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override;
45
46 /**
47 * Shut down the exporter.
48 * @param timeout an optional timeout, the default timeout of 0 means that no
49 * timeout is applied.
50 * @return return the status of this operation
51 */
52 bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override;
53
54 private:
55 std::ostream &sout_;
56 bool is_shutdown_ = false;
57 mutable opentelemetry::common::SpinLockMutex lock_;
58 bool isShutdown() const noexcept;
59 void printInstrumentationInfoMetricData(
60 const sdk::metrics::InstrumentationInfoMetrics &info_metrics);
61 void printPointData(const opentelemetry::sdk::metrics::PointType &point_data);
62 void printPointAttributes(const opentelemetry::sdk::metrics::PointAttributes &point_attributes);
63 };
64 } // namespace metrics
65 } // namespace exporter
66 OPENTELEMETRY_END_NAMESPACE
67 #endif