-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect tracer with external application's logging facilities (#150)
- Loading branch information
Showing
23 changed files
with
736 additions
and
407 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,62 @@ | ||
#include "logger.h" | ||
|
||
namespace datadog { | ||
namespace opentracing { | ||
|
||
namespace { | ||
|
||
std::string format_message(uint64_t trace_id, ot::string_view message) { | ||
return std::string("[trace_id: ") + std::to_string(trace_id) + std::string("] ") + | ||
std::string(message); | ||
} | ||
|
||
std::string format_message(uint64_t trace_id, uint64_t span_id, ot::string_view message) { | ||
return std::string("[trace_id: ") + std::to_string(trace_id) + std::string(", span_id: ") + | ||
std::to_string(span_id) + std::string("] ") + std::string(message); | ||
} | ||
|
||
} // namespace | ||
|
||
void StandardLogger::Log(LogLevel level, ot::string_view message) const noexcept { | ||
log_func_(level, ot::string_view{message}); | ||
} | ||
|
||
void StandardLogger::Log(LogLevel level, uint64_t trace_id, ot::string_view message) const | ||
noexcept { | ||
log_func_(level, ot::string_view{format_message(trace_id, message)}); | ||
} | ||
|
||
void StandardLogger::Log(LogLevel level, uint64_t trace_id, uint64_t span_id, | ||
ot::string_view message) const noexcept { | ||
log_func_(level, format_message(trace_id, span_id, message)); | ||
} | ||
|
||
void VerboseLogger::Log(LogLevel level, ot::string_view message) const noexcept { | ||
log_func_(level, message); | ||
} | ||
|
||
void VerboseLogger::Log(LogLevel level, uint64_t trace_id, ot::string_view message) const | ||
noexcept { | ||
log_func_(level, format_message(trace_id, message)); | ||
} | ||
|
||
void VerboseLogger::Log(LogLevel level, uint64_t trace_id, uint64_t span_id, | ||
ot::string_view message) const noexcept { | ||
log_func_(level, format_message(trace_id, span_id, message)); | ||
} | ||
|
||
void VerboseLogger::Trace(ot::string_view message) const noexcept { | ||
log_func_(LogLevel::debug, message); | ||
} | ||
|
||
void VerboseLogger::Trace(uint64_t trace_id, ot::string_view message) const noexcept { | ||
log_func_(LogLevel::debug, format_message(trace_id, message)); | ||
} | ||
|
||
void VerboseLogger::Trace(uint64_t trace_id, uint64_t span_id, ot::string_view message) const | ||
noexcept { | ||
log_func_(LogLevel::debug, format_message(trace_id, span_id, message)); | ||
} | ||
|
||
} // namespace opentracing | ||
} // namespace datadog |
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,55 @@ | ||
#ifndef DD_OPENTRACING_LOGGER_H | ||
#define DD_OPENTRACING_LOGGER_H | ||
|
||
#include "datadog/opentracing.h" | ||
|
||
namespace datadog { | ||
namespace opentracing { | ||
|
||
class Logger { | ||
public: | ||
virtual void Log(LogLevel level, ot::string_view message) const noexcept = 0; | ||
virtual void Log(LogLevel level, uint64_t trace_id, ot::string_view message) const noexcept = 0; | ||
virtual void Log(LogLevel level, uint64_t trace_id, uint64_t span_id, | ||
ot::string_view message) const noexcept = 0; | ||
virtual void Trace(ot::string_view message) const noexcept = 0; | ||
virtual void Trace(uint64_t trace_id, ot::string_view message) const noexcept = 0; | ||
virtual void Trace(uint64_t trace_id, uint64_t span_id, ot::string_view message) const | ||
noexcept = 0; | ||
|
||
protected: | ||
Logger(LogFunc log_func) : log_func_(log_func) {} | ||
virtual ~Logger() = default; | ||
LogFunc log_func_; | ||
}; | ||
|
||
// The standard logger provides stub implementations of Trace methods, that reduces the | ||
// performance hit when this level of detail is disabled. | ||
class StandardLogger final : public Logger { | ||
public: | ||
StandardLogger(LogFunc log_func) : Logger(log_func) {} | ||
void Log(LogLevel level, ot::string_view message) const noexcept override; | ||
void Log(LogLevel level, uint64_t trace_id, ot::string_view message) const noexcept override; | ||
void Log(LogLevel level, uint64_t trace_id, uint64_t span_id, ot::string_view message) const | ||
noexcept override; | ||
void Trace(ot::string_view) const noexcept override {} | ||
void Trace(uint64_t, ot::string_view) const noexcept override {} | ||
void Trace(uint64_t, uint64_t, ot::string_view) const noexcept override {} | ||
}; | ||
|
||
class VerboseLogger final : public Logger { | ||
public: | ||
VerboseLogger(LogFunc log_func) : Logger(log_func) {} | ||
void Log(LogLevel level, ot::string_view message) const noexcept override; | ||
void Log(LogLevel level, uint64_t trace_id, ot::string_view message) const noexcept override; | ||
void Log(LogLevel level, uint64_t trace_id, uint64_t span_id, ot::string_view message) const | ||
noexcept override; | ||
void Trace(ot::string_view message) const noexcept override; | ||
void Trace(uint64_t trace_id, ot::string_view message) const noexcept override; | ||
void Trace(uint64_t trace_id, uint64_t span_id, ot::string_view message) const noexcept override; | ||
}; | ||
|
||
} // namespace opentracing | ||
} // namespace datadog | ||
|
||
#endif // DD_OPENTRACING_LOGGER_H |
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
Oops, something went wrong.