Skip to content

Commit

Permalink
Merge branch 'open-telemetry:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcw authored Nov 10, 2024
2 parents 01e5bcf + 1863fe7 commit ae421a9
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,8 @@ jobs:
CXX_STANDARD: '14'
run: |
./ci/do_ci.sh cmake.w3c.trace-context.build-server
cd $HOME/build/ext/test/w3c_tracecontext_test
./w3c_tracecontext_test &
cd $HOME/build/ext/test/w3c_tracecontext_http_test_server
./w3c_tracecontext_http_test_server &
- name: Checkout w3c/trace-context repo
uses: actions/checkout@v4
with:
Expand Down
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
2 changes: 1 addition & 1 deletion ext/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

add_subdirectory(http)
if(BUILD_W3CTRACECONTEXT_TEST)
add_subdirectory(w3c_tracecontext_test)
add_subdirectory(w3c_tracecontext_http_test_server)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

cc_binary(
name = "w3c_tracecontext_test",
name = "w3c_tracecontext_http_test_server",
srcs = [
"main.cc",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include)

add_executable(w3c_tracecontext_test main.cc)
add_executable(w3c_tracecontext_http_test_server main.cc)
target_link_libraries(
w3c_tracecontext_test
w3c_tracecontext_http_test_server
PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace
opentelemetry_http_client_curl opentelemetry_exporter_ostream_span
${CURL_LIBRARIES} nlohmann_json::nlohmann_json)
if(nlohmann_json_clone)
add_dependencies(w3c_tracecontext_test nlohmann_json::nlohmann_json)
add_dependencies(w3c_tracecontext_http_test_server
nlohmann_json::nlohmann_json)
endif()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ instructions](https://github.com/w3c/trace-context/tree/master/test#implement-te
1: Build and start the test service endpoint:

```sh
./w3c_tracecontext_test
./w3c_tracecontext_http_test_server

Listening to http://localhost:30000/test
```

A custom port number for the test service to listen to can be specified:

```sh
./w3c_tracecontext_test 31339
./w3c_tracecontext_http_test_server 31339

Listening to http://localhost:31339/test
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void initTracer()
nostd::shared_ptr<trace_api::Tracer> get_tracer()
{
auto provider = trace_api::Provider::GetTracerProvider();
return provider->GetTracer("w3c_tracecontext_test");
return provider->GetTracer("w3c_tracecontext_http_test_server");
}

struct Uri
Expand Down

0 comments on commit ae421a9

Please sign in to comment.