-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Zpages webserver hosting from Exporter (#626)
- Loading branch information
Showing
10 changed files
with
201 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include <chrono> | ||
#include <memory> | ||
#include <mutex> | ||
#include <unordered_set> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "opentelemetry/ext/zpages/threadsafe_span_data.h" | ||
#include "opentelemetry/sdk/trace/processor.h" | ||
#include "opentelemetry/sdk/trace/recordable.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace ext | ||
{ | ||
namespace zpages | ||
{ | ||
/* | ||
* The span processor passes and stores running and completed recordables (casted as span_data) | ||
* to be used by the TraceZ Data Aggregator. | ||
*/ | ||
class TracezSharedData | ||
{ | ||
public: | ||
struct CollectedSpans | ||
{ | ||
std::unordered_set<ThreadsafeSpanData *> running; | ||
std::vector<std::unique_ptr<ThreadsafeSpanData>> completed; | ||
}; | ||
|
||
/* | ||
* Initialize a shared data storage. | ||
*/ | ||
explicit TracezSharedData() noexcept {} | ||
|
||
/* | ||
* Called when a span has been started. | ||
*/ | ||
void OnStart(ThreadsafeSpanData *span) noexcept; | ||
|
||
/* | ||
* Called when a span has ended. | ||
*/ | ||
void OnEnd(std::unique_ptr<ThreadsafeSpanData> &&span) noexcept; | ||
|
||
/* | ||
* Returns a snapshot of all spans stored. This snapshot has a copy of the | ||
* stored running_spans and gives ownership of completed spans to the caller. | ||
* Stored completed_spans are cleared from the processor. Currently, | ||
* copy-on-write is utilized where possible to minimize contention, but locks | ||
* may be added in the future. | ||
* @return snapshot of all currently running spans and newly completed spans | ||
* (spans never sent while complete) at the time that the function is called | ||
*/ | ||
CollectedSpans GetSpanSnapshot() noexcept; | ||
|
||
private: | ||
mutable std::mutex mtx_; | ||
CollectedSpans spans_; | ||
}; | ||
} // namespace zpages | ||
} // namespace ext | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "opentelemetry/ext/zpages/tracez_shared_data.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace ext | ||
{ | ||
namespace zpages | ||
{ | ||
|
||
void TracezSharedData::OnStart(ThreadsafeSpanData *span) noexcept | ||
{ | ||
std::lock_guard<std::mutex> lock(mtx_); | ||
spans_.running.insert(span); | ||
} | ||
|
||
void TracezSharedData::OnEnd(std::unique_ptr<ThreadsafeSpanData> &&span) noexcept | ||
{ | ||
std::lock_guard<std::mutex> lock(mtx_); | ||
auto span_it = spans_.running.find(span.get()); | ||
if (span_it != spans_.running.end()) | ||
{ | ||
spans_.running.erase(span_it); | ||
spans_.completed.push_back(std::unique_ptr<ThreadsafeSpanData>(span.release())); | ||
} | ||
} | ||
|
||
TracezSharedData::CollectedSpans TracezSharedData::GetSpanSnapshot() noexcept | ||
{ | ||
CollectedSpans snapshot; | ||
std::lock_guard<std::mutex> lock(mtx_); | ||
snapshot.running = spans_.running; | ||
snapshot.completed = std::move(spans_.completed); | ||
spans_.completed.clear(); | ||
return snapshot; | ||
} | ||
|
||
} // namespace zpages | ||
} // namespace ext | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.