forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_metric_storage.cc
More file actions
48 lines (42 loc) · 1.91 KB
/
Copy pathsync_metric_storage.cc
File metadata and controls
48 lines (42 loc) · 1.91 KB
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
41
42
43
44
45
46
47
48
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#include <memory>
#include <mutex>
#include <utility>
#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h"
#include "opentelemetry/sdk/metrics/state/metric_collector.h"
#include "opentelemetry/sdk/metrics/state/sync_metric_storage.h"
#include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace metrics
{
bool SyncMetricStorage::Collect(CollectorHandle *collector,
nostd::span<std::shared_ptr<CollectorHandle>> collectors,
opentelemetry::common::SystemTimestamp sdk_start_ts,
opentelemetry::common::SystemTimestamp collection_ts,
nostd::function_ref<bool(MetricData)> callback) noexcept
{
// Add the current delta metrics to `unreported metrics stash` for all the collectors,
// this will also empty the delta metrics hashmap, and make it available for
// recordings
std::shared_ptr<AttributesHashMap> delta_metrics = nullptr;
{
std::lock_guard<opentelemetry::common::SpinLockMutex> guard(attribute_hashmap_lock_);
delta_metrics = std::move(attributes_hashmap_);
attributes_hashmap_.reset(new AttributesHashMap(aggregation_config_->cardinality_limit_));
}
return temporal_metric_storage_.buildMetrics(collector, collectors, sdk_start_ts, collection_ts,
delta_metrics, callback);
}
} // namespace metrics
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE