-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
382 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "common_metrics_foo_library", | ||
srcs = [ | ||
"foo_library.cc", | ||
], | ||
hdrs = [ | ||
"foo_library.h", | ||
], | ||
defines = ["BAZEL_BUILD"], | ||
deps = [ | ||
"//api", | ||
"//sdk:headers", | ||
"//sdk/src/metrics", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include <chrono> | ||
# include <thread> | ||
# include "opentelemetry/metrics/provider.h" | ||
|
||
namespace nostd = opentelemetry::nostd; | ||
namespace metrics_api = opentelemetry::metrics; | ||
|
||
void foo_library(const std::string &name) | ||
{ | ||
// Get the Meter from the MeterProvider | ||
auto provider = metrics_api::Provider::GetMeterProvider(); | ||
nostd::shared_ptr<metrics_api::Meter> meter = provider->GetMeter(name, "1.2.0"); | ||
auto double_counter = meter->CreateDoubleCounter(name); | ||
double_counter->Add(28.5); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
double_counter->Add(3.14); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
double_counter->Add(23.5); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(5000)); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include <string> | ||
|
||
void foo_library(const std::string &name); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef ENABLE_METRICS_PREVIEW | ||
# include <memory> | ||
# include "opentelemetry/exporters/ostream/metric_exporter.h" | ||
# include "opentelemetry/metrics/provider.h" | ||
# include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" | ||
# include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" | ||
# include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h" | ||
# include "opentelemetry/sdk/metrics/meter.h" | ||
# include "opentelemetry/sdk/metrics/meter_provider.h" | ||
|
||
# ifdef BAZEL_BUILD | ||
# include "examples/common/metrics_foo_library/foo_library.h" | ||
# else | ||
# include "metrics_foo_library/foo_library.h" | ||
# endif | ||
|
||
namespace metric_sdk = opentelemetry::sdk::metrics; | ||
namespace nostd = opentelemetry::nostd; | ||
namespace common = opentelemetry::common; | ||
namespace exportermetrics = opentelemetry::exporter::metrics; | ||
namespace metrics_api = opentelemetry::metrics; | ||
|
||
namespace | ||
{ | ||
|
||
void initMetrics(const std::string &name) | ||
{ | ||
std::unique_ptr<metric_sdk::MetricExporter> exporter{new exportermetrics::OStreamMetricExporter}; | ||
std::vector<std::unique_ptr<metric_sdk::MetricExporter>> exporters; | ||
|
||
std::string version{"1.2.0"}; | ||
std::string schema{"https://opentelemetry.io/schemas/1.2.0"}; | ||
|
||
// Initialize and set the global MeterProvider | ||
metric_sdk::PeriodicExportingMetricReaderOptions options; | ||
options.export_interval_millis = std::chrono::milliseconds(1000); | ||
options.export_timeout_millis = std::chrono::milliseconds(500); | ||
std::unique_ptr<metric_sdk::MetricReader> reader{ | ||
new metric_sdk::PeriodicExportingMetricReader(std::move(exporter), options)}; | ||
auto provider = std::shared_ptr<metrics_api::MeterProvider>( | ||
new metric_sdk::MeterProvider(std::move(exporters))); | ||
auto p = std::static_pointer_cast<metric_sdk::MeterProvider>(provider); | ||
p->AddMetricReader(std::move(reader)); | ||
std::unique_ptr<metric_sdk::InstrumentSelector> instrument_selector{ | ||
new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kCounter, name)}; | ||
std::unique_ptr<metric_sdk::MeterSelector> meter_selector{ | ||
new metric_sdk::MeterSelector(name, version, schema)}; | ||
std::unique_ptr<metric_sdk::View> view{ | ||
new metric_sdk::View{name, "description", metric_sdk::AggregationType::kSum}}; | ||
p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(view)); | ||
metrics_api::Provider::SetMeterProvider(provider); | ||
} | ||
} // namespace | ||
int main() | ||
{ | ||
std::string name{"ostream_metric_example"}; | ||
initMetrics(name); | ||
foo_library(name); | ||
} | ||
#else | ||
int main() {} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
755f109
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_SpinLockThrashing/1/process_time/real_time
1.4771269363107034
ms/iter0.13078752007384906
ms/iter11.29
BM_SpinLockThrashing/2/process_time/real_time
2.9463249704112178
ms/iter0.2554788518307814
ms/iter11.53
BM_ProcYieldSpinLockThrashing/1/process_time/real_time
2.946163478650545
ms/iter0.13001907292013928
ms/iter22.66
BM_NaiveSpinLockThrashing/1/process_time/real_time
0.8838350122625177
ms/iter0.14128856100599307
ms/iter6.26
This comment was automatically generated by workflow using github-action-benchmark.
755f109
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_LockFreeBuffer/1
4216000.080108643
ns/iter377973.2680820919
ns/iter11.15
BM_LockFreeBuffer/2
4440041.780471802
ns/iter1787918.3292388916
ns/iter2.48
This comment was automatically generated by workflow using github-action-benchmark.