Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 0ec2c1b

Browse files
authored
Stackdriver trace exporter: add prepare_client_context callback. (#445)
1 parent 1d75995 commit 0ec2c1b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

opencensus/exporters/trace/stackdriver/internal/stackdriver_exporter.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ void Handler::Export(
237237
::google::protobuf::Empty response;
238238
grpc::ClientContext context;
239239
context.set_deadline(absl::ToChronoTime(absl::Now() + opts_.rpc_deadline));
240+
opts_.prepare_client_context(&context);
240241
grpc::Status status =
241242
opts_.trace_service_stub->BatchWriteSpans(&context, request, &response);
242243
if (!status.ok()) {

opencensus/exporters/trace/stackdriver/stackdriver_exporter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef OPENCENSUS_EXPORTERS_TRACE_STACKDRIVER_STACKDRIVER_EXPORTER_H_
1616
#define OPENCENSUS_EXPORTERS_TRACE_STACKDRIVER_STACKDRIVER_EXPORTER_H_
1717

18+
#include <functional>
1819
#include <memory>
1920
#include <string>
2021

@@ -39,6 +40,13 @@ struct StackdriverOptions {
3940
// instead. Useful for testing.
4041
std::unique_ptr<google::devtools::cloudtrace::v2::TraceService::StubInterface>
4142
trace_service_stub;
43+
44+
// (optional) A function which can be used to modify the grpc::ClientContext
45+
// before making API requests. For example, to add custom credentials.
46+
// This function will be called by the exporter before every BatchWriteSpans
47+
// RPC. This function will not be called in parallel.
48+
std::function<void(grpc::ClientContext*)> prepare_client_context =
49+
[](grpc::ClientContext*) {};
4250
};
4351

4452
class StackdriverExporter {

0 commit comments

Comments
 (0)