-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
114 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// | ||
// Copyright 2024 gRPC authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// | ||
|
||
#ifdef BAZEL_BUILD | ||
#include "examples/cpp/otel/util.h" | ||
#else | ||
#include "util.h" | ||
#endif | ||
|
||
#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h" | ||
#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" | ||
#include "opentelemetry/sdk/metrics/view/view_factory.h" | ||
|
||
#include <grpcpp/grpcpp.h> | ||
|
||
void AddLatencyView(opentelemetry::sdk::metrics::MeterProvider* provider, | ||
const std::string& name, const std::string& unit) { | ||
auto histogram_config = std::make_shared< | ||
opentelemetry::sdk::metrics::HistogramAggregationConfig>(); | ||
histogram_config->boundaries_ = { | ||
0, 0.00001, 0.00005, 0.0001, 0.0003, 0.0006, 0.0008, 0.001, 0.002, | ||
0.003, 0.004, 0.005, 0.006, 0.008, 0.01, 0.013, 0.016, 0.02, | ||
0.025, 0.03, 0.04, 0.05, 0.065, 0.08, 0.1, 0.13, 0.16, | ||
0.2, 0.25, 0.3, 0.4, 0.5, 0.65, 0.8, 1, 2, | ||
5, 10, 20, 50, 100}; | ||
provider->AddView( | ||
opentelemetry::sdk::metrics::InstrumentSelectorFactory::Create( | ||
opentelemetry::sdk::metrics::InstrumentType::kHistogram, name, unit), | ||
opentelemetry::sdk::metrics::MeterSelectorFactory::Create( | ||
"grpc-c++", grpc::Version(), ""), | ||
opentelemetry::sdk::metrics::ViewFactory::Create( | ||
name, "", unit, | ||
opentelemetry::sdk::metrics::AggregationType::kHistogram, | ||
std::move(histogram_config))); | ||
} |
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,31 @@ | ||
// | ||
// | ||
// Copyright 2024 gRPC authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// | ||
|
||
#ifndef GRPCPP_EXAMPLES_CPP_OTEL_UTIL_H | ||
#define GRPCPP_EXAMPLES_CPP_OTEL_UTIL_H | ||
|
||
#include <string> | ||
|
||
#include "opentelemetry/sdk/metrics/meter_provider.h" | ||
|
||
// Helper function that adds view for gRPC latency instrument \a name with unit | ||
// \a unit with bucket boundaries that are more useful for RPCs. | ||
void AddLatencyView(opentelemetry::sdk::metrics::MeterProvider* provider, | ||
const std::string& name, const std::string& unit); | ||
|
||
#endif // GRPCPP_EXAMPLES_CPP_OTEL_UTIL_H |