Skip to content

Commit

Permalink
[BUILD] Use fully qualified references to trace/common namespace (#2424)
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdandrutu authored Dec 5, 2023
1 parent 39ad238 commit d91e5ba
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace trace
namespace detail
{
template <class T>
inline void take_span_context_kv(SpanContext, common::KeyValueIterableView<T>)
inline void take_span_context_kv(SpanContext, opentelemetry::common::KeyValueIterableView<T>)
{}

template <class T, nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
Expand Down
13 changes: 7 additions & 6 deletions exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Logger : public opentelemetry::logs::Logger
opentelemetry::trace::TraceId trace_id,
opentelemetry::trace::SpanId span_id,
opentelemetry::trace::TraceFlags trace_flags,
common::SystemTimestamp timestamp) noexcept
opentelemetry::common::SystemTimestamp timestamp) noexcept
{
UNREFERENCED_PARAMETER(trace_flags);

Expand Down Expand Up @@ -358,11 +358,12 @@ class LoggerProvider : public opentelemetry::logs::LoggerProvider
}

nostd::shared_ptr<opentelemetry::logs::Logger> GetLogger(
nostd::string_view logger_name,
nostd::string_view library_name,
nostd::string_view version = "",
nostd::string_view schema_url = "",
const common::KeyValueIterable &attributes = common::NoopKeyValueIterable()) override
opentelemetry::nostd::string_view logger_name,
opentelemetry::nostd::string_view library_name,
opentelemetry::nostd::string_view version = "",
opentelemetry::nostd::string_view schema_url = "",
const opentelemetry::common::KeyValueIterable &attributes =
opentelemetry::common::NoopKeyValueIterable()) override
{
UNREFERENCED_PARAMETER(library_name);
UNREFERENCED_PARAMETER(version);
Expand Down
62 changes: 32 additions & 30 deletions exporters/etw/include/opentelemetry/exporters/etw/etw_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,67 +195,67 @@ class PropertyValue : public PropertyVariant
* @brief Convert non-owning common::AttributeValue to owning PropertyValue.
* @return
*/
PropertyValue &FromAttributeValue(const common::AttributeValue &v)
PropertyValue &FromAttributeValue(const opentelemetry::common::AttributeValue &v)
{
switch (v.index())
{
case common::AttributeType::kTypeBool:
case opentelemetry::common::AttributeType::kTypeBool:
PropertyVariant::operator=(nostd::get<bool>(v));
break;
case common::AttributeType::kTypeInt:
case opentelemetry::common::AttributeType::kTypeInt:
PropertyVariant::operator=(nostd::get<int32_t>(v));
break;
case common::AttributeType::kTypeInt64:
case opentelemetry::common::AttributeType::kTypeInt64:
PropertyVariant::operator=(nostd::get<int64_t>(v));
break;
case common::AttributeType::kTypeUInt:
case opentelemetry::common::AttributeType::kTypeUInt:
PropertyVariant::operator=(nostd::get<uint32_t>(v));
break;
case common::AttributeType::kTypeUInt64:
case opentelemetry::common::AttributeType::kTypeUInt64:
PropertyVariant::operator=(nostd::get<uint64_t>(v));
break;
case common::AttributeType::kTypeDouble:
case opentelemetry::common::AttributeType::kTypeDouble:
PropertyVariant::operator=(nostd::get<double>(v));
break;
case common::AttributeType::kTypeCString: {
case opentelemetry::common::AttributeType::kTypeCString: {
PropertyVariant::operator=(nostd::get<const char *>(v));
break;
}
case common::AttributeType::kTypeString: {
case opentelemetry::common::AttributeType::kTypeString: {
PropertyVariant::operator=
(std::string{nostd::string_view(nostd::get<nostd::string_view>(v)).data()});
break;
}

case common::AttributeType::kTypeSpanByte:
case opentelemetry::common::AttributeType::kTypeSpanByte:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const uint8_t>>(v)));
break;

case common::AttributeType::kTypeSpanBool:
case opentelemetry::common::AttributeType::kTypeSpanBool:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const bool>>(v)));
break;

case common::AttributeType::kTypeSpanInt:
case opentelemetry::common::AttributeType::kTypeSpanInt:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const int32_t>>(v)));
break;

