Skip to content

Commit 24a523c

Browse files
authored
[EXPORTER]: Elasticsearch exporter put log resource in root instead of under 'resources' (open-telemetry#3131)
1 parent 95d039c commit 24a523c

File tree

3 files changed

+19
-55
lines changed

3 files changed

+19
-55
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Important changes:
3535
* Upgrade to prometheus 1.3.0
3636
[#3122](https://github.com/open-telemetry/opentelemetry-cpp/pull/3122)
3737

38+
* [EXPORTER] Change log resources location for ElasticsearchLogRecordExporter
39+
[#3119](https://github.com/open-telemetry/opentelemetry-cpp/pull/3131)
40+
41+
* Moved from `root/resources` to `root`
42+
3843
## [1.17 2024-10-07]
3944

4045
* [CI] Add a clang-tidy build

exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable
2828
{
2929
private:
3030
/**
31-
* A helper method that writes a key/value pair under a specified name, the two names used here
32-
* being "attributes" and "resources"
31+
* A helper method that writes a value under a specified name.
32+
* `name` will be at the root of the JSON object. If it has to be nested under some other keys,
33+
* then write `name` as `key1.key2.[...].name`
3334
*/
34-
void WriteKeyValue(nostd::string_view key,
35-
const opentelemetry::common::AttributeValue &value,
36-
const std::string &name);
37-
38-
void WriteKeyValue(nostd::string_view key,
39-
const opentelemetry::sdk::common::OwnedAttributeValue &value,
40-
const std::string &name);
35+
void WriteValue(const opentelemetry::sdk::common::OwnedAttributeValue &value,
36+
const std::string &name);
4137

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

exporters/elasticsearch/src/es_log_recordable.cc

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,33 @@ namespace exporter
1414
{
1515
namespace logs
1616
{
17-
void ElasticSearchRecordable::WriteKeyValue(nostd::string_view key,
18-
const opentelemetry::common::AttributeValue &value,
19-
const std::string &name)
20-
{
21-
switch (value.index())
22-
{
23-
case common::AttributeType::kTypeBool:
24-
json_[name][key.data()] = opentelemetry::nostd::get<bool>(value) ? true : false;
25-
return;
26-
case common::AttributeType::kTypeInt:
27-
json_[name][key.data()] = opentelemetry::nostd::get<int>(value);
28-
return;
29-
case common::AttributeType::kTypeInt64:
30-
json_[name][key.data()] = opentelemetry::nostd::get<int64_t>(value);
31-
return;
32-
case common::AttributeType::kTypeUInt:
33-
json_[name][key.data()] = opentelemetry::nostd::get<unsigned int>(value);
34-
return;
35-
case common::AttributeType::kTypeUInt64:
36-
json_[name][key.data()] = opentelemetry::nostd::get<uint64_t>(value);
37-
return;
38-
case common::AttributeType::kTypeDouble:
39-
json_[name][key.data()] = opentelemetry::nostd::get<double>(value);
40-
return;
41-
case common::AttributeType::kTypeCString:
42-
json_[name][key.data()] = opentelemetry::nostd::get<const char *>(value);
43-
return;
44-
case common::AttributeType::kTypeString:
45-
json_[name][key.data()] =
46-
opentelemetry::nostd::get<opentelemetry::nostd::string_view>(value).data();
47-
return;
48-
default:
49-
return;
50-
}
51-
}
52-
53-
void ElasticSearchRecordable::WriteKeyValue(
54-
nostd::string_view key,
17+
void ElasticSearchRecordable::WriteValue(
5518
const opentelemetry::sdk::common::OwnedAttributeValue &value,
5619
const std::string &name)
5720
{
5821
namespace common = opentelemetry::sdk::common;
5922
switch (value.index())
6023
{
6124
case common::kTypeBool:
62-
json_[name][key.data()] = opentelemetry::nostd::get<bool>(value) ? true : false;
25+
json_[name] = opentelemetry::nostd::get<bool>(value) ? true : false;
6326
return;
6427
case common::kTypeInt:
65-
json_[name][key.data()] = opentelemetry::nostd::get<int>(value);
28+
json_[name] = opentelemetry::nostd::get<int>(value);
6629
return;
6730
case common::kTypeInt64:
68-
json_[name][key.data()] = opentelemetry::nostd::get<int64_t>(value);
31+
json_[name] = opentelemetry::nostd::get<int64_t>(value);
6932
return;
7033
case common::kTypeUInt:
71-
json_[name][key.data()] = opentelemetry::nostd::get<unsigned int>(value);
34+
json_[name] = opentelemetry::nostd::get<unsigned int>(value);
7235
return;
7336
case common::kTypeUInt64:
74-
json_[name][key.data()] = opentelemetry::nostd::get<uint64_t>(value);
37+
json_[name] = opentelemetry::nostd::get<uint64_t>(value);
7538
return;
7639
case common::kTypeDouble:
77-
json_[name][key.data()] = opentelemetry::nostd::get<double>(value);
40+
json_[name] = opentelemetry::nostd::get<double>(value);
7841
return;
7942
case common::kTypeString:
80-
json_[name][key.data()] = opentelemetry::nostd::get<std::string>(value).data();
43+
json_[name] = opentelemetry::nostd::get<std::string>(value).data();
8144
return;
8245
default:
8346
return;
@@ -321,7 +284,7 @@ void ElasticSearchRecordable::SetResource(
321284
{
322285
for (auto &attribute : resource.GetAttributes())
323286
{
324-
WriteKeyValue(attribute.first, attribute.second, "resource");
287+
WriteValue(attribute.second, attribute.first);
325288
}
326289
}
327290

0 commit comments

Comments
 (0)