1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #ifndef ENABLE_METRICS_PREVIEW
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"
15 OPENTELEMETRY_BEGIN_NAMESPACE
22 * The OStreamMetricExporter exports record data through an ostream
24 class OStreamMetricExporter final
: public opentelemetry::sdk::metrics::MetricExporter
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
32 explicit OStreamMetricExporter(std::ostream
&sout
= std::cout
) noexcept
;
36 * @param data metrics data
38 sdk::common::ExportResult
Export(const sdk::metrics::ResourceMetrics
&data
) noexcept override
;
41 * Force flush the exporter.
44 std::chrono::microseconds timeout
= (std::chrono::microseconds::max
)()) noexcept override
;
47 * Shut down the exporter.
48 * @param timeout an optional timeout, the default timeout of 0 means that no
50 * @return return the status of this operation
52 bool Shutdown(std::chrono::microseconds timeout
= std::chrono::microseconds(0)) noexcept override
;
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
);
64 } // namespace metrics
65 } // namespace exporter
66 OPENTELEMETRY_END_NAMESPACE