Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Dec 6, 2024
1 parent 6a11053 commit ef4abd9
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exporters/fluentd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ endif()

include_directories(include)

if(OPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL)
add_definitions(-DOPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL)
endif()

# create fluentd trace exporter
add_library(opentelemetry_exporter_geneva_trace src/trace/fluentd_exporter.cc
src/trace/recordable.cc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/exporters/fluentd/common/fluentd_logging.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"
Expand Down Expand Up @@ -99,6 +100,93 @@ void inline PopulateAttribute(
}
}

void inline PopulateOwnedAttribute(
nlohmann::json &attribute, nostd::string_view key,
const opentelemetry::sdk::common::OwnedAttributeValue &value) {
// Assert size of variant to ensure that this method gets updated if the
// variant definition changes
static_assert(
nostd::variant_size<opentelemetry::common::AttributeValue>::value ==
kAttributeValueSize + 1,
"AttributeValue contains unknown type");

namespace common = opentelemetry::sdk::common;
switch(value.index()) {
case common::kTypeBool:
attribute[key.data()] = nostd::get<bool>(value);
break;
case common::kTypeInt:
attribute[key.data()] = nostd::get<int>(value);
break;
case common::kTypeUInt:
attribute[key.data()] = nostd::get<unsigned int>(value);
break;
case common::kTypeInt64:
attribute[key.data()] = nostd::get<int64_t>(value);
break;
case common::kTypeDouble:
attribute[key.data()] = nostd::get<double>(value);
break;
case common::kTypeString:
attribute[key.data()] = nostd::get<std::string>(value);
break;
case common::kTypeSpanBool:
attribute[key.data()] = {};
for (const auto &val : nostd::get<std::vector<bool>>(value)) {
attribute[key.data()].push_back(val);
}
break;
case common::kTypeSpanInt:
attribute[key.data()] = {};
for (const auto &val : nostd::get<std::vector<int>>(value)) {
attribute[key.data()].push_back(val);
}
break;
case common::kTypeSpanUInt:
attribute[key.data()] = {};
for (const auto &val : nostd::get<std::vector<unsigned int>>(value)) {
attribute[key.data()].push_back(val);
}
break;
case common::kTypeSpanInt64:
attribute[key.data()] = {};
for (const auto &val : nostd::get<std::vector<int64_t>>(value)) {
attribute[key.data()].push_back(val);
}
break;
case common::kTypeSpanDouble:
attribute[key.data()] = {};
for (const auto &val : nostd::get<std::vector<double>>(value)) {
attribute[key.data()].push_back(val);
}
break;
case common::kTypeSpanString:
attribute[key.data()] = {};
for (const auto &val :
nostd::get<std::vector<std::string>>(value)) {
attribute[key.data()].push_back(val);
}
break;
case common::kTypeUInt64:
attribute[key.data()] = nostd::get<uint64_t>(value);
break;
case common::kTypeSpanUInt64:
attribute[key.data()] = {};
for (const auto &val : nostd::get<std::vector<uint64_t>>(value)) {
attribute[key.data()].push_back(val);
}
break;
case common::kTypeSpanByte:
attribute[key.data()] = {};
for (const auto &val : nostd::get<std::vector<uint8_t>>(value)) {
attribute[key.data()].push_back(val);
}
break;
default:
break;
}
}

inline std::string AttributeValueToString(
const opentelemetry::common::AttributeValue &value) {
std::string result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ class Recordable final : public opentelemetry::sdk::logs::Recordable {
* @param Resource the resource to set
*/
void SetResource(const opentelemetry::sdk::resource::Resource
#ifdef OPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL
&resource) noexcept override;
#else
&resource) noexcept override {} // Not Supported

#endif
/**
* Set an attribute of a log.
* @param key the key of the attribute
Expand Down
15 changes: 15 additions & 0 deletions exporters/fluentd/src/log/recordable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "opentelemetry/exporters/fluentd/common/fluentd_common.h"
#include "opentelemetry/exporters/fluentd/common/fluentd_logging.h"

#include "opentelemetry/sdk/resource/resource.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/trace_id.h"
Expand Down Expand Up @@ -54,6 +55,20 @@ void Recordable::SetSpanId(const opentelemetry::trace::SpanId &span_id) noexcept
json_[FLUENT_FIELD_SPAN_ID] = std::string(span_id_lower_base16, 16);
}

#ifdef OPENTELEMETRY_ENABLE_FLUENT_RESOURCE_PUBLISH_EXPERIMENTAL
void Recordable::SetResource(const opentelemetry::sdk::resource::Resource
&resource) noexcept {
if(resource.GetAttributes().size() > 0) {
if (!json_.contains(FLUENT_FIELD_PROPERTIES)) {
json_[FLUENT_FIELD_PROPERTIES] = nlohmann::json::object();
}
}
for(const auto& [key, value] : resource.GetAttributes()) {
fluentd_common::PopulateOwnedAttribute(json_[FLUENT_FIELD_PROPERTIES], key, value);
}
}
#endif

void Recordable::SetAttribute(
nostd::string_view key,
const opentelemetry::common::AttributeValue &value) noexcept {
Expand Down

0 comments on commit ef4abd9

Please sign in to comment.