diff --git a/CHANGELOG.md b/CHANGELOG.md index 04b1603c3c..6d8ca3317f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h index 52d24cada6..9baf9ef7bd 100644 --- a/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h +++ b/exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h @@ -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); diff --git a/exporters/elasticsearch/src/es_log_recordable.cc b/exporters/elasticsearch/src/es_log_recordable.cc index 56d7cea71b..3412a8cc61 100644 --- a/exporters/elasticsearch/src/es_log_recordable.cc +++ b/exporters/elasticsearch/src/es_log_recordable.cc @@ -14,44 +14,7 @@ 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(value) ? true : false; - return; - case common::AttributeType::kTypeInt: - json_[name][key.data()] = opentelemetry::nostd::get(value); - return; - case common::AttributeType::kTypeInt64: - json_[name][key.data()] = opentelemetry::nostd::get(value); - return; - case common::AttributeType::kTypeUInt: - json_[name][key.data()] = opentelemetry::nostd::get(value); - return; - case common::AttributeType::kTypeUInt64: - json_[name][key.data()] = opentelemetry::nostd::get(value); - return; - case common::AttributeType::kTypeDouble: - json_[name][key.data()] = opentelemetry::nostd::get(value); - return; - case common::AttributeType::kTypeCString: - json_[name][key.data()] = opentelemetry::nostd::get(value); - return; - case common::AttributeType::kTypeString: - json_[name][key.data()] = - opentelemetry::nostd::get(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) { @@ -59,25 +22,25 @@ void ElasticSearchRecordable::WriteKeyValue( switch (value.index()) { case common::kTypeBool: - json_[name][key.data()] = opentelemetry::nostd::get(value) ? true : false; + json_[name] = opentelemetry::nostd::get(value) ? true : false; return; case common::kTypeInt: - json_[name][key.data()] = opentelemetry::nostd::get(value); + json_[name] = opentelemetry::nostd::get(value); return; case common::kTypeInt64: - json_[name][key.data()] = opentelemetry::nostd::get(value); + json_[name] = opentelemetry::nostd::get(value); return; case common::kTypeUInt: - json_[name][key.data()] = opentelemetry::nostd::get(value); + json_[name] = opentelemetry::nostd::get(value); return; case common::kTypeUInt64: - json_[name][key.data()] = opentelemetry::nostd::get(value); + json_[name] = opentelemetry::nostd::get(value); return; case common::kTypeDouble: - json_[name][key.data()] = opentelemetry::nostd::get(value); + json_[name] = opentelemetry::nostd::get(value); return; case common::kTypeString: - json_[name][key.data()] = opentelemetry::nostd::get(value).data(); + json_[name] = opentelemetry::nostd::get(value).data(); return; default: return; @@ -321,7 +284,7 @@ void ElasticSearchRecordable::SetResource( { for (auto &attribute : resource.GetAttributes()) { - WriteKeyValue(attribute.first, attribute.second, "resource"); + WriteValue(attribute.second, attribute.first); } }