-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Links and Events to OStreamSpanExporter (#663)
* Add Links and Events to OStreamSpanExporter Previously these were just ignored. Summary of changes: - Moved print methods into the translation unit - Added new print methods for links and events - Refactored tests - Added new convenience OStream capture utility - Restructured tests to focus on stream tests and feature tests - Added new tests for links and events * Add new test utility to bazel build
- Loading branch information
Showing
5 changed files
with
358 additions
and
163 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
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,57 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace ostream | ||
{ | ||
namespace test | ||
{ | ||
/** | ||
* The OStreamCapture captures from the specified stream for its lifetime | ||
*/ | ||
class OStreamCapture | ||
{ | ||
public: | ||
/** | ||
* Create a OStreamCapture which will capture the output of the ostream that it was constructed | ||
* with for the lifetime of the instance. | ||
*/ | ||
OStreamCapture(std::ostream &ostream) : stream_(ostream), buf_(ostream.rdbuf()) | ||
{ | ||
stream_.rdbuf(captured_.rdbuf()); | ||
} | ||
|
||
~OStreamCapture() { stream_.rdbuf(buf_); } | ||
|
||
/** | ||
* Returns the captured data from the stream. | ||
*/ | ||
std::string GetCaptured() const { return captured_.str(); } | ||
|
||
private: | ||
std::ostream &stream_; | ||
std::streambuf *buf_; | ||
std::stringstream captured_; | ||
}; | ||
|
||
/** | ||
* Helper method to invoke the passed func while recording the output of the specified stream and | ||
* return the output afterwards. | ||
*/ | ||
template <typename Func> | ||
std::string WithOStreamCapture(std::ostream &stream, Func func) | ||
{ | ||
OStreamCapture capture(stream); | ||
func(); | ||
return capture.GetCaptured(); | ||
} | ||
|
||
} // namespace test | ||
} // namespace ostream | ||
} // namespace exporter | ||
OPENTELEMETRY_END_NAMESPACE |
Oops, something went wrong.