]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright The OpenTelemetry Authors |
2 | // SPDX-License-Identifier: Apache-2.0 | |
3 | ||
4 | #pragma once | |
5 | #ifndef ENABLE_METRICS_PREVIEW | |
6 | # include <memory> | |
7 | # include <mutex> | |
8 | # include <vector> | |
9 | # include "opentelemetry/metrics/meter.h" | |
10 | # include "opentelemetry/metrics/meter_provider.h" | |
11 | # include "opentelemetry/nostd/shared_ptr.h" | |
12 | # include "opentelemetry/sdk/metrics/meter.h" | |
13 | # include "opentelemetry/sdk/metrics/meter_context.h" | |
14 | # include "opentelemetry/sdk/resource/resource.h" | |
15 | # include "opentelemetry/version.h" | |
16 | ||
17 | OPENTELEMETRY_BEGIN_NAMESPACE | |
18 | namespace sdk | |
19 | { | |
20 | namespace metrics | |
21 | { | |
22 | ||
23 | // forward declaration | |
24 | class MetricCollector; | |
25 | class MetricReader; | |
26 | ||
27 | class MeterProvider final : public opentelemetry::metrics::MeterProvider | |
28 | { | |
29 | public: | |
30 | /** | |
31 | * Initialize a new meter provider | |
32 | * @param views The views for this meter provider | |
33 | * @param resource The resources for this meter provider. | |
34 | */ | |
35 | MeterProvider( | |
36 | std::unique_ptr<ViewRegistry> views = std::unique_ptr<ViewRegistry>(new ViewRegistry()), | |
37 | sdk::resource::Resource resource = sdk::resource::Resource::Create({})) noexcept; | |
38 | ||
39 | /** | |
40 | * Initialize a new meter provider with a specified context | |
41 | * @param context The shared meter configuration/pipeline for this provider. | |
42 | */ | |
43 | explicit MeterProvider(std::shared_ptr<sdk::metrics::MeterContext> context) noexcept; | |
44 | ||
45 | nostd::shared_ptr<opentelemetry::metrics::Meter> GetMeter( | |
46 | nostd::string_view name, | |
47 | nostd::string_view version = "", | |
48 | nostd::string_view schema_url = "") noexcept override; | |
49 | ||
50 | /** | |
51 | * Obtain the resource associated with this meter provider. | |
52 | * @return The resource for this meter provider. | |
53 | */ | |
54 | const sdk::resource::Resource &GetResource() const noexcept; | |
55 | ||
56 | /** | |
57 | * Attaches a metric reader to list of configured readers for this Meter providers. | |
58 | * @param reader The metric reader for this meter provider. This | |
59 | * must not be a nullptr. | |
60 | * | |
61 | * Note: This reader may not receive any in-flight meter data, but will get newly created meter | |
62 | * data. Note: This method is not thread safe, and should ideally be called from main thread. | |
63 | */ | |
64 | void AddMetricReader(std::unique_ptr<MetricReader> reader) noexcept; | |
65 | ||
66 | /** | |
67 | * Attaches a View to list of configured Views for this Meter provider. | |
68 | * @param view The Views for this meter provider. This | |
69 | * must not be a nullptr. | |
70 | * | |
71 | * Note: This view may not receive any in-flight meter data, but will get newly created meter | |
72 | * data. Note: This method is not thread safe, and should ideally be called from main thread. | |
73 | */ | |
74 | void AddView(std::unique_ptr<InstrumentSelector> instrument_selector, | |
75 | std::unique_ptr<MeterSelector> meter_selector, | |
76 | std::unique_ptr<View> view) noexcept; | |
77 | ||
78 | /** | |
79 | * Shutdown the meter provider. | |
80 | */ | |
81 | bool Shutdown() noexcept; | |
82 | ||
83 | /** | |
84 | * Force flush the meter provider. | |
85 | */ | |
86 | bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; | |
87 | ||
88 | private: | |
89 | std::shared_ptr<sdk::metrics::MeterContext> context_; | |
90 | std::mutex lock_; | |
91 | }; | |
92 | } // namespace metrics | |
93 | } // namespace sdk | |
94 | OPENTELEMETRY_END_NAMESPACE | |
95 | #endif |