case common::AttributeType::kTypeSpanInt64:
case opentelemetry::common::AttributeType::kTypeSpanInt64:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const int64_t>>(v)));
break;

case common::AttributeType::kTypeSpanUInt:
case opentelemetry::common::AttributeType::kTypeSpanUInt:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const uint32_t>>(v)));
break;

case common::AttributeType::kTypeSpanUInt64:
case opentelemetry::common::AttributeType::kTypeSpanUInt64:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const uint64_t>>(v)));
break;

case common::AttributeType::kTypeSpanDouble:
case opentelemetry::common::AttributeType::kTypeSpanDouble:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const double>>(v)));
break;

case common::AttributeType::kTypeSpanString:
case opentelemetry::common::AttributeType::kTypeSpanString:
PropertyVariant::operator=(to_vector(nostd::get<nostd::span<const nostd::string_view>>(v)));
break;

Expand All @@ -269,9 +269,9 @@ class PropertyValue : public PropertyVariant
* @brief Convert owning PropertyValue to non-owning common::AttributeValue
* @param other
*/
common::AttributeValue ToAttributeValue() const
opentelemetry::common::AttributeValue ToAttributeValue() const
{
common::AttributeValue value;
opentelemetry::common::AttributeValue value;

switch (this->index())
{
Expand Down Expand Up @@ -353,7 +353,7 @@ using PropertyValueMap = std::map<std::string, PropertyValue>;
/**
* @brief Map of PropertyValue with common::KeyValueIterable interface.
*/
class Properties : public common::KeyValueIterable, public PropertyValueMap
class Properties : public opentelemetry::common::KeyValueIterable, public PropertyValueMap
{

/**
Expand Down Expand Up @@ -404,19 +404,20 @@ class Properties : public common::KeyValueIterable, public PropertyValueMap
* container.
*
*/
Properties(const common::KeyValueIterable &other) { (*this) = other; }
Properties(const opentelemetry::common::KeyValueIterable &other) { (*this) = other; }

/**
* @brief PropertyValueMap assignment operator.
*/
Properties &operator=(const common::KeyValueIterable &other)
Properties &operator=(const opentelemetry::common::KeyValueIterable &other)
{
clear();
other.ForEachKeyValue([&](nostd::string_view key, common::AttributeValue value) noexcept {
std::string k(key.data(), key.length());
(*this)[k].FromAttributeValue(value);
return true;
});
other.ForEachKeyValue(
[&](nostd::string_view key, opentelemetry::common::AttributeValue value) noexcept {
std::string k(key.data(), key.length());
(*this)[k].FromAttributeValue(value);
return true;
});
return (*this);
}

Expand All @@ -431,12 +432,13 @@ class Properties : public common::KeyValueIterable, public PropertyValueMap
* the iteration is aborted.
* @return true if every key-value pair was iterated over
*/
bool ForEachKeyValue(nostd::function_ref<bool(nostd::string_view, common::AttributeValue)>
callback) const noexcept override
bool ForEachKeyValue(
nostd::function_ref<bool(nostd::string_view, opentelemetry::common::AttributeValue)> callback)
const noexcept override
{
for (const auto &kv : (*this))
{
const common::AttributeValue &value = kv.second.ToAttributeValue();
const opentelemetry::common::AttributeValue &value = kv.second.ToAttributeValue();
if (!callback(nostd::string_view{kv.first}, value))
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class ETWProvider
}
# if HAVE_TYPE_GUID
// TODO: consider adding UUID/GUID to spec
case common::AttributeType::TYPE_GUID: {
case opentelemetry::common::AttributeType::TYPE_GUID: {
auto temp = nostd::get<GUID>(value);
// TODO: add transform from GUID type to string?
jObj[name] = temp;
Expand Down
77 changes: 41 additions & 36 deletions exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ std::string GetName(T &t)
* @return Span Start timestamp
*/
template <class T>
common::SystemTimestamp GetStartTime(T &t)
opentelemetry::common::SystemTimestamp GetStartTime(T &t)
{
return t.GetStartTime();
}
Expand All @@ -119,7 +119,7 @@ common::SystemTimestamp GetStartTime(T &t)
* @return Span Stop timestamp
*/
template <class T>
common::SystemTimestamp GetEndTime(T &t)
opentelemetry::common::SystemTimestamp GetEndTime(T &t)
{
return t.GetEndTime();
}
Expand Down Expand Up @@ -161,7 +161,7 @@ void UpdateStatus(T &t, Properties &props)
*/

class Tracer : public opentelemetry::trace::Tracer,
public std::enable_shared_from_this<trace::Tracer>
public std::enable_shared_from_this<opentelemetry::trace::Tracer>
{

/**
Expand Down Expand Up @@ -214,16 +214,16 @@ class Tracer : public opentelemetry::trace::Tracer,
{
size_t idx = 0;
std::string linksValue;
links.ForEachKeyValue(
[&](opentelemetry::trace::SpanContext ctx, const common::KeyValueIterable &) {
if (!linksValue.empty())
{
linksValue += ',';
linksValue += ToLowerBase16(ctx.span_id());
}
idx++;
return true;
});
links.ForEachKeyValue([&](opentelemetry::trace::SpanContext ctx,
const opentelemetry::common::KeyValueIterable &) {
if (!linksValue.empty())
{
linksValue += ',';
linksValue += ToLowerBase16(ctx.span_id());
}
idx++;
return true;
});
attributes[ETW_FIELD_SPAN_LINKS] = linksValue;
}
}
Expand Down Expand Up @@ -414,7 +414,7 @@ class Tracer : public opentelemetry::trace::Tracer,
*/
nostd::shared_ptr<opentelemetry::trace::Span> StartSpan(
nostd::string_view name,
const common::KeyValueIterable &attributes,
const opentelemetry::common::KeyValueIterable &attributes,
const opentelemetry::trace::SpanContextKeyValueIterable &links,
const opentelemetry::trace::StartSpanOptions &options = {}) noexcept override
{
Expand All @@ -425,8 +425,9 @@ class Tracer : public opentelemetry::trace::Tracer,
Properties evtCopy = attributes;
return StartSpan(name, evtCopy, links, options);
#else // OPENTELEMETRY_RTTI_ENABLED is defined
common::KeyValueIterable &attribs = const_cast<common::KeyValueIterable &>(attributes);
Properties *evt = dynamic_cast<Properties *>(&attribs);
opentelemetry::common::KeyValueIterable &attribs =
const_cast<opentelemetry::common::KeyValueIterable &>(attributes);
Properties *evt = dynamic_cast<Properties *>(&attribs);
if (evt != nullptr)
{
// Pass as a reference to original modifyable collection without creating a copy
Expand Down Expand Up @@ -491,8 +492,9 @@ class Tracer : public opentelemetry::trace::Tracer,

if (sampling_result.decision == sdk::trace::Decision::DROP)
{
auto noopSpan = nostd::shared_ptr<trace::Span>{
new (std::nothrow) trace::NoopSpan(this->shared_from_this(), std::move(spanContext))};
auto noopSpan = nostd::shared_ptr<opentelemetry::trace::Span>{
new (std::nothrow)
opentelemetry::trace::NoopSpan(this->shared_from_this(), std::move(spanContext))};
return noopSpan;
}

Expand Down Expand Up @@ -602,9 +604,9 @@ class Tracer : public opentelemetry::trace::Tracer,
* @return
*/
void AddEvent(opentelemetry::trace::Span &span,
nostd::string_view name,
common::SystemTimestamp timestamp,
const common::KeyValueIterable &attributes) noexcept
opentelemetry::nostd::string_view name,
opentelemetry::common::SystemTimestamp timestamp,
const opentelemetry::common::KeyValueIterable &attributes) noexcept
{
// If RTTI is enabled by compiler, the below code modifies the attributes object passed as arg,
// which is sometime not desirable, set OPENTELEMETRY_NOT_USE_RTTI in application
Expand All @@ -614,8 +616,9 @@ class Tracer : public opentelemetry::trace::Tracer,
Properties evtCopy = attributes;
return AddEvent(span, name, timestamp, evtCopy);
#else // OPENTELEMETRY_RTTI_ENABLED is defined
common::KeyValueIterable &attribs = const_cast<common::KeyValueIterable &>(attributes);
Properties *evt = dynamic_cast<Properties *>(&attribs);
opentelemetry::common::KeyValueIterable &attribs =
const_cast<opentelemetry::common::KeyValueIterable &>(attributes);
Properties *evt = dynamic_cast<Properties *>(&attribs);
if (evt != nullptr)
{
// Pass as a reference to original modifyable collection without creating a copy
Expand All @@ -635,8 +638,8 @@ class Tracer : public opentelemetry::trace::Tracer,
* @return
*/
void AddEvent(opentelemetry::trace::Span &span,
nostd::string_view name,
common::SystemTimestamp timestamp,
opentelemetry::nostd::string_view name,
opentelemetry::common::SystemTimestamp timestamp,
Properties &evt) noexcept
{
// TODO: respect originating timestamp. Do we need to reserve
Expand Down Expand Up @@ -693,8 +696,8 @@ class Tracer : public opentelemetry::trace::Tracer,
* @return
*/
void AddEvent(opentelemetry::trace::Span &span,
nostd::string_view name,
common::SystemTimestamp timestamp) noexcept
opentelemetry::nostd::string_view name,
opentelemetry::common::SystemTimestamp timestamp) noexcept
{
AddEvent(span, name, timestamp, sdk::GetEmptyAttributes());
}
Expand Down Expand Up @@ -728,8 +731,8 @@ class Span : public opentelemetry::trace::Span
*/
Properties attributes_;

common::SystemTimestamp start_time_;
common::SystemTimestamp end_time_;
opentelemetry::common::SystemTimestamp start_time_;
opentelemetry::common::SystemTimestamp end_time_;

opentelemetry::trace::StatusCode status_code_{opentelemetry::trace::StatusCode::kUnset};
std::string status_description_;
Expand Down Expand Up @@ -794,13 +797,13 @@ class Span : public opentelemetry::trace::Span
* @brief Get start time of this Span.
* @return
*/
common::SystemTimestamp GetStartTime() { return start_time_; }
opentelemetry::common::SystemTimestamp GetStartTime() { return start_time_; }

/**
* @brief Get end time of this Span.
* @return
*/
common::SystemTimestamp GetEndTime() { return end_time_; }
opentelemetry::common::SystemTimestamp GetEndTime() { return end_time_; }

/**
* @brief Get Span Name.
Expand Down Expand Up @@ -849,7 +852,8 @@ class Span : public opentelemetry::trace::Span
* @param timestamp
* @return
*/
void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp) noexcept override
void AddEvent(nostd::string_view name,
opentelemetry::common::SystemTimestamp timestamp) noexcept override
{
owner_.AddEvent(*this, name, timestamp);
}
Expand All @@ -861,9 +865,9 @@ class Span : public opentelemetry::trace::Span
* @param attributes Event attributes.
* @return
*/
void AddEvent(nostd::string_view name,
common::SystemTimestamp timestamp,
const common::KeyValueIterable &attributes) noexcept override
void AddEvent(opentelemetry::nostd::string_view name,
opentelemetry::common::SystemTimestamp timestamp,
const opentelemetry::common::KeyValueIterable &attributes) noexcept override
{
owner_.AddEvent(*this, name, timestamp, attributes);
}
Expand Down Expand Up @@ -901,7 +905,8 @@ class Span : public opentelemetry::trace::Span
* @param value
* @return
*/
void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept override
void SetAttribute(nostd::string_view key,
const opentelemetry::common::AttributeValue &value) noexcept override
{
// don't override fields propagated from span data.
if (key == ETW_FIELD_NAME || key == ETW_FIELD_SPAN_ID || key == ETW_FIELD_TRACE_ID ||
Expand Down
Loading

1 comment on commit d91e5ba

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: d91e5ba Previous: 39ad238 Ratio
BM_BaselineBuffer/2 16975409.984588623 ns/iter 2435254.9138335963 ns/iter 6.97
BM_BaselineBuffer/4 14347150.325775146 ns/iter 2583832.1285025156 ns/iter 5.55
BM_LockFreeBuffer/2 8079392.910003662 ns/iter 1108050.5847930908 ns/iter 7.29
BM_LockFreeBuffer/4 11283597.946166992 ns/iter 1227333.8765860451 ns/iter 9.19

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.