Skip to content

Commit

Permalink
Upgrade instrumentation_library_metrics to scope_metrics (open-te…
Browse files Browse the repository at this point in the history
…lemetry#1507)

* Upgrade `instrumentation_library_metrics` to `scope_metrics`

Signed-off-by: owentou <owentou@tencent.com>

* Rename `InstrumentationLibrary` -> `InstrumentationScope`

Signed-off-by: owentou <owentou@tencent.com>

* Fix style

Signed-off-by: owentou <owentou@tencent.com>

* Fix compiling

Signed-off-by: owentou <owentou@tencent.com>

* Remove duplicated `ElasticSearchRecordable::SetInstrumentationLibrary`

Signed-off-by: owentou <owentou@tencent.com>

* Fix comments

Signed-off-by: owentou <owentou@tencent.com>

* Update the usage of `instrumentation_library` of prometheus exporter.

Signed-off-by: owentou <owentou@tencent.com>
  • Loading branch information
owent authored and yxue committed Dec 5, 2022
1 parent 567fb5b commit 67be77f
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ class OStreamMetricExporter final : public opentelemetry::sdk::metrics::PushMetr
mutable opentelemetry::common::SpinLockMutex lock_;
sdk::metrics::AggregationTemporality aggregation_temporality_;
bool isShutdown() const noexcept;
<<<<<<< HEAD
void printInstrumentationInfoMetricData(const sdk::metrics::ScopeMetrics &info_metrics,
const sdk::metrics::ResourceMetrics &data);
=======
void printInstrumentationInfoMetricData(const sdk::metrics::ScopeMetrics &info_metrics);
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
void printPointData(const opentelemetry::sdk::metrics::PointType &point_data);
void printPointAttributes(const opentelemetry::sdk::metrics::PointAttributes &point_attributes);
void printAttributes(const std::map<std::string, sdk::common::OwnedAttributeValue> &map,
Expand Down
8 changes: 8 additions & 0 deletions exporters/ostream/src/metric_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,21 @@ void OStreamMetricExporter::printResources(const opentelemetry::sdk::resource::R
}

void OStreamMetricExporter::printInstrumentationInfoMetricData(
<<<<<<< HEAD
const sdk::metrics::ScopeMetrics &info_metric,
const sdk::metrics::ResourceMetrics &data)
=======
const sdk::metrics::ScopeMetrics &info_metric)
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
{
// sout_ is shared
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
sout_ << "{";
<<<<<<< HEAD
sout_ << "\n scope name\t: " << info_metric.scope_->GetName()
=======
sout_ << "\n name\t\t: " << info_metric.scope_->GetName()
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
<< "\n schema url\t: " << info_metric.scope_->GetSchemaURL()
<< "\n version\t: " << info_metric.scope_->GetVersion();
for (const auto &record : info_metric.metric_data_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ class OtlpMetricUtils
static void ConvertGaugeMetric(const opentelemetry::sdk::metrics::MetricData &metric_data,
proto::metrics::v1::Gauge *const gauge) noexcept;

<<<<<<< HEAD
<<<<<<< HEAD:exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metric_utils.h
static void PopulateInstrumentInfoMetrics(
=======
static void PopulateInstrumentationInfoMetric(
>>>>>>> 85212acd (Add the in-memory metrics exporter.):exporters/otlp/include/opentelemetry/exporters/otlp/otlp_metrics_utils.h
=======
static void PopulateInstrumentInfoMetrics(
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
const opentelemetry::sdk::metrics::MetricData &metric_data,
proto::metrics::v1::Metric *metric) noexcept;

Expand Down
12 changes: 12 additions & 0 deletions exporters/otlp/src/otlp_http_metric_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,31 +116,43 @@ opentelemetry::sdk::common::ExportResult OtlpHttpMetricExporter::Export(
{
if (http_client_->IsShutdown())
{
<<<<<<< HEAD
<<<<<<< HEAD
std::size_t metric_count = data.scope_metric_data_.size();
=======
std::size_t metric_count = data.instrumentation_info_metric_data_.size();
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
std::size_t metric_count = data.scope_metric_data_.size();
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Client] ERROR: Export "
<< metric_count << " metric(s) failed, exporter is shutdown");
return opentelemetry::sdk::common::ExportResult::kFailure;
}

<<<<<<< HEAD
<<<<<<< HEAD
if (data.scope_metric_data_.empty())
=======
if (data.instrumentation_info_metric_data_.empty())
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======
if (data.scope_metric_data_.empty())
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
{
return opentelemetry::sdk::common::ExportResult::kSuccess;
}
proto::collector::metrics::v1::ExportMetricsServiceRequest service_request;
OtlpMetricUtils::PopulateRequest(data, &service_request);
<<<<<<< HEAD
<<<<<<< HEAD
std::size_t metric_count = data.scope_metric_data_.size();
#ifdef ENABLE_ASYNC_EXPORT
=======
std::size_t metric_count = data.instrumentation_info_metric_data_.size();
=======
std::size_t metric_count = data.scope_metric_data_.size();
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
# ifdef ENABLE_ASYNC_EXPORT
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
http_client_->Export(service_request, [metric_count](
Expand Down
10 changes: 10 additions & 0 deletions exporters/otlp/src/otlp_metric_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,14 @@ void OtlpMetricUtils::PopulateResourceMetrics(
continue;
}
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
auto scope_lib_metrics = resource_metrics->add_scope_metrics();
proto::common::v1::InstrumentationScope *scope = scope_lib_metrics->mutable_scope();
scope->set_name(scope_metrics.scope_->GetName());
scope->set_version(scope_metrics.scope_->GetVersion());
<<<<<<< HEAD
=======
auto instrumentation_lib_metrics = resource_metrics->add_instrumentation_library_metrics();
proto::common::v1::InstrumentationLibrary *instrumentation_library =
Expand All @@ -309,6 +313,12 @@ void OtlpMetricUtils::PopulateResourceMetrics(
=======
PopulateInstrumentationInfoMetric(metric_data, instrumentation_lib_metrics->add_metrics());
>>>>>>> 8d1f241d ([Metrics] Add OTLP http metric exporter (#1487))
=======

for (auto &metric_data : scope_metrics.metric_data_)
{
PopulateInstrumentInfoMetrics(metric_data, scope_lib_metrics->add_metrics());
>>>>>>> f846878c (Upgrade `instrumentation_library_metrics` to `scope_metrics` (#1507))
}
}
}
Expand Down
Loading

0 comments on commit 67be77f

Please sign in to comment.