-
Notifications
You must be signed in to change notification settings - Fork 4
impl: Add TracingConnection decorator #84
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0ecdae7
impl: Add TracingConnection decorator
cuiy0006 d28db7f
format
cuiy0006 fb6f170
bazel
cuiy0006 62eabb1
bazel
cuiy0006 b7864b3
cmake
cuiy0006 e1a5e0f
flag and checkers
cuiy0006 f67c983
bazel
cuiy0006 a2702b2
first working unit test
cuiy0006 d8f9b0a
unit test namespace
cuiy0006 e23e541
add all unit tests
cuiy0006 9e7a427
checkers
cuiy0006 ed3c3b7
clang-tidy
cuiy0006 48e1079
address comments
cuiy0006 af0ac8f
checkers
cuiy0006 f91f91f
Merge branch 'main' into add-tracing-connection
cuiy0006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
127 changes: 127 additions & 0 deletions
127
google/cloud/bigquery_unified/internal/tracing_connection.cc
This file contains hidden or 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,127 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // https://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. | ||
|
|
||
| #include "google/cloud/bigquery_unified/internal/tracing_connection.h" | ||
| #include "google/cloud/internal/opentelemetry.h" | ||
| #include "google/cloud/internal/traced_stream_range.h" | ||
|
|
||
| namespace google::cloud::bigquery_unified_internal { | ||
| GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN | ||
|
|
||
| #ifdef GOOGLE_CLOUD_CPP_BIGQUERY_HAVE_OPENTELEMETRY | ||
|
|
||
| TracingConnection::TracingConnection( | ||
| std::shared_ptr<bigquery_unified::Connection> child) | ||
| : child_(std::move(child)) {} | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> TracingConnection::CancelJob( | ||
| google::cloud::bigquery::v2::CancelJobRequest const& request, | ||
| Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::CancelJob"); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), child_->CancelJob(request, opts)); | ||
| } | ||
|
|
||
| StatusOr<google::cloud::bigquery::v2::JobReference> | ||
| TracingConnection::CancelJob( | ||
| google::cloud::NoAwaitTag, | ||
| google::cloud::bigquery::v2::CancelJobRequest const& request, | ||
| Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::CancelJob"); | ||
| auto scope = opentelemetry::trace::Scope(span); | ||
| return internal::EndSpan(*span, | ||
| child_->CancelJob(NoAwaitTag{}, request, opts)); | ||
| } | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> TracingConnection::CancelJob( | ||
| google::cloud::bigquery::v2::JobReference const& job_reference, | ||
| Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::CancelJob"); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), | ||
| child_->CancelJob(job_reference, opts)); | ||
| } | ||
|
|
||
| StatusOr<google::cloud::bigquery::v2::Job> TracingConnection::GetJob( | ||
| google::cloud::bigquery::v2::GetJobRequest const& request, Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::GetJob"); | ||
| auto scope = opentelemetry::trace::Scope(span); | ||
| return internal::EndSpan(*span, child_->GetJob(request, opts)); | ||
| } | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> TracingConnection::InsertJob( | ||
| google::cloud::bigquery::v2::Job const& job, Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::InsertJob"); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), child_->InsertJob(job, opts)); | ||
| } | ||
|
|
||
| StatusOr<google::cloud::bigquery::v2::JobReference> | ||
| TracingConnection::InsertJob(google::cloud::NoAwaitTag, | ||
| google::cloud::bigquery::v2::Job const& job, | ||
| Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::InsertJob"); | ||
| auto scope = opentelemetry::trace::Scope(span); | ||
| return internal::EndSpan(*span, child_->InsertJob(NoAwaitTag{}, job, opts)); | ||
| } | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> TracingConnection::InsertJob( | ||
| google::cloud::bigquery::v2::JobReference const& job_reference, | ||
| Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::InsertJob"); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), | ||
| child_->InsertJob(job_reference, opts)); | ||
| } | ||
|
|
||
| Status TracingConnection::DeleteJob( | ||
| google::cloud::bigquery::v2::DeleteJobRequest const& request, | ||
| Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::DeleteJob"); | ||
| auto scope = opentelemetry::trace::Scope(span); | ||
| return internal::EndSpan(*span, child_->DeleteJob(request, opts)); | ||
| } | ||
|
|
||
| StreamRange<google::cloud::bigquery::v2::ListFormatJob> | ||
| TracingConnection::ListJobs( | ||
| google::cloud::bigquery::v2::ListJobsRequest request, Options opts) { | ||
| auto span = internal::MakeSpan("bigquery_unified::Connection::ListJobs"); | ||
| internal::OTelScope scope(span); | ||
| auto sr = child_->ListJobs(std::move(request), opts); | ||
| return internal::MakeTracedStreamRange< | ||
| google::cloud::bigquery::v2::ListFormatJob>(std::move(span), | ||
| std::move(sr)); | ||
| } | ||
|
|
||
| StatusOr<bigquery_unified::ReadArrowResponse> TracingConnection::ReadArrow( | ||
| google::cloud::bigquery::storage::v1::CreateReadSessionRequest const& | ||
| read_session, | ||
| Options opts) { | ||
| // Not add span tracing for now, will add it after discussion. | ||
| return child_->ReadArrow(read_session, opts); | ||
| } | ||
| #endif // GOOGLE_CLOUD_CPP_BIGQUERY_HAVE_OPENTELEMETRY | ||
|
|
||
| std::shared_ptr<bigquery_unified::Connection> MakeTracingConnection( | ||
| std::shared_ptr<bigquery_unified::Connection> conn) { | ||
| #ifdef GOOGLE_CLOUD_CPP_BIGQUERY_HAVE_OPENTELEMETRY | ||
| if (internal::TracingEnabled(conn->options())) { | ||
| conn = std::make_shared<TracingConnection>(std::move(conn)); | ||
| } | ||
| #endif // GOOGLE_CLOUD_CPP_BIGQUERY_HAVE_OPENTELEMETRY | ||
| return conn; | ||
| } | ||
|
|
||
| GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END | ||
| } // namespace google::cloud::bigquery_unified_internal |
92 changes: 92 additions & 0 deletions
92
google/cloud/bigquery_unified/internal/tracing_connection.h
This file contains hidden or 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,92 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // https://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 GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_TRACING_CONNECTION_H | ||
| #define GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_TRACING_CONNECTION_H | ||
|
|
||
| #include "google/cloud/bigquery/storage/v1/bigquery_read_connection.h" | ||
| #include "google/cloud/bigquery_unified/connection.h" | ||
| #include "google/cloud/bigquery_unified/version.h" | ||
| #include "google/cloud/bigquerycontrol/v2/job_connection.h" | ||
| #include <memory> | ||
|
|
||
| namespace google::cloud::bigquery_unified_internal { | ||
| GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN | ||
|
|
||
| class TracingConnection : public bigquery_unified::Connection { | ||
| public: | ||
| ~TracingConnection() override = default; | ||
|
|
||
| explicit TracingConnection( | ||
| std::shared_ptr<bigquery_unified::Connection> child); | ||
|
|
||
| Options options() override { return child_->options(); } | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> CancelJob( | ||
| google::cloud::bigquery::v2::CancelJobRequest const& request, | ||
| Options opts) override; | ||
|
|
||
| StatusOr<google::cloud::bigquery::v2::JobReference> CancelJob( | ||
| google::cloud::NoAwaitTag, | ||
| google::cloud::bigquery::v2::CancelJobRequest const& request, | ||
| Options opts) override; | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> CancelJob( | ||
| google::cloud::bigquery::v2::JobReference const& job_reference, | ||
| Options opts) override; | ||
|
|
||
| StatusOr<google::cloud::bigquery::v2::Job> GetJob( | ||
| google::cloud::bigquery::v2::GetJobRequest const& request, | ||
| Options opts) override; | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> InsertJob( | ||
| google::cloud::bigquery::v2::Job const& job, Options opts) override; | ||
|
|
||
| StatusOr<google::cloud::bigquery::v2::JobReference> InsertJob( | ||
| google::cloud::NoAwaitTag, google::cloud::bigquery::v2::Job const& job, | ||
| Options opts) override; | ||
|
|
||
| future<StatusOr<google::cloud::bigquery::v2::Job>> InsertJob( | ||
| google::cloud::bigquery::v2::JobReference const& job_reference, | ||
| Options opts) override; | ||
|
|
||
| Status DeleteJob(google::cloud::bigquery::v2::DeleteJobRequest const& request, | ||
| Options opts) override; | ||
|
|
||
| StreamRange<google::cloud::bigquery::v2::ListFormatJob> ListJobs( | ||
| google::cloud::bigquery::v2::ListJobsRequest request, | ||
| Options opts) override; | ||
|
|
||
| StatusOr<bigquery_unified::ReadArrowResponse> ReadArrow( | ||
| google::cloud::bigquery::storage::v1::CreateReadSessionRequest const& | ||
| read_session, | ||
| Options opts) override; | ||
|
|
||
| private: | ||
| std::shared_ptr<bigquery_unified::Connection> child_; | ||
| }; | ||
|
|
||
| /** | ||
| * Conditionally applies the tracing decorator to the given connection. | ||
| * | ||
| * The connection is only decorated if tracing is enabled (as determined by the | ||
| * connection's options). | ||
| */ | ||
| std::shared_ptr<bigquery_unified::Connection> MakeTracingConnection( | ||
| std::shared_ptr<bigquery_unified::Connection> conn); | ||
|
|
||
| GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END | ||
| } // namespace google::cloud::bigquery_unified_internal | ||
|
|
||
| #endif // GOOGLE_CLOUD_CPP_BIGQUERY_GOOGLE_CLOUD_BIGQUERY_UNIFIED_INTERNAL_TRACING_CONNECTION_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.