-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ETW Log Exporter #1006
Merged
Merged
ETW Log Exporter #1006
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4f780b4
ETW exporter for logs
lalitb a7a1b95
ETW Log exporter
lalitb 71d7c7e
Merge branch 'main' into etw-logger
lalitb fab17e8
add more tests
lalitb c4e5341
move common functionality in etw_config.h
lalitb 44a1160
format
lalitb a1f2479
Update exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h
lalitb 25a67c8
Update exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h
lalitb d3db333
Update exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h
lalitb 6a6c68e
Update exporters/etw/include/opentelemetry/exporters/etw/etw_fields.h
lalitb 96daa8b
Merge branch 'main' into etw-logger
lalitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
186 changes: 186 additions & 0 deletions
186
exporters/etw/include/opentelemetry/exporters/etw/etw_config.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#include <map> | ||
|
||
#include "opentelemetry/nostd/shared_ptr.h" | ||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/nostd/unique_ptr.h" | ||
#include "opentelemetry/nostd/variant.h" | ||
#include "opentelemetry/trace/span_id.h" | ||
|
||
#include "opentelemetry/exporters/etw/etw_provider.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace exporter | ||
{ | ||
namespace etw | ||
{ | ||
/** | ||
* @brief TelemetryProvider Options passed via SDK API. | ||
*/ | ||
using TelemetryProviderOptions = | ||
std::map<std::string, nostd::variant<std::string, uint64_t, float, bool>>; | ||
|
||
/** | ||
* @brief TelemetryProvider runtime configuration class. Internal representation | ||
* of TelemetryProviderOptions used by various components of SDK. | ||
*/ | ||
typedef struct | ||
{ | ||
bool enableTraceId; // Set `TraceId` on ETW events | ||
bool enableSpanId; // Set `SpanId` on ETW events | ||
bool enableActivityId; // Assign `SpanId` to `ActivityId` | ||
bool enableActivityTracking; // Emit TraceLogging events for Span/Start and Span/Stop Not used | ||
// for Logs | ||
bool enableRelatedActivityId; // Assign parent `SpanId` to `RelatedActivityId` | ||
bool enableAutoParent; // Start new spans as children of current active span, Not used for Logs | ||
ETWProvider::EventFormat | ||
encoding; // Event encoding to use for this provider (TLD, MsgPack, XML, etc.). | ||
} TelemetryProviderConfiguration; | ||
|
||
/** | ||
* @brief Helper template to convert a variant value from TelemetryProviderOptions to | ||
* LoggerProviderConfiguration | ||
* | ||
* @param options TelemetryProviderOptions passed on API surface | ||
* @param key Option name | ||
* @param value Reference to destination value | ||
* @param defaultValue Default value if option is not supplied | ||
*/ | ||
template <typename T> | ||
static inline void GetOption(const TelemetryProviderOptions &options, | ||
const char *key, | ||
T &value, | ||
T defaultValue) | ||
{ | ||
auto it = options.find(key); | ||
if (it != options.end()) | ||
{ | ||
auto val = it->second; | ||
value = nostd::get<T>(val); | ||
} | ||
else | ||
{ | ||
value = defaultValue; | ||
} | ||
} | ||
|
||
/** | ||
* @brief Helper template to convert encoding config option to EventFormat. | ||
* Configuration option passed as `options["encoding"] = "MsgPack"`. | ||
* Default encoding is TraceLogging Dynamic Manifest (TLD). | ||
* | ||
* Valid encoding names listed below. | ||
* | ||
* For MessagePack encoding: | ||
* - "MSGPACK" | ||
* - "MsgPack" | ||
* - "MessagePack" | ||
* | ||
* For XML encoding: | ||
* - "XML" | ||
* - "xml" | ||
* | ||
* For TraceLogging Dynamic encoding: | ||
* - "TLD" | ||
* - "tld" | ||
* | ||
*/ | ||
static inline ETWProvider::EventFormat GetEncoding(const TelemetryProviderOptions &options) | ||
{ | ||
ETWProvider::EventFormat evtFmt = ETWProvider::EventFormat::ETW_MANIFEST; | ||
|
||
auto it = options.find("encoding"); | ||
if (it != options.end()) | ||
{ | ||
auto varValue = it->second; | ||
std::string val = nostd::get<std::string>(varValue); | ||
|
||
#pragma warning(push) | ||
#pragma warning(disable : 4307) /* Integral constant overflow - OK while computing hash */ | ||
auto h = utils::hashCode(val.c_str()); | ||
switch (h) | ||
{ | ||
case CONST_HASHCODE(MSGPACK): | ||
// nobrk | ||
case CONST_HASHCODE(MsgPack): | ||
// nobrk | ||
case CONST_HASHCODE(MessagePack): | ||
evtFmt = ETWProvider::EventFormat::ETW_MSGPACK; | ||
break; | ||
|
||
case CONST_HASHCODE(XML): | ||
// nobrk | ||
case CONST_HASHCODE(xml): | ||
evtFmt = ETWProvider::EventFormat::ETW_XML; | ||
break; | ||
|
||
case CONST_HASHCODE(TLD): | ||
// nobrk | ||
case CONST_HASHCODE(tld): | ||
// nobrk | ||
evtFmt = ETWProvider::EventFormat::ETW_MANIFEST; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
#pragma warning(pop) | ||
} | ||
|
||
return evtFmt; | ||
} | ||
|
||
/** | ||
* @brief Utility template to obtain etw::TracerProvider._config or etw::LoggerProvider._config | ||
* | ||
* @tparam T etw::TracerProvider | ||
* @param t etw::TracerProvider ref | ||
* @return TelemetryProviderConfiguration ref | ||
*/ | ||
template <class T> | ||
TelemetryProviderConfiguration &GetConfiguration(T &t) | ||
{ | ||
return t.config_; | ||
} | ||
|
||
/** | ||
* @brief Utility template to convert SpanId or TraceId to hex. | ||
* @param id - value of SpanId or TraceId | ||
* @return Hexadecimal representation of Id as string. | ||
*/ | ||
template <class T> | ||
static inline std::string ToLowerBase16(const T &id) | ||
{ | ||
char buf[2 * T::kSize] = {0}; | ||
id.ToLowerBase16(buf); | ||
return std::string(buf, sizeof(buf)); | ||
} | ||
|
||
/** | ||
* @brief Utility method to convert span_id (8 byte) to ActivityId GUID (16 bytes) | ||
* @param span OpenTelemetry Span Id object | ||
* @return GUID struct containing 8-bytes of SpanId + 8 NUL bytes. | ||
*/ | ||
static inline bool CopySpanIdToActivityId(const opentelemetry::trace::SpanId &span_id, | ||
GUID &outGuid) | ||
{ | ||
memset(&outGuid, 0, sizeof(outGuid)); | ||
if (!span_id.IsValid()) | ||
{ | ||
return false; | ||
} | ||
auto spanId = span_id.Id().data(); | ||
uint8_t *guidPtr = reinterpret_cast<uint8_t *>(&outGuid); | ||
for (size_t i = 0; i < 8; i++) | ||
{ | ||
guidPtr[i] = spanId[i]; | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace etw | ||
} // namespace exporter | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: keep alignment of comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format tool format this way to keep under configured line limit :)
opentelemetry-cpp/.clang-format
Line 11 in 2f462a5