This repository was archived by the owner on Jul 31, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
opencensus/exporters/stats/stackdriver Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1414
1515#include " opencensus/exporters/stats/stackdriver/stackdriver_exporter.h"
1616
17+ #include < grpcpp/grpcpp.h>
18+
1719#include < algorithm>
1820#include < cmath>
1921#include < cstdint>
2022#include < memory>
2123#include < vector>
2224
23- #include < grpcpp/grpcpp.h>
2425#include " absl/memory/memory.h"
2526#include " absl/strings/str_cat.h"
2627#include " absl/strings/string_view.h"
@@ -156,6 +157,7 @@ void Handler::ExportViewData(
156157 }
157158 ctx[rpc_index].set_deadline (
158159 absl::ToChronoTime (absl::Now () + opts_.rpc_deadline ));
160+ opts_.prepare_client_context (&ctx[rpc_index]);
159161 auto rpc (opts_.metric_service_stub ->AsyncCreateTimeSeries (&ctx[rpc_index],
160162 request, &cq));
161163 rpc->Finish (&response, &status[rpc_index], (void *)(uintptr_t )rpc_index);
@@ -198,6 +200,7 @@ bool Handler::MaybeRegisterView(
198200 ::grpc::ClientContext context;
199201 context.set_deadline (absl::ToChronoTime (absl::Now () + opts_.rpc_deadline ));
200202 google::api::MetricDescriptor response;
203+ opts_.prepare_client_context (&context);
201204 ::grpc::Status status = opts_.metric_service_stub ->CreateMetricDescriptor (
202205 &context, request, &response);
203206 if (!status.ok ()) {
Original file line number Diff line number Diff line change @@ -80,6 +80,14 @@ struct StackdriverOptions {
8080 // instead. Useful for testing.
8181 std::unique_ptr<google::monitoring::v3::MetricService::StubInterface>
8282 metric_service_stub;
83+
84+ // Optional: A function which can be used to modify the grpc::ClientContext
85+ // before making API requests. For example, to add custom credentials.
86+ // This function will be called by the exporter before every CreateTimeSeries
87+ // and CreateMetricDescriptor RPC.
88+ // This function will not be called in parallel.
89+ std::function<void (grpc::ClientContext*)> prepare_client_context =
90+ [](grpc::ClientContext*) {};
8391};
8492
8593// Exports stats for registered views (see opencensus/stats/stats_exporter.h) to
You can’t perform that action at this time.
0 commit comments