Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
27adfde
Clean add of tracez processor files
jajanet Jul 8, 2020
8f3d1bc
Change cmake files
jajanet Jul 8, 2020
f106309
adjust cmake files
jajanet Jul 8, 2020
75cb6ee
Fix CMake and test style
jajanet Jul 9, 2020
d5d8ed5
Add tests, better test names/docstrings
jajanet Jul 9, 2020
f8df6bb
Cast recordable to span_data, fix test formatting
jajanet Jul 10, 2020
8508a00
Add touchups to tests and formatting
jajanet Jul 10, 2020
f1f54f0
Change asserts into expects
jajanet Jul 10, 2020
2b1a5b7
Fix OnEnd mem leak, reset flush/shutdown functions
jajanet Jul 13, 2020
bc0aaea
Add TODOs for thread safety concerns, update README
jajanet Jul 13, 2020
af3b3a7
Make processor more thread-safe with tests
jajanet Jul 13, 2020
7085288
Add missed TODO comment
jajanet Jul 13, 2020
80f04c5
Merge branch 'zpages-tracez-spanprocessor-threading' into zpages-trac…
jajanet Jul 13, 2020
09037be
Fix test thread safety, add test fixtures
jajanet Jul 14, 2020
69a30c9
Adjust import order, spacing
jajanet Jul 14, 2020
466ac2e
Add noop tests for ForceFlush/Shutdown
jajanet Jul 14, 2020
d9ba5b3
Move includes, remove README update date
jajanet Jul 14, 2020
0dc7aa6
Order includes alphabetically
jajanet Jul 14, 2020
4c23ec5
Merge remote-tracking branch 'open-telemetry/master' into zpages-trac…
jajanet Jul 15, 2020
dde9a4f
Increase span creation numbers
jajanet Jul 15, 2020
649367e
Decrease spans created in thread safety tests
jajanet Jul 16, 2020
7d5182f
Merge remote-tracking branch 'open-telemetry/master' into zpages-trac…
jajanet Jul 16, 2020
b7e83b7
Merge branch 'zpages-tracez-spanprocessor' of https://github.com/kman…
jajanet Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ add_subdirectory(sdk)
include_directories(.)
add_subdirectory(exporters)
add_subdirectory(examples)
add_subdirectory(ext)
7 changes: 7 additions & 0 deletions ext/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "headers",
hdrs = glob(["include/**/*.h"]),
strip_include_prefix = "include",
)
5 changes: 5 additions & 0 deletions ext/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_subdirectory(src)

if(BUILD_TESTING)
add_subdirectory(test)
endif()
93 changes: 93 additions & 0 deletions ext/include/opentelemetry/ext/zpages/tracez_processor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#pragma once

#include <chrono>
#include <memory>
#include <mutex>
#include <unordered_set>
#include <vector>
#include <utility>

#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/sdk/trace/span_data.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 TracezSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor {
public:

struct CollectedSpans {
std::unordered_set<opentelemetry::sdk::trace::SpanData*> running;
std::vector<std::unique_ptr<opentelemetry::sdk::trace::SpanData>> completed;
};

/*
* Initialize a span processor.
*/
explicit TracezSpanProcessor() noexcept {}

/*
* Create a span recordable, which is span_data
* @return a newly initialized recordable
*/
std::unique_ptr<opentelemetry::sdk::trace::Recordable> MakeRecordable() noexcept override
{
return std::unique_ptr<opentelemetry::sdk::trace::Recordable>(new opentelemetry::sdk::trace::SpanData);
}

/*
* OnStart is called when a span starts; the recordable is cast to span_data and added to running_spans.
* @param span a recordable for a span that was just started
*/
void OnStart(opentelemetry::sdk::trace::Recordable &span) noexcept override;

/*
* OnEnd is called when a span ends; that span_data is moved from running_spans to
* completed_spans
* @param span a recordable for a span that was ended
*/
void OnEnd(std::unique_ptr<opentelemetry::sdk::trace::Recordable> &&span) noexcept override;

