Skip to content

Commit

Permalink
Merge branch 'main' into rename-w3c-tracecontext
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 authored Nov 8, 2024
2 parents a48838b + 24a523c commit 7925a01
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 67 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Important changes:
* Upgrade to prometheus 1.3.0
[#3122](https://github.com/open-telemetry/opentelemetry-cpp/pull/3122)

* [EXPORTER] Change log resources location for ElasticsearchLogRecordExporter
[#3119](https://github.com/open-telemetry/opentelemetry-cpp/pull/3131)

* Moved from `root/resources` to `root`

## [1.17 2024-10-07]

* [CI] Add a clang-tidy build
Expand Down
6 changes: 4 additions & 2 deletions api/include/opentelemetry/common/spin_lock_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class SpinLockMutex
# else
__builtin_ia32_pause();
# endif
#elif defined(__arm__)
__asm__ volatile("yield" ::: "memory");
#elif defined(__armel__) || defined(__ARMEL__)
asm volatile("nop" ::: "memory");
#elif defined(__arm__) || defined(__aarch64__) // arm big endian / arm64
__asm__ __volatile__("yield" ::: "memory");
#else
// TODO: Issue PAGE/YIELD on other architectures.
#endif
Expand Down
5 changes: 2 additions & 3 deletions api/include/opentelemetry/logs/event_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ class EventLogger
}
nostd::unique_ptr<LogRecord> log_record = delegate_logger->CreateLogRecord();

IgnoreTraitResult(
detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::template Set(
log_record.get(), std::forward<ArgumentType>(args))...);
IgnoreTraitResult(detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::Set(
log_record.get(), std::forward<ArgumentType>(args))...);

EmitEvent(event_name, std::move(log_record));
}
Expand Down
5 changes: 2 additions & 3 deletions api/include/opentelemetry/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ class Logger
return;
}

IgnoreTraitResult(
detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::template Set(
log_record.get(), std::forward<ArgumentType>(args))...);
IgnoreTraitResult(detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::Set(
log_record.get(), std::forward<ArgumentType>(args))...);

EmitLogRecord(std::move(log_record));
}
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/logs/logger_type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ struct LogRecordSetterTrait
* = nullptr>
inline static LogRecord *Set(LogRecord *log_record, ArgumentType &&arg) noexcept
{
return LogRecordSetterTrait<common::KeyValueIterable>::template Set(
log_record, std::forward<ArgumentType>(arg));
return LogRecordSetterTrait<common::KeyValueIterable>::Set(log_record,
std::forward<ArgumentType>(arg));
}

template <class ArgumentType,
Expand Down
6 changes: 4 additions & 2 deletions api/test/common/spinlock_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ static void BM_ProcYieldSpinLockThrashing(benchmark::State &s)
# else
__builtin_ia32_pause();
# endif
#elif defined(__arm__)
__asm__ volatile("yield" ::: "memory");
#elif defined(__armel__) || defined(__ARMEL__)
asm volatile("nop" ::: "memory");
#elif defined(__arm__) || defined(__aarch64__) // arm big endian / arm64
__asm__ __volatile__("yield" ::: "memory");
#endif
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable
{
private:
/**
* A helper method that writes a key/value pair under a specified name, the two names used here
* being "attributes" and "resources"
* A helper method that writes a value under a specified name.
* `name` will be at the root of the JSON object. If it has to be nested under some other keys,
* then write `name` as `key1.key2.[...].name`
*/
void WriteKeyValue(nostd::string_view key,
const opentelemetry::common::AttributeValue &value,
const std::string &name);

void WriteKeyValue(nostd::string_view key,
const opentelemetry::sdk::common::OwnedAttributeValue &value,
const std::string &name);
void WriteValue(const opentelemetry::sdk::common::OwnedAttributeValue &value,
const std::string &name);

void WriteValue(const opentelemetry::common::AttributeValue &value, const std::string &name);

Expand Down
55 changes: 9 additions & 46 deletions exporters/elasticsearch/src/es_log_recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,70 +14,33 @@ namespace exporter
{
namespace logs
{
void ElasticSearchRecordable::WriteKeyValue(nostd::string_view key,
const opentelemetry::common::AttributeValue &value,
const std::string &name)
{
switch (value.index())
{
case common::AttributeType::kTypeBool:
json_[name][key.data()] = opentelemetry::nostd::get<bool>(value) ? true : false;
return;
case common::AttributeType::kTypeInt:
json_[name][key.data()] = opentelemetry::nostd::get<int>(value);
return;
case common::AttributeType::kTypeInt64:
json_[name][key.data()] = opentelemetry::nostd::get<int64_t>(value);
return;
case common::AttributeType::kTypeUInt:
json_[name][key.data()] = opentelemetry::nostd::get<unsigned int>(value);
return;
case common::AttributeType::kTypeUInt64:
json_[name][key.data()] = opentelemetry::nostd::get<uint64_t>(value);
return;
case common::AttributeType::kTypeDouble:
json_[name][key.data()] = opentelemetry::nostd::get<double>(value);
return;
case common::AttributeType::kTypeCString:
json_[name][key.data()] = opentelemetry::nostd::get<const char *>(value);
return;
case common::AttributeType::kTypeString:
json_[name][key.data()] =
opentelemetry::nostd::get<opentelemetry::nostd::string_view>(value).data();
return;
default:
return;
}
}

void ElasticSearchRecordable::WriteKeyValue(
nostd::string_view key,
void ElasticSearchRecordable::WriteValue(
const opentelemetry::sdk::common::OwnedAttributeValue &value,
const std::string &name)
{
namespace common = opentelemetry::sdk::common;
switch (value.index())
{
case common::kTypeBool:
json_[name][key.data()] = opentelemetry::nostd::get<bool>(value) ? true : false;
json_[name] = opentelemetry::nostd::get<bool>(value) ? true : false;
return;
case common::kTypeInt:
json_[name][key.data()] = opentelemetry::nostd::get<int>(value);
json_[name] = opentelemetry::nostd::get<int>(value);
return;
case common::kTypeInt64:
json_[name][key.data()] = opentelemetry::nostd::get<int64_t>(value);
json_[name] = opentelemetry::nostd::get<int64_t>(value);
return;
case common::kTypeUInt:
json_[name][key.data()] = opentelemetry::nostd::get<unsigned int>(value);
json_[name] = opentelemetry::nostd::get<unsigned int>(value);
return;
case common::kTypeUInt64:
json_[name][key.data()] = opentelemetry::nostd::get<uint64_t>(value);
json_[name] = opentelemetry::nostd::get<uint64_t>(value);
return;
case common::kTypeDouble:
json_[name][key.data()] = opentelemetry::nostd::get<double>(value);
json_[name] = opentelemetry::nostd::get<double>(value);
return;
case common::kTypeString:
json_[name][key.data()] = opentelemetry::nostd::get<std::string>(value).data();
json_[name] = opentelemetry::nostd::get<std::string>(value).data();
return;
default:
return;
Expand Down Expand Up @@ -321,7 +284,7 @@ void ElasticSearchRecordable::SetResource(
{
for (auto &attribute : resource.GetAttributes())
{
WriteKeyValue(attribute.first, attribute.second, "resource");
WriteValue(attribute.second, attribute.first);
}
}

Expand Down

0 comments on commit 7925a01

Please sign in to comment.