|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#include <memory> |
| 5 | +#include <string> |
| 6 | +#include <utility> |
| 7 | + |
| 8 | +#include "opentelemetry/exporters/prometheus/exporter_factory.h" |
| 9 | +#include "opentelemetry/exporters/prometheus/exporter_options.h" |
| 10 | +#include "opentelemetry/exporters/prometheus/prometheus_pull_builder.h" |
| 11 | +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_builder.h" |
| 12 | +#include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" |
| 13 | +#include "opentelemetry/sdk/configuration/registry.h" |
| 14 | +#include "opentelemetry/sdk/metrics/metric_reader.h" |
| 15 | +#include "opentelemetry/version.h" |
| 16 | + |
| 17 | +OPENTELEMETRY_BEGIN_NAMESPACE |
| 18 | +namespace exporter |
| 19 | +{ |
| 20 | +namespace metrics |
| 21 | +{ |
| 22 | + |
| 23 | +void PrometheusPullBuilder::Register(opentelemetry::sdk::configuration::Registry *registry) |
| 24 | +{ |
| 25 | + auto builder = std::make_unique<PrometheusPullBuilder>(); |
| 26 | + registry->SetPrometheusPullMetricExporterBuilder(std::move(builder)); |
| 27 | +} |
| 28 | + |
| 29 | +std::unique_ptr<opentelemetry::sdk::metrics::MetricReader> PrometheusPullBuilder::Build( |
| 30 | + const opentelemetry::sdk::configuration::PrometheusPullMetricExporterConfiguration *model) const |
| 31 | +{ |
| 32 | + opentelemetry::exporter::metrics::PrometheusExporterOptions options(nullptr); |
| 33 | + |
| 34 | + std::string url(model->host); |
| 35 | + url.append(":"); |
| 36 | + url.append(std::to_string(model->port)); |
| 37 | + |
| 38 | + options.url = url; |
| 39 | + options.populate_target_info = true; |
| 40 | + options.without_otel_scope = model->without_scope_info; |
| 41 | + options.without_units = model->without_units; |
| 42 | + options.without_type_suffix = model->without_type_suffix; |
| 43 | + |
| 44 | + return PrometheusExporterFactory::Create(options); |
| 45 | +} |
| 46 | + |
| 47 | +} // namespace metrics |
| 48 | +} // namespace exporter |
| 49 | +OPENTELEMETRY_END_NAMESPACE |
0 commit comments