Repository navigation
feat(common): add StartWithCorkedInitialMetadata. #16569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
58755de
d21dc76
abd5678
82dd1bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,19 +43,14 @@ class AsyncStreamingReadWriteRpcTracing | |
| } | ||
|
|
||
| future<bool> Start() override { | ||
| // It is sufficient to set `span_` as the parent of `start_span`, because | ||
| // the lower levels do not create any spans. | ||
| opentelemetry::trace::StartSpanOptions options; | ||
| options.parent = span_->GetContext(); | ||
| auto start_span = internal::MakeSpan("Start", options); | ||
| return impl_->Start().then( | ||
| [this, ss = std::move(start_span)](future<bool> f) { | ||
| EndSpan(*ss); | ||
| auto started = f.get(); | ||
| span_->SetAttribute("gl-cpp.stream_started", started); | ||
| started_ = started; | ||
| return started; | ||
| }); | ||
| return StartInternal<&AsyncStreamingReadWriteRpc<Request, Response>::Start>( | ||
| "Start"); | ||
| } | ||
|
|
||
| future<bool> StartWithCorkedInitialMetadata() override { | ||
| return StartInternal<&AsyncStreamingReadWriteRpc< | ||
| Request, Response>::StartWithCorkedInitialMetadata>( | ||
| "StartWithCorkedInitialMetadata"); | ||
| } | ||
|
Comment on lines
45
to
54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using future<bool> Start() override {
return StartInternal<&AsyncStreamingReadWriteRpc<Request, Response>::Start>("Start");
}
future<bool> StartWithCorkedInitialMetadata() override {
return StartInternal<
&AsyncStreamingReadWriteRpc<Request, Response>::StartWithCorkedInitialMetadata>(
"StartWithCorkedInitialMetadata");
}References
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree that it is "less verbose" to spell |
||
|
|
||
| future<std::optional<Response>> Read() override { | ||
|
|
@@ -119,6 +114,23 @@ class AsyncStreamingReadWriteRpcTracing | |
| return EndSpan(*std::move(span_), std::move(status)); | ||
| } | ||
|
|
||
| template <auto StartFunc> | ||
| future<bool> StartInternal(std::string_view span_name) { | ||
| // It is sufficient to set `span_` as the parent of `start_span`, because | ||
| // the lower levels do not create any spans. | ||
| opentelemetry::trace::StartSpanOptions options; | ||
| options.parent = span_->GetContext(); | ||
| auto start_span = internal::MakeSpan(span_name, options); | ||
| return std::invoke(StartFunc, *impl_) | ||
| .then([this, ss = std::move(start_span)](future<bool> f) { | ||
| EndSpan(*ss); | ||
| auto started = f.get(); | ||
| span_->SetAttribute("gl-cpp.stream_started", started); | ||
| started_ = started; | ||
| return started; | ||
| }); | ||
| } | ||
|
|
||
| std::shared_ptr<grpc::ClientContext> context_; | ||
| std::unique_ptr<AsyncStreamingReadWriteRpc<Request, Response>> impl_; | ||
| opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> span_; | ||
|
|
||
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.
Avoid using
autofor the lambda parameterfhere. Specifying the explicit typefuture<bool>is more readable, avoids creating a generic lambda unnecessarily, and is consistent with the other stream wrappers in this PR (such as the tracing and logging wrappers).References
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.
This (
auto fas the lambda parameter) is verbatim the approach used in all the other methods in this class, so IMO it would be more confusing to have just this one specifyfuture<bool>.