Skip to content

Commit

Permalink
[EXPORTER]: Elasticsearch exporter put log resource in root instead o…
Browse files Browse the repository at this point in the history
…f under 'resources' (#3131)
  • Loading branch information
ShadowMaxLeb authored Nov 8, 2024
1 parent 95d039c commit 24a523c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 55 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
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 24a523c

Please sign in to comment.