/*
* 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;

/*
* For now, does nothing. In the future, it
* may send all ended spans that have not yet been sent to the aggregator.
* @param timeout an optional timeout, the default timeout of 0 means that no
* timeout is applied. Currently, timeout does nothing.
*/
void ForceFlush(
std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override {}

/*
* Shut down the processor and do any cleanup required, which is none.
* After the call to Shutdown, subsequent calls to OnStart, OnEnd, ForceFlush
* or Shutdown will return immediately without doing anything.
* @param timeout an optional timeout, the default timeout of 0 means that no
* timeout is applied. Currently, timeout does nothing.
*/
void Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override {}

private:
mutable std::mutex mtx_;
CollectedSpans spans_;
};
} // namespace zpages
} // namespace ext
OPENTELEMETRY_END_NAMESPACE
1 change: 1 addition & 0 deletions ext/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(zpages)
27 changes: 27 additions & 0 deletions ext/src/zpages/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2020, OpenTelemetry 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.

package(default_visibility = ["//visibility:public"])

cc_library(
name = "zpages",
srcs = glob(["**/*.cc"]),
hdrs = glob(["**/*.h"]),
include_prefix = "ext/zpages",
deps = [
"//api",
"//sdk:headers",
"//ext:headers",
],
)
8 changes: 8 additions & 0 deletions ext/src/zpages/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_library(opentelemetry_zpages
tracez_processor.cc
../../include/opentelemetry/ext/zpages/tracez_processor.h)

target_include_directories(opentelemetry_zpages PUBLIC ../../include)

target_link_libraries(opentelemetry_zpages opentelemetry_api opentelemetry_trace)

Comment thread
jajanet marked this conversation as resolved.
21 changes: 10 additions & 11 deletions ext/src/zpages/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
# zPages
> Last updated 6/26/20

