File: async_instruments_test.cc

package info (click to toggle)
opentelemetry-cpp 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,744 kB
  • sloc: cpp: 79,029; sh: 1,640; makefile: 43; python: 31
file content (40 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <map>
#include <memory>
#include <string>
#include <utility>

#include "opentelemetry/metrics/observer_result.h"
#include "opentelemetry/sdk/metrics/async_instruments.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/sdk/metrics/state/metric_storage.h"
#include "opentelemetry/sdk/metrics/state/multi_metric_storage.h"
#include "opentelemetry/sdk/metrics/state/observable_registry.h"

using namespace opentelemetry;
using namespace opentelemetry::sdk::metrics;

using M = std::map<std::string, std::string>;

namespace
{
// NOLINTNEXTLINE
void asyc_generate_measurements(opentelemetry::metrics::ObserverResult /* observer */,
                                void * /* state */)
{}
}  // namespace

TEST(AsyncInstruments, ObservableInstrument)
{
  InstrumentDescriptor instrument_descriptor = {"long_counter", "description", "1",
                                                InstrumentType::kObservableCounter,
                                                InstrumentValueType::kLong};
  std::shared_ptr<ObservableRegistry> observable_registry(new ObservableRegistry());
  std::unique_ptr<AsyncWritableMetricStorage> metric_storage(new AsyncMultiMetricStorage());
  ObservableInstrument observable_counter_long(instrument_descriptor, std::move(metric_storage),
                                               observable_registry);
  observable_counter_long.AddCallback(asyc_generate_measurements, nullptr);
}