This repository was archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathrunning_span_store_impl.h
More file actions
82 lines (64 loc) · 2.64 KB
/
running_span_store_impl.h
File metadata and controls
82 lines (64 loc) · 2.64 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2017, OpenCensus Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef OPENCENSUS_TRACE_INTERNAL_RUNNING_SPAN_STORE_IMPL_H_
#define OPENCENSUS_TRACE_INTERNAL_RUNNING_SPAN_STORE_IMPL_H_
#include <cstdint>
#include <memory>
#include <unordered_map>
#include <vector>
#include "absl/base/thread_annotations.h"
#include "absl/synchronization/mutex.h"
#include "opencensus/trace/internal/running_span_store.h"
#include "opencensus/trace/internal/span_impl.h"
namespace opencensus {
namespace trace {
namespace exporter {
// RunningSpanStoreImpl implements the store for the RunningSpanStore API.
//
// This class is thread-safe and a singleton.
class RunningSpanStoreImpl {
public:
// Returns the global instance of RunningSpanStoreImpl.
static RunningSpanStoreImpl* Get();
// Adds a new running Span.
void AddSpan(const SpanId& id, const std::shared_ptr<SpanImpl>& span)
LOCKS_EXCLUDED(mu_);
// Finds a Span with id SpanId, returns false if not found.
bool FindSpan(const SpanId& id, std::shared_ptr<SpanImpl>* span)
LOCKS_EXCLUDED(mu_);
// Removes a Span that's no longer running. Returns true on success, false if
// that Span was not being tracked.
bool RemoveSpan(const SpanId& id) LOCKS_EXCLUDED(mu_);
// Returns a summary of the data available in the RunningSpanStore.
RunningSpanStore::Summary GetSummary() const LOCKS_EXCLUDED(mu_);
// Returns the running spans that match the filter.
std::vector<SpanData> GetRunningSpans(
const RunningSpanStore::Filter& filter) const LOCKS_EXCLUDED(mu_);
private:
friend class RunningSpanStoreImplTestPeer;
RunningSpanStoreImpl() {}
// Clears all currently active spans from the store.
void ClearForTesting() LOCKS_EXCLUDED(mu_);
mutable absl::Mutex mu_;
// Necessary for using SpanId as the key in the map.
struct SpanIdHash {
std::size_t operator()(SpanId const& s) const noexcept { return s.hash(); }
};
std::unordered_map<SpanId, std::shared_ptr<SpanImpl>, SpanIdHash> spans_
GUARDED_BY(mu_);
};
} // namespace exporter
} // namespace trace
} // namespace opencensus
#endif // OPENCENSUS_TRACE_INTERNAL_RUNNING_SPAN_STORE_IMPL_H_