# Table of Contents
## Table of Contents
- [Summary](#summary)
- [TraceZ](#tracez)
- [RPCz](#rpcz)
- [Usage](#usage)
- [Links of Interest](#links-of-interest)

## Summary
zPages allow easy viewing of tracing information. When included for a process, zPages will display basic information about that process on a webpage. There are currently two types of zPages: TraceZ and RPCz.
zPages allow easy viewing of tracing information. When included for a process, zPages will display basic information about that process on a webpage. Two types of zPages include TraceZ and RPCz.

Including a zPage within a page is useful for developers because it's quicker to get running than adding extra code and installing external exporters like Jaeger and Zipkin. zPages tend to be more lightweight than these external exporters, but are also helpful for debugging latency issues and deadlocks.
Including a zPage within a page is useful for developers because it's quicker to get running than adding extra code and installing external exporters like Jaeger and Zipkin. zPages tend to be more lightweight than these external exporters, but are also helpful for debugging latency issues (slow parts of applications) and deadlocks (running spans that don't end).

The idea of "zPages" originates from one of OpenTelemetry's predecessors, [OpenCensus](https://opencensus.io/). You can read more about it [here](https://opencensus.io/zpages). OpenCensus has different zPage implementations in [Java](https://opencensus.io/zpages/java/), [Go](https://opencensus.io/zpages/go/), and [Node](https://opencensus.io/zpages/node/) and there has been similar internal solutions developed at companies like Uber, but *this is the first major open-source implementation of zPages in C++*. Within OpenTelemetry, zPages are also being developed in [Java](https://github.com/open-telemetry/opentelemetry-java).

#### How It Works
On a high level, zPages work by reading a process' spans using a SpanProcessor, which exports spans to the appropriate DataAggregator that a HttpServer uses.
On a high level, an application creates spans using a Tracer Provider/Tracer who passes them to a Span Processor, which exports spans to the appropriate Data Aggregator that a Http Server displays information for.

> TODO: Add picture examples for span overview and individual span view

### TraceZ
TraceZ is a type of zPage that shows information on tracing spans, and allows users to look closer at specific and individual spans. Details a user would view include span id, name, status, and timestamps. The individual components of TraceZ are as follows:

- TracezSpanProcessor (TSP)
- Contact point for TraceZ to connect with a process, which collects tracing information and provides an interface for TDA.
- A tracer/tracer provider (which the user chooses) creates spans, which connects to TSP so that TraceZ to detect spans. The TSP then stores tracing information in running and completed containers and provides an interface for TDA to access their information.
- TracezDataAggregator (TDA)
- Intermediary between the TSP and THS, which also performs various functions and calculations to send the correct tracing information to the THS.
- Intermediary between the TSP and THS, which also performs various functions and calculations (mainly grouping spans by their names and latency times) to send the correct tracing information to the THS.
- TracezHttpServer (THS)
- User-facing web page generator, which creates HTML pages using TDA that display 1) overall information on all of the process's spans and 2) more detailed information on specific spans when clicked.
- User-facing web page generator, which creates HTML pages using TDA that display 1) overall information and trends on all of the process's spans and 2) more detailed information on specific spans when clicked.

### RPCz
RPCz is a type of zPage that provides details on instrumented sent and received RPC messages. Although there is currently no ongoing development of RPCz for OpenTelemetry, OpenCensus zPages have implementations of RPCz (linked above).
Expand All @@ -41,6 +40,6 @@ RPCz is a type of zPage that provides details on instrumented sent and received
- [TracezSpanProcessor Design Doc](https://docs.google.com/document/d/1kO4iZARYyr-EGBlY2VNM3ELU3iw6ZrC58Omup_YT-fU/edit#) (pending review)
- [TracezDataAggregator Design Doc](https://docs.google.com/document/d/1ziKFgvhXFfRXZjOlAHQRR-TzcNcTXzg1p2I9oPCEIoU/edit?ts=5ef0d177#heading=h.5irk4csrpu0y) (pending review)
- [TracezHttpServer Design Doc](https://docs.google.com/document/d/1U1V8QZ5LtGl4Mich-aJ6KZGLHrMIE8pWyspmzvnIefI/edit#) (draft)
- [Contribution Guidelines](https://github.com/open-telemetry/opentelemetry-cpp/blob/master/CONTRIBUTING.md)


- [zPages General Direction Spec](https://github.com/open-telemetry/oteps/blob/master/text/0110-z-pages.md)
- [Prospective Fields Displayed by
TraceZ](https://github.com/open-telemetry/opentelemetry-cpp/blob/master/sdk/include/opentelemetry/sdk/trace/span_data.h)
38 changes: 38 additions & 0 deletions ext/src/zpages/tracez_processor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "opentelemetry/ext/zpages/tracez_processor.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace ext {
namespace zpages {

void TracezSpanProcessor::OnStart(opentelemetry::sdk::trace::Recordable &span) noexcept {
std::lock_guard<std::mutex> lock(mtx_);
Comment thread
jajanet marked this conversation as resolved.
spans_.running.insert(static_cast<opentelemetry::sdk::trace::SpanData*>(&span));
Comment thread
jajanet marked this conversation as resolved.
}

void TracezSpanProcessor::OnEnd(std::unique_ptr<opentelemetry::sdk::trace::Recordable> &&span) noexcept {
if (span == nullptr) return;
auto span_raw = static_cast<opentelemetry::sdk::trace::SpanData*>(span.get());
std::lock_guard<std::mutex> lock(mtx_);
auto span_it = spans_.running.find(span_raw);
if (span_it != spans_.running.end()) {
spans_.running.erase(span_it);
spans_.completed.push_back(
std::unique_ptr<opentelemetry::sdk::trace::SpanData>(
static_cast<opentelemetry::sdk::trace::SpanData*>(span.release())));
}
}


TracezSpanProcessor::CollectedSpans TracezSpanProcessor::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
1 change: 1 addition & 0 deletions ext/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(zpages)
11 changes: 11 additions & 0 deletions ext/test/zpages/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cc_test(
name = "tracez_processor_tests",
srcs = [
"tracez_processor_test.cc",
],
deps = [
"//sdk/src/trace",
"//ext/src/zpages",
"@com_google_googletest//:gtest_main",
],
)
13 changes: 13 additions & 0 deletions ext/test/zpages/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
foreach(testname
tracez_processor_test)
add_executable(${testname} "${testname}.cc")
target_link_libraries(
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_zpages)

gtest_add_tests(
TARGET ${testname}
TEST_PREFIX ext.
TEST_LIST ${testname})
endforeach()

Loading