Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading