Skip to content

Commit

Permalink
fix(metrics): ostream exporter should print out resource attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bsarden committed Jul 28, 2022
1 parent 3a8f913 commit cccc5b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ class OStreamMetricExporter final : public opentelemetry::sdk::metrics::MetricEx
mutable opentelemetry::common::SpinLockMutex lock_;
bool isShutdown() const noexcept;
void printInstrumentationInfoMetricData(
const sdk::metrics::InstrumentationInfoMetrics &info_metrics);
const sdk::metrics::InstrumentationInfoMetrics &info_metrics, const sdk::metrics::ResourceMetrics &data);
void printPointData(const opentelemetry::sdk::metrics::PointType &point_data);
void printPointAttributes(const opentelemetry::sdk::metrics::PointAttributes &point_attributes);
void printAttributes(
const std::unordered_map<std::string, sdk::common::OwnedAttributeValue> &map,
const std::string prefix);
void printResources(const opentelemetry::sdk::resource::Resource &resources);
};
} // namespace metrics
} // namespace exporter
Expand Down
27 changes: 25 additions & 2 deletions exporters/ostream/src/metric_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,33 @@ sdk::common::ExportResult OStreamMetricExporter::Export(

for (auto &record : data.instrumentation_info_metric_data_)
{
printInstrumentationInfoMetricData(record);
printInstrumentationInfoMetricData(record, data);
}
return sdk::common::ExportResult::kSuccess;
}

void OStreamMetricExporter::printAttributes(
const std::unordered_map<std::string, sdk::common::OwnedAttributeValue> &map,
const std::string prefix)
{
for (const auto &kv : map)
{
sout_ << prefix << kv.first << ": ";
opentelemetry::exporter::ostream_common::print_value(kv.second, sout_);
}
}

void OStreamMetricExporter::printResources(const opentelemetry::sdk::resource::Resource &resources)
{
auto attributes = resources.GetAttributes();
if (attributes.size())
{
printAttributes(attributes, "\n\t");
}
}

void OStreamMetricExporter::printInstrumentationInfoMetricData(
const sdk::metrics::InstrumentationInfoMetrics &info_metric)
const sdk::metrics::InstrumentationInfoMetrics &info_metric, const sdk::metrics::ResourceMetrics &data)
{
// sout_ is shared
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
Expand All @@ -109,6 +129,9 @@ void OStreamMetricExporter::printInstrumentationInfoMetricData(
printPointAttributes(pd.attributes);
}
}

sout_ << "\n resources\t:";
printResources(*data.resource_);
}
sout_ << "\n}\n";
}
Expand Down

0 comments on commit cccc5b4

Please sign in to comment.